glom r2052 - in trunk: . glom glom/python_embed



Author: murrayc
Date: Thu Apr  9 17:56:09 2009
New Revision: 2052
URL: http://svn.gnome.org/viewvc/glom?rev=2052&view=rev

Log:
2009-04-09  Murray Cumming  <murrayc murrayc com>

* glom/python_embed/glom_python.[h|cc]: 
Added glom_python_module_is_available() and 
gda_python_module_is_available().
* glom/main.cc: Use them to do some extra runtime sanity checking, 
warning the user if their install is broken.

Modified:
   trunk/ChangeLog
   trunk/glom/main.cc
   trunk/glom/python_embed/glom_python.cc
   trunk/glom/python_embed/glom_python.h

Modified: trunk/glom/main.cc
==============================================================================
--- trunk/glom/main.cc	(original)
+++ trunk/glom/main.cc	Thu Apr  9 17:56:09 2009
@@ -38,7 +38,8 @@
 #endif //GLOM_ENABLE_POSTGRESQL
 
 // For sanity checks:
-#include <libglom/data_structure/glomconversions.h> // For GLOM_IMAGE_FORMAT
+#include <libglom/data_structure/glomconversions.h>
+#include <glom/python_embed/glom_python.h>
 
 #ifndef GLOM_ENABLE_CLIENT_ONLY
 #include <gtksourceviewmm/init.h>
@@ -103,7 +104,7 @@
 }
 
 #ifdef GLOM_ENABLE_POSTGRESQL
-bool check_user_is_not_root()
+bool check_user_is_not_root_with_warning()
 {
   Glib::ustring message;
 #ifdef G_OS_WIN32
@@ -119,7 +120,7 @@
     message = ex.what();
   }
 #else
-  //std::cout << "ConnectionPool::check_user_is_not_root(): geteuid()=" << geteuid() << ", getgid()=" << getgid() << std::endl;
+  //std::cout << "ConnectionPool::check_user_is_not_root_with_warning(): geteuid()=" << geteuid() << ", getgid()=" << getgid() << std::endl;
 
   //This is very linux-specific. We should ifdef this out for other platforms.
   if(geteuid() == 0)
@@ -203,6 +204,42 @@
 
 #endif //GLOM_ENABLE_POSTGRESQL
 
+bool check_pyglom_is_available_with_warning()
+{
+  if(glom_python_module_is_available())
+    return true;
+
+   /* The python module could not be imported by Glom, so warn the user: */
+   const Glib::ustring message = _("Your installation of Glom is not complete, because the Glom Python module is not available on your system.\n\nPlease report this bug to your vendor, or your system administrator so it can be corrected.");
+      
+#ifndef GLOM_ENABLE_MAEMO
+  Gtk::MessageDialog dialog(Utils::bold_message(_("Glom Python Module Not Installed")), true /* use_markup */, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true /* modal */);
+  dialog.set_secondary_text(message);
+  dialog.run();
+#else
+  Hildon::Note note(Hildon::NOTE_TYPE_INFORMATION, message);
+  note.run();
+#endif //GLOM_ENABLE_MAEMO
+}
+
+bool check_pygda_is_available_with_warning()
+{
+  if(glom_python_module_is_available())
+    return true;
+
+   /* The python module could not be imported by Glom, so warn the user: */
+   const Glib::ustring message = _("Your installation of Glom is not complete, because the gda Python module is not available on your system.\n\nPlease report this bug to your vendor, or your system administrator so it can be corrected.");
+      
+#ifndef GLOM_ENABLE_MAEMO
+  Gtk::MessageDialog dialog(Utils::bold_message(_("gda Python Module Not Installed")), true /* use_markup */, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true /* modal */);
+  dialog.set_secondary_text(message);
+  dialog.run();
+#else
+  Hildon::Note note(Hildon::NOTE_TYPE_INFORMATION, message);
+  note.run();
+#endif //GLOM_ENABLE_MAEMO
+}
+
 } //namespace Glom
 
 #ifndef G_OS_WIN32
@@ -388,10 +425,16 @@
       
     // Postgres can't be started as root. initdb complains.
     // So just prevent this in general. It is safer anyway.
-    if(!Glom::check_user_is_not_root())
+    if(!Glom::check_user_is_not_root_with_warning())
       return -1;
 #endif //GLOM_ENABLE_POSTGRESQL
 
+    if(!Glom::check_pyglom_is_available_with_warning())
+      return -1;
+
+    if(!Glom::check_pygda_is_available_with_warning())
+      return -1;
+
 
     // Some more sanity checking:
     // These print errors to the stdout if they fail.

Modified: trunk/glom/python_embed/glom_python.cc
==============================================================================
--- trunk/glom/python_embed/glom_python.cc	(original)
+++ trunk/glom/python_embed/glom_python.cc	Thu Apr  9 17:56:09 2009
@@ -136,6 +136,20 @@
   g_free(chrRetval);
 }
 
+bool glom_python_module_is_available()
+{
+  PyObject* module_glom = PyImport_ImportModule((char*)"glom"); //TODO: unref this?
+  return module_glom != 0;
+}
+
+bool gda_python_module_is_available()
+{
+  PyObject* module_glom = PyImport_ImportModule((char*)"gda"); //TODO: unref this?
+  return module_glom != 0;
+}
+
+
+
 void glom_execute_python_function_implementation(const Glib::ustring& func_impl, const type_map_fields& field_values, Document* pDocument, const Glib::ustring& table_name, const Glib::RefPtr<Gnome::Gda::Connection>& opened_connection)
 {
   glom_evaluate_python_function_implementation(Field::TYPE_TEXT, func_impl, field_values, pDocument, table_name, opened_connection);

Modified: trunk/glom/python_embed/glom_python.h
==============================================================================
--- trunk/glom/python_embed/glom_python.h	(original)
+++ trunk/glom/python_embed/glom_python.h	Thu Apr  9 17:56:09 2009
@@ -22,11 +22,22 @@
 #define GLOM_PYTHON_H
 
 #include <libglom/data_structure/field.h>
+#include <libglom/document/document.h>
 #include <glibmm/ustring.h>
 
 namespace Glom
 {
 
+/** Check that Python can really import the Glom module, 
+ * as a runtime sanity check.
+ */
+bool glom_python_module_is_available();
+
+/** Check that Python can really import the gda module, 
+ * as a runtime sanity check.
+ */
+bool gda_python_module_is_available();
+
 typedef std::map<Glib::ustring, Gnome::Gda::Value> type_map_fields;
 
 void glom_execute_python_function_implementation(const Glib::ustring& func_impl, const type_map_fields& field_values, Document* pDocument, const Glib::ustring& table_name, const Glib::RefPtr<Gnome::Gda::Connection>& opened_connection);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]