Changeset 9803

Show
Ignore:
Timestamp:
06/14/08 20:20:24 (6 months ago)
Author:
vardo
Message:

Plugin can be a package (directory) now. Added example plugin that modifies roster window (with glade file).

Added activate and deactivate methods to Plugin (used in forementioned RosterButtonsPlugin?).

Location:
branches/plugin-system
Files:
4 added
2 modified

Legend:

Unmodified
Added
Removed
  • branches/plugin-system/src/plugins/pluginmanager.py

    r9773 r9803  
    172172                if success: 
    173173                        self.active_plugins.append(plugin_object) 
     174                        plugin_object.activate() 
    174175                        plugin_class._instance = plugin_object 
    175176                        plugin_class._active = True 
     
    194195                         
    195196                # removing plug-in from active plug-ins list 
     197                plugin_object.deactivate() 
    196198                self.active_plugins.remove(plugin_object) 
    197199                plugin_object.__class__._active = False 
     
    250252                if os.path.isdir(path): 
    251253                        dir_list = os.listdir(path) 
    252                         log.debug(dir_list) 
     254                        #log.debug(dir_list) 
    253255 
    254256                        sys.path.insert(0, path) 
    255                         log.debug(sys.path) 
    256  
    257                         for file_name in fnmatch.filter(dir_list, '*.py'): 
    258                                 log.debug('- "%s"'%(file_name)) 
    259                                 file_path = os.path.join(path, file_name) 
     257                        #log.debug(sys.path) 
     258 
     259                        for elem_name in dir_list: 
     260                                log.debug('- "%s"'%(elem_name)) 
     261                                file_path = os.path.join(path, elem_name) 
    260262                                log.debug('  "%s"'%(file_path)) 
    261                                 if os.path.isfile(file_path): 
    262                                         module_name = os.path.splitext(file_name)[0] 
    263                                         module = __import__(module_name) 
    264                                         for module_attr_name in [f_name for f_name in dir(module)  
    265                                                                 if not (f_name.startswith('__') or  
    266                                                                                 f_name.endswith('__'))]: 
     263                                 
     264                                module = None 
     265                                 
     266                                if os.path.isfile(file_path) and fnmatch.fnmatch(file_path,'*.py'): 
     267                                        module_name = os.path.splitext(elem_name)[0] 
     268                                        log.debug('Possible module detected.') 
     269                                        try: 
     270                                                module = __import__(module_name) 
     271                                                log.debug('Module imported.') 
     272                                        except ValueError, value_error: 
     273                                                log.debug('Module not imported successfully. ValueError: %s'%(value_error)) 
     274                                        except ImportError, import_error: 
     275                                                log.debug('Module not imported successfully. ImportError: %s'%(import_error)) 
     276                                         
     277                                elif os.path.isdir(file_path): 
     278                                        module_name = elem_name 
     279                                        file_path += os.path.sep 
     280                                        log.debug('Possible package detected.') 
     281                                        try: 
     282                                                module = __import__(module_name) 
     283                                                log.debug('Package imported.') 
     284                                        except ValueError, value_error: 
     285                                                log.debug('Package not imported successfully. ValueError: %s'%(value_error)) 
     286                                        except ImportError, import_error: 
     287                                                log.debug('Package not imported successfully. ImportError: %s'%(import_error)) 
     288                                         
     289                                         
     290                                if module: 
     291                                        log.debug('Attributes processing started') 
     292                                        for module_attr_name in [attr_name for attr_name in dir(module)  
     293                                                                                         if not (attr_name.startswith('__') or  
     294                                                                                                         attr_name.endswith('__'))]: 
    267295                                                module_attr = getattr(module, module_attr_name) 
    268296                                                log.debug('%s : %s'%(module_attr_name, module_attr)) 
    269  
     297                                                 
    270298                                                try: 
    271299                                                        if issubclass(module_attr, GajimPlugin) and \ 
    272300                                                           not module_attr is GajimPlugin: 
    273301                                                                log.debug('is subclass of GajimPlugin') 
     302                                                                #log.debug('file_path: %s\nabspath: %s\ndirname: %s'%(file_path, os.path.abspath(file_path), os.path.dirname(os.path.abspath(file_path)))) 
     303                                                                #log.debug('file_path: %s\ndirname: %s\nabspath: %s'%(file_path, os.path.dirname(file_path), os.path.abspath(os.path.dirname(file_path)))) 
     304                                                                module_attr.__path__ = os.path.abspath(os.path.dirname(file_path)) 
    274305                                                                plugins_found.append(module_attr) 
    275306                                                except TypeError, type_error: 
  • branches/plugin-system/src/plugins/plugin.py

    r9792 r9803  
    2424:license: GPL 
    2525''' 
     26 
     27import os 
    2628 
    2729from plugins.helpers import log_calls 
     
    118120                self._save_config() 
    119121                 
     122        @log_calls('GajimPlugin') 
     123        def local_file_path(self, file_name): 
     124                return os.path.join(self.__path__, file_name) 
     125         
     126        @log_calls('GajimPlugin') 
     127        def activate(self): 
     128                pass 
     129                 
     130        @log_calls('GajimPlugin') 
     131        def deactivate(self): 
     132                pass 
    120133 
    121134class Config(dict):