コード例 #1
0
ファイル: pluginmanager.py プロジェクト: simhnna/openlp
 def find_plugins(self):
     """
     Scan a directory for objects inheriting from the ``Plugin`` class.
     """
     glob_pattern = os.path.join('plugins', '*', '[!.]*plugin.py')
     extension_loader(glob_pattern)
     plugin_classes = Plugin.__subclasses__()
     plugin_objects = []
     for p in plugin_classes:
         try:
             plugin = p()
             self.log_debug('Loaded plugin {plugin}'.format(plugin=str(p)))
             plugin_objects.append(plugin)
         except TypeError:
             self.log_exception(
                 'Failed to load plugin {plugin}'.format(plugin=str(p)))
     plugins_list = sorted(plugin_objects, key=lambda plugin: plugin.weight)
     for plugin in plugins_list:
         if plugin.check_pre_conditions():
             self.log_debug(
                 'Plugin {plugin} active'.format(plugin=str(plugin.name)))
             plugin.set_status()
         else:
             plugin.status = PluginStatus.Disabled
         self.plugins.append(plugin)
コード例 #2
0
 def find_plugins(self):
     """
     Scan a directory for objects inheriting from the ``Plugin`` class.
     """
     start_depth = len(os.path.abspath(self.base_path).split(os.sep))
     present_plugin_dir = os.path.join(self.base_path, 'presentations')
     self.log_debug('finding plugins in {path} at depth {depth:d}'.format(
         path=self.base_path, depth=start_depth))
     for root, dirs, files in os.walk(self.base_path):
         for name in files:
             if name.endswith('.py') and not name.startswith('__'):
                 path = os.path.abspath(os.path.join(root, name))
                 this_depth = len(path.split(os.sep))
                 if this_depth - start_depth > 2:
                     # skip anything lower down
                     break
                 module_name = name[:-3]
                 # import the modules
                 self.log_debug(
                     'Importing {name} from {root}. Depth {depth:d}'.format(
                         name=module_name, root=root, depth=this_depth))
                 try:
                     # Use the "imp" library to try to get around a problem with the PyUNO library which
                     # monkey-patches the __import__ function to do some magic. This causes issues with our tests.
                     # First, try to find the module we want to import, searching the directory in root
                     fp, path_name, description = imp.find_module(
                         module_name, [root])
                     # Then load the module (do the actual import) using the details from find_module()
                     imp.load_module(module_name, fp, path_name,
                                     description)
                 except ImportError as e:
                     self.log_exception(
                         'Failed to import module {name} on path {path}: '
                         '{args}'.format(name=module_name,
                                         path=path,
                                         args=e.args[0]))
     plugin_classes = Plugin.__subclasses__()
     plugin_objects = []
     for p in plugin_classes:
         try:
             plugin = p()
             self.log_debug('Loaded plugin {plugin}'.format(plugin=str(p)))
             plugin_objects.append(plugin)
         except TypeError:
             self.log_exception(
                 'Failed to load plugin {plugin}'.format(plugin=str(p)))
     plugins_list = sorted(plugin_objects, key=lambda plugin: plugin.weight)
     for plugin in plugins_list:
         if plugin.check_pre_conditions():
             self.log_debug(
                 'Plugin {plugin} active'.format(plugin=str(plugin.name)))
             plugin.set_status()
         else:
             plugin.status = PluginStatus.Disabled
         self.plugins.append(plugin)
コード例 #3
0
 def find_plugins(self):
     """
     Scan a directory for objects inheriting from the ``Plugin`` class.
     """
     log.info('Finding plugins')
     start_depth = len(os.path.abspath(self.base_path).split(os.sep))
     present_plugin_dir = os.path.join(self.base_path, 'presentations')
     log.debug('finding plugins in %s at depth %d', str(self.base_path), start_depth)
     for root, dirs, files in os.walk(self.base_path):
         if sys.platform == 'darwin' and root.startswith(present_plugin_dir):
             # TODO Presentation plugin is not yet working on Mac OS X.
             # For now just ignore it. The following code will ignore files from the presentation plugin directory
             # and thereby never import the plugin.
             continue
         for name in files:
             if name.endswith('.py') and not name.startswith('__'):
                 path = os.path.abspath(os.path.join(root, name))
                 this_depth = len(path.split(os.sep))
                 if this_depth - start_depth > 2:
                     # skip anything lower down
                     break
                 module_name = name[:-3]
                 # import the modules
                 log.debug('Importing %s from %s. Depth %d', module_name, root, this_depth)
                 try:
                     # Use the "imp" library to try to get around a problem with the PyUNO library which
                     # monkey-patches the __import__ function to do some magic. This causes issues with our tests.
                     # First, try to find the module we want to import, searching the directory in root
                     fp, path_name, description = imp.find_module(module_name, [root])
                     # Then load the module (do the actual import) using the details from find_module()
                     imp.load_module(module_name, fp, path_name, description)
                 except ImportError as e:
                     log.exception('Failed to import module %s on path %s: %s', module_name, path, e.args[0])
     plugin_classes = Plugin.__subclasses__()
     plugin_objects = []
     for p in plugin_classes:
         try:
             plugin = p()
             log.debug('Loaded plugin %s', str(p))
             plugin_objects.append(plugin)
         except TypeError:
             log.exception('Failed to load plugin %s', str(p))
     plugins_list = sorted(plugin_objects, key=lambda plugin: plugin.weight)
     for plugin in plugins_list:
         if plugin.check_pre_conditions():
             log.debug('Plugin %s active', str(plugin.name))
             plugin.set_status()
         else:
             plugin.status = PluginStatus.Disabled
         self.plugins.append(plugin)
コード例 #4
0
ファイル: pluginmanager.py プロジェクト: imkernel/openlp
 def find_plugins(self):
     """
     Scan a directory for objects inheriting from the ``Plugin`` class.
     """
     start_depth = len(os.path.abspath(self.base_path).split(os.sep))
     present_plugin_dir = os.path.join(self.base_path, 'presentations')
     self.log_debug('finding plugins in {path} at depth {depth:d}'.format(path=self.base_path, depth=start_depth))
     for root, dirs, files in os.walk(self.base_path):
         for name in files:
             if name.endswith('.py') and not name.startswith('__'):
                 path = os.path.abspath(os.path.join(root, name))
                 this_depth = len(path.split(os.sep))
                 if this_depth - start_depth > 2:
                     # skip anything lower down
                     break
                 module_name = name[:-3]
                 # import the modules
                 self.log_debug('Importing {name} from {root}. Depth {depth:d}'.format(name=module_name,
                                                                                       root=root,
                                                                                       depth=this_depth))
                 try:
                     # Use the "imp" library to try to get around a problem with the PyUNO library which
                     # monkey-patches the __import__ function to do some magic. This causes issues with our tests.
                     # First, try to find the module we want to import, searching the directory in root
                     fp, path_name, description = imp.find_module(module_name, [root])
                     # Then load the module (do the actual import) using the details from find_module()
                     imp.load_module(module_name, fp, path_name, description)
                 except ImportError as e:
                     self.log_exception('Failed to import module {name} on path {path}: '
                                        '{args}'.format(name=module_name, path=path, args=e.args[0]))
     plugin_classes = Plugin.__subclasses__()
     plugin_objects = []
     for p in plugin_classes:
         try:
             plugin = p()
             self.log_debug('Loaded plugin {plugin}'.format(plugin=str(p)))
             plugin_objects.append(plugin)
         except TypeError:
             self.log_exception('Failed to load plugin {plugin}'.format(plugin=str(p)))
     plugins_list = sorted(plugin_objects, key=lambda plugin: plugin.weight)
     for plugin in plugins_list:
         if plugin.check_pre_conditions():
             self.log_debug('Plugin {plugin} active'.format(plugin=str(plugin.name)))
             plugin.set_status()
         else:
             plugin.status = PluginStatus.Disabled
         self.plugins.append(plugin)