From Eliot:
authorAnders Broman <anders.broman@ericsson.com>
Mon, 24 Oct 2011 16:33:01 +0000 (16:33 -0000)
committerAnders Broman <anders.broman@ericsson.com>
Mon, 24 Oct 2011 16:33:01 +0000 (16:33 -0000)
Search personal plugins dir for python plugins

https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=6448

svn path=/trunk/; revision=39534

epan/wspython/register-dissector.py
epan/wspython/wspy_register.c

index 8a983e6f3b2d94f41d44845669b24733b8fd420a..a9ca3ac4164317827472c0521612b3fb64a81083 100755 (executable)
@@ -47,35 +47,42 @@ def plugin_import(name):
   except KeyError:
     pass
 
-  return __import__(name)
+  r = __import__(name)
+  return r
 
-def register_dissectors(dir):
+def register_dissectors(wspython_dir,  plugins_pers_dir=None):
   #append dir to be able to import py_lib
-  sys.path.append(dir)
+  sys.path.append(wspython_dir)
   from wspy_libws import get_libws_handle
   libws = get_libws_handle()
 
-  dissectors_dir = os.path.join(dir, "wspy_dissectors")
+  dissectors_dirs = [
+    os.path.join(wspython_dir, 'wspy_dissectors'),
+    plugins_pers_dir
+  ]
 
-  #Check if we have the dissectors directory
-  if not os.path.isdir(dissectors_dir):
-    return []
+  registered_protocols = []
+  for dissectors_dir in dissectors_dirs:
+      print 'looking for dissectors in', dissectors_dir
+      #Check if we have the dissectors directory
+      if not os.path.isdir(dissectors_dir):
+        continue
 
-  #append dir to be able to import python dissectors
-  sys.path.append(dissectors_dir)
+      #append dir to be able to import python dissectors
+      sys.path.append(dissectors_dir)
 
-  registered_protocols = []
-  #Read all python dissectors
-  try:
-    dissectors = get_plugin_list(dissectors_dir, "(?P<plugin>.*)\.py$")
-  #For each dissector, register it and put it in the list of registered
-  #protocols
-    for dissector in dissectors:
-      d = plugin_import(dissector)
-      registered_protocol = d.register_protocol()
-      if registered_protocol:
-        registered_protocols.append(registered_protocol)
-  except Exception, e:
-    print e
+      #Read all python dissectors
+      dissectors = get_plugin_list(dissectors_dir, "(?P<plugin>.*)\.py$")
 
+      #For each dissector, register it and put it in the list of registered
+      #protocols
+      for dissector in dissectors:
+          try:
+              d = plugin_import(dissector)
+              registered_protocol = d.register_protocol()
+              if registered_protocol:
+                registered_protocols.append(registered_protocol)
+          except Exception, e:
+              print 'register dissector %s exception %s' % (dissector, e)
+  print 'registered protocols', registered_protocols
   return registered_protocols
index 0df7e9eb46ad58ebca67c0462fdccc580104efd4..97bde1b2f305704c0a88ef5464d51c16a1fbaac6 100644 (file)
@@ -152,7 +152,7 @@ void register_all_py_protocols_func(void)
 
   /* Execute the python register function */
   /* This function returns a sequence of python dissectors objects */
-  py_args = Py_BuildValue("(s)", get_wspython_dir());
+  py_args = Py_BuildValue("ss",  get_wspython_dir(), get_plugins_pers_dir());
   py_dissectors = PyObject_CallObject(register_fn, py_args);
 
   /* Check that the py_dissectors is really a sequence */