changeset 23de2f5dd58a in /home/hg/repos/gajim
details:http://hg.gajim.org/gajim?cmd=changeset;node=23de2f5dd58a description: support min_gajim_version and max_gajim_version in plugins
diffstat:
src/common/defs.py | 2 +- src/plugins/pluginmanager.py | 72 ++++++++++++++++++++++++++----------------- 2 files changed, 45 insertions(+), 29 deletions(-)
diffs (116 lines):
diff -r f61b0d6163e0 -r 23de2f5dd58a src/common/defs.py --- a/src/common/defs.py Sat Jan 26 19:40:59 2013 +0100 +++ b/src/common/defs.py Sat Jan 26 22:31:17 2013 +0100 @@ -27,7 +27,7 @@ basedir = '../' localedir = '../po'
-version = '0.15.2.0' +version = '0.15.10.0' import subprocess try: node = subprocess.Popen('hg tip --template "{node|short}"', shell=True, diff -r f61b0d6163e0 -r 23de2f5dd58a src/plugins/pluginmanager.py --- a/src/plugins/pluginmanager.py Sat Jan 26 19:40:59 2013 +0100 +++ b/src/plugins/pluginmanager.py Sat Jan 26 22:31:17 2013 +0100 @@ -420,39 +420,61 @@ for elem_name in dir_list: file_path = os.path.join(path, elem_name)
- module = None - if os.path.isfile(file_path) and fnmatch.fnmatch(file_path, '*.py'): module_name = os.path.splitext(elem_name)[0] - try: - module = __import__(module_name) - except ValueError as value_error: - log.debug(str(value_error)) - except ImportError as import_error: - log.debug(str(import_error)) - elif os.path.isdir(file_path) and scan_dirs: module_name = elem_name - if module_name in sys.modules: - # do not load the module twice - continue file_path += os.path.sep - try: - module = __import__(module_name) - except ValueError as value_error: - log.debug(str(value_error)) - except ImportError as import_error: - log.debug(str(import_error)) - - - if module is None: - continue
manifest_path = os.path.join(os.path.dirname(file_path), 'manifest.ini') if scan_dirs and (not os.path.isfile(manifest_path)): continue
+ # read metadata from manifest.ini + conf.remove_section('info') + conf_file = open(manifest_path) + conf.read_file(conf_file) + conf_file.close() + + try: + min_v = conf.get('info', 'min_gajim_version') + except Exception: + min_v = None + try: + max_v = conf.get('info', 'max_gajim_version') + except Exception: + max_v = None + + gajim_v = gajim.config.get('version') + gajim_v = gajim_v.split('-', 1)[0] + gajim_v = gajim_v.split('.') + + if min_v: + min_v = min_v.split('.') + if gajim_v < min_v: + continue + if max_v: + max_v = max_v.split('.') + if gajim_v > max_v: + continue + + + module = None + + if module_name in sys.modules: + # do not load the module twice + continue + try: + module = __import__(module_name) + except ValueError as value_error: + log.debug(str(value_error)) + except ImportError as import_error: + log.debug(str(import_error)) + + if module is None: + continue + log.debug('Attributes processing started') for module_attr_name in [attr_name for attr_name in dir(module) if not (attr_name.startswith('__') or attr_name.endswith('__'))]: @@ -467,16 +489,10 @@ module_attr.__path__ = os.path.abspath( os.path.dirname(file_path))
- # read metadata from manifest.ini - conf_file = open(manifest_path) - conf.read_file(conf_file) - conf_file.close() - for option in fields: if conf.get('info', option) is '': raise configparser.NoOptionError('field empty') setattr(module_attr, option, conf.get('info', option)) - conf.remove_section('info')
plugins_found.append(module_attr) except TypeError: