Author: dmeyer
Date: Fri Feb 8 15:15:52 2008
New Revision: 3040
Log:
Add generic plugin finder to avoid duplicate code in all
modules that load plugins from a given directory.
Modified:
trunk/base/src/utils.py
Modified: trunk/base/src/utils.py
==============================================================================
--- trunk/base/src/utils.py (original)
+++ trunk/base/src/utils.py Fri Feb 8 15:15:52 2008
@@ -202,6 +202,27 @@
_utils.set_process_name(name, len(cmdline))
+def get_plugins(path, include_files=True, include_directories=True):
+ """
+ Get a list of plugins in the given plugin directory. The 'path' argument
+ can also be a full path of an __init__ file.
+ """
+ if os.path.isfile(path):
+ path = os.path.dirname(path)
+ result = []
+ for plugin in os.listdir(path):
+ for ext in ('.py', '.pyc', '.pyo'):
+ if plugin.endswith(ext) and include_files:
+ plugin = plugin[:-len(ext)]
+ break
+ else:
+ if not include_directories or not os.path.isdir(os.path.join(path,
plugin)):
+ continue
+ if not plugin in result and not plugin == '__init__':
+ result.append(plugin)
+ return result
+
+
class Singleton(object):
"""
Create Singleton object from classref on demand.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog