def __loadPlugin__(pathPluginsTypes, plugin, key, iou=None): """ @summary: Load a plugin. @param pathPluginsTypes: Path of directory where plugin is. @param key: Name of directory parent. @param plugin: Name of plugin. @param iou: IOUtils object. @return: Int with value of op. 0 - Ok 1 - No deps 2 - Fail """ iRes = 0 delIou = False if iou == None: delIou = True iou = IOUtils() py_mod = None filesPluginPath = os.path.join(pathPluginsTypes, plugin) files = iou.getFiles(filesPluginPath) isPlugin = False isCompilled = False if ((files.count("camimgplugin.py") > 0) and (files.count("__init__.py") > 0)): isCompilled = False isPlugin = True """ if ((files.count("camimgplugin.pyc") > 0) and (files.count("__init__.pyc") > 0)): isCompilled = True isPlugin = True """ if (isPlugin): pluginPath = os.path.join(filesPluginPath, "camimgplugin.pyc" if isCompilled else "camimgplugin.py") pluginModAccess = ("%s.%s" % (key, plugin)) if (not isCompilled): pluginPackagePath = os.path.join(filesPluginPath, "__init__.py") imp.load_source(pluginModAccess, pluginPackagePath) __log__.debug("__init__.py imported from package %s", filesPluginPath) py_mod = imp.load_source("%s.cammingplugin" % pluginModAccess, pluginPath) else: pluginPackagePath = os.path.join(filesPluginPath, "__init__.pyc") imp.load_compiled(pluginModAccess, pluginPackagePath) __log__.debug("__init__.pyc imported from package %s", filesPluginPath) py_mod = imp.load_compiled("%s.cammingplugin" % pluginModAccess, pluginPath) __log__.info("It detected a plugin in %s" % pluginPath) if (isPlugin and (py_mod != None)): sys.path.append(filesPluginPath) if __classplugin__ in dir(py_mod): __log__.debug("Loading %s..." % pluginPath) plugin = py_mod.camimgplugin() if (plugin.getType() != None): py_mod_class = None if (plugin.isNeedLoad()): if ((plugin.getPluginDependecies() != None) and (len(plugin.getPluginDependecies()) > 0)): for dep in plugin.getPluginDependecies(): if not (dep in pluginsLoadedArray): iRes = 1 __log__.info("\t%s deps no satisfied." % pluginPath) break if (iRes == 0): if (plugin.isCompiled()): __log__.debug("\t%s is compiled plugin." % pluginPath) pluginPath = os.path.join(filesPluginPath, "%s.pyc" % plugin.getPluginModule()) pluginModName = "%s.%s" % (pluginModAccess, plugin.getPluginModule()) try: py_mod_class = imp.load_compiled(pluginModName, pluginPath) except ImportError, ie: __log__.error("It could not load %s from %s. %s" % (pluginModName, pluginPath, ie)) iRes = 2 else: __log__.debug("\t%s is source plugin." % pluginPath) pluginPath = os.path.join(filesPluginPath, "%s.py" % plugin.getPluginModule()) pluginModName = "%s.%s" % (pluginModAccess, plugin.getPluginModule()) try: py_mod_class = imp.load_source(pluginModName, pluginPath) except ImportError, ie: __log__.error("It could not load %s from %s. %s" % (pluginModName, pluginPath, ie)) iRes = 2 else: __log__.debug("\t%s is need load." % pluginPath) if (iRes == 0): if (pluginsLoaded.has_key(plugin.getType())): pluginsLoaded[plugin.getType()].append((plugin, (py_mod_class.CamimgPlugin if py_mod_class else None))) else: pluginsLoaded[plugin.getType()] = [(plugin, (py_mod_class.CamimgPlugin if py_mod_class else None))] pluginsLoadedArray.append(plugin.getId()) plugin.initialize() else: __log__.warning("It can not determinate type of the plugin %s" % pluginPath)
def __addTargetFiles__(self, files, defaultIcon, iterOp, iter=None, position=gtk.TREE_VIEW_DROP_AFTER, recursiveLevel=0, gtkLock=True): """ @summary: Add files to target listview. @param files: List of files to add. @param defaultIcon: Default icon to associate with each file. @param iterOp: GtkIter of operation progress bar. @param recursiveLevel: Current recursive level. @param iter: Iter that it will use as reference to insert new files. @param position: Position over iter. @param gtkLock: True to do a lock on gtk loop. """ if (files != None): operations = RegOperations() # Add each file into target TreeView for file in files: __log__.debug("Adding %s" % file) if (iterOp != None): operations.stepOperation(iterOp) if (file == ""): __log__.warn("Empty file path. Skip file") continue if (self.__core__.getItem(file) != None): __log__.info("File %s already exists in target file list" % file) continue # Checks if is a folder and system is configured to add files recursively if (os.path.isdir(file) and Configuration().getConfiguration().getboolean("UI_CORE", "add_recursive")): __log__.debug("%s is folder. Adding images into folder." % file) # Do recursivity if (recursiveLevel < Configuration().getConfiguration().getint("UI_CORE", "recursive_level")): ioUtils = IOUtils() listNewFiles = [] if ((recursiveLevel + 1) != Configuration().getConfiguration().getint("UI_CORE", "recursive_level")): listNewFiles += ioUtils.getDirectories(file, Configuration().getConfiguration().getboolean("NAVIGATOR", "show_hiddens"), getFullpath=True) listNewFiles += ioUtils.getFiles(file, Configuration().getConfiguration().getboolean("NAVIGATOR", "show_hiddens"), getFullpath=True) __log__.debug("Adding images from folder %s" % file) operations.addElements(iterOp, len(listNewFiles), gtkLock=gtkLock) self.__addTargetFiles__(listNewFiles, defaultIcon, iterOp, iter=iter, position=position, recursiveLevel=(recursiveLevel + 1), gtkLock=gtkLock) del ioUtils else: __log__.debug("Max. recursive level got.") continue head, filename = os.path.split(file) item = CamItem(file, target=filename) __log__.debug("New CamItem created for filename %s. %s" % (filename, item)) # Create a new row newRowData = [defaultIcon, file, _("Loading..."), filename , item.getDescription(), defaultIcon, False, True] iterAdd = UIUtils.insertIterAtPathPosition(self.__model__, newRowData, iter, position=position, doGObject=gtkLock) __log__.info("New file inserted into target treeview. %s" % file) if (iterAdd != None): self.__core__.addItem(file, item) self.updateItem(iterAdd, item, gtkLock=gtkLock) else: __log__.error("It could not insert new item into project. %s" % file) del newRowData del item else: __log__.warning("Files parameter is None")