Ejemplo n.º 1
0
 def __init__(self, node, hotkey_manager, *main_views):
     '''
 Initialize the plugin manager.
 
 @param node: The application's main node.
 @type node: L{Node}
 @param hotkey_manager: Application's hot key manager.
 @type hotkey_manager: L{HotkeyManager}
 @param main_views: List of permanent plugin views.
 @type main_views: list of {PluginView}
 '''
     gtk.ListStore.__init__(
         self,
         object,  # Plugin instance
         object,  # Plugin class
         str)  # Plugin path
     self.node = node
     self.hotkey_manager = hotkey_manager
     self.gsettings = GSettings(schema=GSCHEMA)
     self.view_manager = ViewManager(*main_views)
     self.message_manager = MessageManager()
     self.message_manager.connect('plugin-reload-request',
                                  self._onPluginReloadRequest)
     self.message_manager.connect('module-reload-request',
                                  self._onModuleReloadRequest)
     message_tab = self.message_manager.getMessageTab()
     self.view_manager.addElement(message_tab)
     self._row_changed_handler = \
         self.connect('row_changed', self._onPluginRowChanged)
     self._loadPlugins()
Ejemplo n.º 2
0
 def __init__(self, node, hotkey_manager, *main_views):
   '''
   Initialize the plugin manager.
   
   @param node: The application's main node.
   @type node: L{Node}
   @param hotkey_manager: Application's hot key manager.
   @type hotkey_manager: L{HotkeyManager}
   @param main_views: List of permanent plugin views.
   @type main_views: list of {PluginView}
   '''
   gtk.ListStore.__init__(self,
                          object, # Plugin instance
                          object, # Plugin class
                          str) # Plugin path
   self.node = node
   self.hotkey_manager = hotkey_manager
   self.view_manager = ViewManager(*main_views)
   self.message_manager = MessageManager()
   self.message_manager.connect('plugin-reload-request', 
                                self._onPluginReloadRequest)
   self.message_manager.connect('module-reload-request', 
                                self._onModuleReloadRequest)
   message_tab = self.message_manager.getMessageTab()
   self.view_manager.addElement(message_tab)
   self._row_changed_handler = \
       self.connect('row_changed', self._onPluginRowChanged)
   self._loadPlugins()
Ejemplo n.º 3
0
class PluginManager(gtk.ListStore, Tools):
  '''

  @cvar COL_INSTANCE: Instance column ID.
  @type COL_INSTANCE: integer
  @cvar COL_CLASS: Class column ID.
  @type COL_CLASS: integer
  @cvar COL_PATH: Module path column ID.
  @type COL_PATH: integer

  @ivar node: Application's selected accessible node.
  @type node: L{Node}
  @ivar hotkey_manager: Application's hotkey manager.
  @type hotkey_manager: L{HotkeyManager}
  @ivar view_manager: Plugin view manager.
  @type view_manager: L{ViewManager}
  @ivar message_manager: Plugin message manager.
  @type message_manager: L{MessageManager}

  '''
  COL_INSTANCE = 0
  COL_CLASS = 1
  COL_PATH = 2
  def __init__(self, node, hotkey_manager, *main_views):
    '''
    Initialize the plugin manager.
    
    @param node: The application's main node.
    @type node: L{Node}
    @param hotkey_manager: Application's hot key manager.
    @type hotkey_manager: L{HotkeyManager}
    @param main_views: List of permanent plugin views.
    @type main_views: list of {PluginView}
    '''
    gtk.ListStore.__init__(self,
                           object, # Plugin instance
                           object, # Plugin class
                           str) # Plugin path
    self.node = node
    self.hotkey_manager = hotkey_manager
    self.view_manager = ViewManager(*main_views)
    self.message_manager = MessageManager()
    self.message_manager.connect('plugin-reload-request', 
                                 self._onPluginReloadRequest)
    self.message_manager.connect('module-reload-request', 
                                 self._onModuleReloadRequest)
    message_tab = self.message_manager.getMessageTab()
    self.view_manager.addElement(message_tab)
    self._row_changed_handler = \
        self.connect('row_changed', self._onPluginRowChanged)
    self._loadPlugins()

  def close(self):
    '''
    Close view manager and plugins.
    '''
    self.view_manager.close()
    for row in self:
      plugin = row[self.COL_INSTANCE]
      if plugin:
        plugin._close()

  def _loadPlugins(self):
    '''
    Load all plugins in global and local plugin paths.
    '''
    for plugin_dir, plugin_fn in self._getPluginFiles():
      self._loadPluginFile(plugin_dir, plugin_fn)
    self.view_manager.initialView()

  def _getPluginFiles(self):
    '''
    Get list of all modules in plugin paths.
    
    @return: List of plugin files with their paths.
    @rtype: tuple
    '''
    plugin_file_list = []
    plugin_dir_local = os.path.join(os.environ['HOME'], 
                                    '.accerciser', 'plugins')
    plugin_dir_global = os.path.join(sys.prefix, 'share',
                                     'accerciser', 'plugins')
    for plugin_dir in (plugin_dir_local, plugin_dir_global):
      if not os.path.isdir(plugin_dir):
        continue
      for fn in os.listdir(plugin_dir):
        if fn.endswith('.py') and not fn.startswith('.'):
          plugin_file_list.append((plugin_dir, fn[:-3]))

    return plugin_file_list

  def _getPluginLocals(self, plugin_dir, plugin_fn):
    '''
    Get namespace of given module
    
    @param plugin_dir: Path.
    @type plugin_dir: string
    @param plugin_fn: Module.
    @type plugin_fn: string
    
    @return: Dictionary of modules symbols.
    @rtype: dictionary
    '''
    sys.path.insert(0, plugin_dir)
    try:
      params = imp.find_module(plugin_fn, [plugin_dir])
      plugin = imp.load_module(plugin_fn, *params)
      plugin_locals = plugin.__dict__
    except Exception, e:
      self.message_manager.newModuleError(plugin_fn, plugin_dir,
        traceback.format_exception_only(e.__class__, e)[0].strip(),
        traceback.format_exc())
      return {}
    sys.path.pop(0)
    return plugin_locals
