[Xfce4-commits] <thunarx-python:master> Implemented runtime debugging control using the THUNARX_PYTHON_DEBUG environment variable

Adam Plumb noreply at xfce.org
Thu May 27 18:11:03 CEST 2010


Updating branch refs/heads/master
         to ea5b45a0a7e2e0a7519e4a121ef510c0aad41294 (commit)
       from fc013be8b3ac923ab6fc1b643ebe5e6181305704 (commit)

commit ea5b45a0a7e2e0a7519e4a121ef510c0aad41294
Author: Adam Plumb <adamplumb at gmail.com>
Date:   Tue Jan 12 16:54:02 2010 -0500

    Implemented runtime debugging control using the THUNARX_PYTHON_DEBUG environment variable

 README               |    7 +++++++
 src/thunarx-python.c |   23 +++++++++++++++++++----
 src/thunarx-python.h |   14 ++++++++++----
 3 files changed, 36 insertions(+), 8 deletions(-)

diff --git a/README b/README
index e618293..3ab6005 100644
--- a/README
+++ b/README
@@ -7,3 +7,10 @@ Dependencies
  * thunar (0.4.0 or later)
  * pygtk (2.6.0 or later)
  * gnome-python (2.12.0 or later)
+ 
+ 
+Debugging
+-----------
+To enable debug mode, start thunar with the following command:
+
+  $ THUNARX_PYTHON_DEBUG=all /path/to/thunar
diff --git a/src/thunarx-python.c b/src/thunarx-python.c
index 91c26e1..91856aa 100644
--- a/src/thunarx-python.c
+++ b/src/thunarx-python.c
@@ -28,6 +28,12 @@
 #include "thunarx-python.h"
 #include "thunarx-python-object.h"
 
+static const GDebugKey thunarx_python_debug_keys[] = {
+  {"all", THUNARX_PYTHON_DEBUG_ALL},
+};
+static const guint thunarx_python_ndebug_keys = sizeof (thunarx_python_debug_keys) / sizeof (GDebugKey);
+ThunarxPythonDebug thunarx_python_debug;
+
 static GArray *all_types = NULL;
 
 G_MODULE_EXPORT void thunar_extension_initialize (ThunarxProviderPlugin *plugin);
@@ -232,7 +238,6 @@ thunarx_python_load_file (ThunarxProviderPlugin *plugin, const gchar *filename)
   }
   
   main_locals = PyModule_GetDict(main_module);
-  g_print("Attempting to load module %s\n", filename);
   module = PyImport_ImportModuleEx((char *) filename, main_locals, main_locals, NULL);
   if (!module)
   {
@@ -314,6 +319,18 @@ G_MODULE_EXPORT void
 thunar_extension_initialize (ThunarxProviderPlugin *plugin)
 {
   const gchar *mismatch;
+  const gchar *env_string;
+
+	env_string = g_getenv("THUNARX_PYTHON_DEBUG");
+	if (env_string != NULL)
+	{
+		thunarx_python_debug = g_parse_debug_string(env_string,
+													 thunarx_python_debug_keys,
+													 thunarx_python_ndebug_keys);
+		env_string = NULL;
+  }
+
+  debug_enter();
 
   /* verify that the thunarx versions are compatible */
   mismatch = thunarx_check_version (THUNARX_MAJOR_VERSION, THUNARX_MINOR_VERSION, THUNARX_MICRO_VERSION);
@@ -323,8 +340,6 @@ thunar_extension_initialize (ThunarxProviderPlugin *plugin)
       return;
     }
 
-  debug ("Initializing thunarx-python extension");
-
   all_types = g_array_new(FALSE, FALSE, sizeof(GType));
   
   thunarx_provider_plugin_set_resident (plugin, TRUE);  
@@ -336,7 +351,7 @@ thunar_extension_initialize (ThunarxProviderPlugin *plugin)
 G_MODULE_EXPORT void
 thunar_extension_shutdown (void)
 {
-  debug ("Shutting down thunarx-python extension");
+  debug_enter();
   
   if (Py_IsInitialized())
     Py_Finalize();
diff --git a/src/thunarx-python.h b/src/thunarx-python.h
index 30a07a8..0d9b51b 100644
--- a/src/thunarx-python.h
+++ b/src/thunarx-python.h
@@ -30,11 +30,17 @@ typedef int Py_ssize_t;
 #define PY_SSIZE_T_MIN INT_MIN
 #endif
 
-#define DEBUG_ENABLED 1
-#define debug(x) { if (DEBUG_ENABLED) g_print("thunarx-python: " x "\n"); }
-#define debug_enter()  { if (DEBUG_ENABLED) \
+typedef enum {
+    THUNARX_PYTHON_DEBUG_ALL = 1 << 0,
+} ThunarxPythonDebug;
+
+extern ThunarxPythonDebug thunarx_python_debug;
+
+#define debug(x) { if (thunarx_python_debug & THUNARX_PYTHON_DEBUG_ALL) \
+                         g_print("thunarx-python: " x "\n"); }
+#define debug_enter()  { if (thunarx_python_debug & THUNARX_PYTHON_DEBUG_ALL) \
                              g_printf("%s: entered\n", __FUNCTION__); }
-#define debug_enter_args(x, y) { if (DEBUG_ENABLED) \
+#define debug_enter_args(x, y) { if (thunarx_python_debug & THUNARX_PYTHON_DEBUG_ALL) \
                                      g_printf("%s: entered " x "\n", __FUNCTION__, y); }
 
 PyTypeObject *_PyGtkWidget_Type;



More information about the Xfce4-commits mailing list