Ejemplo n.º 4
0
 def get_view_manager(self):
     if self._view_manager is None:
         self._view_manager = ViewManager(self)
     return self._view_manager
Ejemplo n.º 5
0
class PluginManager(gtk.ListStore, Tools):
    '''

  @cvar COL_INSTANCE: Instance column ID.
  @type COL_INSTANCE: integer
  @cvar COL_CLASS: Class column ID.
  @type COL_CLASS: integer
  @cvar COL_PATH: Module path column ID.
  @type COL_PATH: integer

  @ivar node: Application's selected accessible node.
  @type node: L{Node}
  @ivar hotkey_manager: Application's hotkey manager.
  @type hotkey_manager: L{HotkeyManager}
  @ivar view_manager: Plugin view manager.
  @type view_manager: L{ViewManager}
  @ivar message_manager: Plugin message manager.
  @type message_manager: L{MessageManager}

  '''
    COL_INSTANCE = 0
    COL_CLASS = 1
    COL_PATH = 2

    def __init__(self, node, hotkey_manager, *main_views):
        '''
    Initialize the plugin manager.
    
    @param node: The application's main node.
    @type node: L{Node}
    @param hotkey_manager: Application's hot key manager.
    @type hotkey_manager: L{HotkeyManager}
    @param main_views: List of permanent plugin views.
    @type main_views: list of {PluginView}
    '''
        gtk.ListStore.__init__(
            self,
            object,  # Plugin instance
            object,  # Plugin class
            str)  # Plugin path
        self.node = node
        self.hotkey_manager = hotkey_manager
        self.gsettings = GSettings(schema=GSCHEMA)
        self.view_manager = ViewManager(*main_views)
        self.message_manager = MessageManager()
        self.message_manager.connect('plugin-reload-request',
                                     self._onPluginReloadRequest)
        self.message_manager.connect('module-reload-request',
                                     self._onModuleReloadRequest)
        message_tab = self.message_manager.getMessageTab()
        self.view_manager.addElement(message_tab)
        self._row_changed_handler = \
            self.connect('row_changed', self._onPluginRowChanged)
        self._loadPlugins()

    def close(self):
        '''
    Close view manager and plugins.
    '''
        self.view_manager.close()
        for row in self:
            plugin = row[self.COL_INSTANCE]
            if plugin:
                plugin._close()

    def _loadPlugins(self):
        '''
    Load all plugins in global and local plugin paths.
    '''
        # AQUI PETAA
        for plugin_dir, plugin_fn in self._getPluginFiles():
            self._loadPluginFile(plugin_dir, plugin_fn)
        self.view_manager.initialView()

    def _getPluginFiles(self):
        '''
    Get list of all modules in plugin paths.
    
    @return: List of plugin files with their paths.
    @rtype: tuple
    '''
        plugin_file_list = []
        plugin_dir_local = os.path.join(os.environ['HOME'], '.accerciser',
                                        'plugins')
        plugin_dir_global = os.path.join(sys.prefix, 'share', 'accerciser',
                                         'plugins')
        for plugin_dir in (plugin_dir_local, plugin_dir_global):
            if not os.path.isdir(plugin_dir):
                continue
            for fn in os.listdir(plugin_dir):
                if fn.endswith('.py') and not fn.startswith('.'):
                    plugin_file_list.append((plugin_dir, fn[:-3]))

        return plugin_file_list

    def _getPluginLocals(self, plugin_dir, plugin_fn):
        '''
    Get namespace of given module
    
    @param plugin_dir: Path.
    @type plugin_dir: string
    @param plugin_fn: Module.
    @type plugin_fn: string
    
    @return: Dictionary of modules symbols.
    @rtype: dictionary
    '''
        sys.path.insert(0, plugin_dir)
        try:
            params = imp.find_module(plugin_fn, [plugin_dir])
            plugin = imp.load_module(plugin_fn, *params)
            plugin_locals = plugin.__dict__
        except Exception, e:
            self.message_manager.newModuleError(
                plugin_fn, plugin_dir,
                traceback.format_exception_only(e.__class__, e)[0].strip(),
                traceback.format_exc())
            return {}
        sys.path.pop(0)
        return plugin_locals