def loadBundle(path): """Load a plugin bundle that may contain multiple .py modules, plus directories. The bundle directories will be included in file searching in paths.py. @param path The location of the plugin bundle. """ contentsPath = os.path.join(path, 'Contents') # Include the bundle contents in the module search path (for the # duration of this function). oldSysPath = sys.path sys.path = [contentsPath] + sys.path # Register the bundle path into paths.py. paths.addBundlePath(contentsPath) # Make the appropriate calls to read the configuration and # language files in the bundle. readBundleConfig(contentsPath) # Load all of the .py modules in the bundle's Python package. package = paths.getBase(path) packagePath = os.path.join(contentsPath, package) for name in os.listdir(packagePath): fullName = os.path.join(packagePath, name) if name != '__init__.py' and paths.hasExtension('py', fullName): loadSingle(fullName, package) # Restore the previous module search path. sys.path = oldSysPath
def loadAll(): "Load all the plugins from the plugins directory." global initCommands initCommands = [] # We'll only use the modified sys.path during this function. oldPath = sys.path # Make the plugins directory the one where to look first. sys.path = [PLUGIN_PATH] + sys.path found = [] for fileName in paths.listFiles(paths.PLUGINS): if paths.hasExtension('py', fileName) or \ (paths.hasExtension('plugin', fileName) and os.path.isdir(fileName)): if fileName not in found: found.append(fileName) # Sort alphabetically across all located plugins. found.sort(key=sortKey) for fileName in found: if paths.hasExtension('py', fileName): loadSingle(fileName) # Single Python module. elif paths.hasExtension('plugin', fileName): loadBundle(fileName) # A plugin bundle. # Import all plugin modules. for importStatement, initStatement, searchPath in initCommands: sys.path = searchPath try: exec importStatement except: logger.add(logger.HIGH, 'error-plugin-init-failed', importStatement, logger.formatTraceback()) # Initialize all plugins. for importStatement, initStatement, searchPath in initCommands: sys.path = searchPath try: exec initStatement except AttributeError, ex: if "'init'" not in str(ex): logger.add(logger.HIGH, 'error-plugin-init-failed', initStatement, logger.formatTraceback()) except:
def loadAll(): """Load the <tt>.lang</tt> files from the lang directories. """ for fileName in paths.listFiles(paths.LANG, False): # We'll load all the files with the .lang extension. if paths.hasExtension('lang', fileName): # Load this language file. load(fileName)
def getLanguages(): langs = [] for fileName in paths.listFiles(paths.LANG): # We'll load all the files with the .lang extension. if paths.hasExtension('lang', fileName): langs.append(paths.getBase(fileName)) return langs
def getCommandLine(self, profile): """Return the command line options to load and configure the addon. This basic implementation assumes no configurability and a single source file. """ if not paths.hasExtension('manifest', self.source): return '-file ' + paths.quote(self.source) else: return ''
def loadPath(path): """Land all the <tt>.lang</tt> files from the specified directory. @param path Directory to read from. """ if not os.path.exists(path): return for name in os.listdir(path): if paths.hasExtension('lang', name): load(os.path.join(path, name))
def updateList(): # Update the found addons list. foundList.clear() dialog.disableWidget(actionButton) extensions = ao.getAddonExtensions() + ['manifest'] # This should be done in addons.py. fileNames = os.listdir(pathField.getText()) for name in fileNames: type = '' for ext in extensions: if paths.hasExtension(ext, name): type = ext break if not type: # Unknown files are skipped. continue # Manifests don't appear in the list if the corresponding # addon is in the same directory. if paths.hasExtension('manifest', name): foundSame = False # Identifier of the addon the manifest belongs to. manifestId = paths.getBase(name) # See if the addon is in the list. for other in fileNames: if other == name: continue if manifestId == ao.formIdentifier(other)[0]: foundSame = True break if foundSame: # Don't add it. continue foundList.addItemWithColumns( name, name, language.translate('addon-dialog-type-' + type))
def readConfigPath(path): """Load all the config files in the specified directory. @param path Directory path. """ try: for name in os.listdir(path): # We'll load all the files with the .conf extension. if paths.hasExtension('conf', name): # Load this configuration file. readConfigFile(os.path.join(path, name)) except OSError: # Path does not exist. pass
def getCommandLine(self, profile): """Bundles are loaded with -file and -def. We'll load the contents of the Defs and Data directories. """ param = '' defsPath = self.__makePath('Defs') if os.path.exists(defsPath): defs = [] # Only include the files that have the .ded extension. for name in os.listdir(defsPath): path = os.path.join(defsPath, name) if paths.hasExtension('ded', path): defs.append(paths.quote(path)) if len(defs) > 0: # At least one definition file was found. param += '-def ' + string.join(defs) dataPath = self.__makePath('Data') if os.path.exists(dataPath): data = [] # Only include the files with known extensions. for name in os.listdir(dataPath): path = os.path.join(dataPath, name) if paths.hasExtension('pk3', path) or \ paths.hasExtension('wad', path) or \ paths.hasExtension('lmp', path): data.append(paths.quote(path)) if len(data): # At least one data file was found. param += ' -file ' + string.join(data) return param
def loadAll(): """Load all addons and manifests.""" # Load all the installed addons in the system and user addon # databases. for repository in [paths.ADDONS] + paths.getAddonPaths(): for name in paths.listFiles(repository): # Case insensitive. if re.search("(?i)^([^.#].*)\.(" + string.join(ao.EXTENSIONS, "|") + ")$", os.path.basename(name)): load(name) # Load all the manifests. for folder in [paths.getSystemPath(paths.MANIFESTS), paths.getUserPath(paths.MANIFESTS)] + paths.getAddonPaths(): for name in paths.listFiles(folder): # Case insensitive. if paths.hasExtension("manifest", name): loadManifest(name)
def install(sourceName): """Installs the specified addon into the user's addon database. @param fileName Full path of the addon to install. @throw AddonFormatError If the addon is not one of the recognized formats, this exception is raised. @return Identifier of the installed addon. @throws Exception The installation failed. """ isManifest = paths.hasExtension('manifest', sourceName) if isManifest: # Manifests are copied to the manifest directory. destPath = paths.getUserPath(paths.MANIFESTS) else: destPath = paths.getUserPath(paths.ADDONS) destName = os.path.join(destPath, os.path.basename(sourceName)) try: # Directories must be copied as a tree. if os.path.isdir(sourceName): shutil.copytree(sourceName, destName) else: shutil.copy2(sourceName, destName) # Load the new addon. if not isManifest: identifier = load(destName) else: identifier = loadManifest(destName) # Now that the addon has been installed, save the updated cache. writeMetaCache() # Send a notification of the new addon. notify = events.Notify('addon-installed') notify.addon = identifier events.send(notify) except Exception, x: # Unsuccessful. raise x
def install(sourceName): """Installs the specified addon into the user's addon database. @param fileName Full path of the addon to install. @throw AddonFormatError If the addon is not one of the recognized formats, this exception is raised. @return Identifier of the installed addon. @throws Exception The installation failed. """ isManifest = paths.hasExtension("manifest", sourceName) if isManifest: # Manifests are copied to the manifest directory. destPath = paths.getUserPath(paths.MANIFESTS) else: destPath = paths.getUserPath(paths.ADDONS) destName = os.path.join(destPath, os.path.basename(sourceName)) try: # Directories must be copied as a tree. if os.path.isdir(sourceName): shutil.copytree(sourceName, destName) else: shutil.copy2(sourceName, destName) # Load the new addon. if not isManifest: identifier = load(destName) else: identifier = loadManifest(destName) # Now that the addon has been installed, save the updated cache. writeMetaCache() # Send a notification of the new addon. notify = events.Notify("addon-installed") notify.addon = identifier events.send(notify) except Exception, x: # Unsuccessful. raise x
def _listProfilesIn(locations): """Compose a list of profile file names by reading from the specified locations. @param paths A list of directory paths. @return An array of absolute file names. """ names = [] for path in locations: try: for name in os.listdir(path): if paths.hasExtension('prof', name): names.append(os.path.join(path, name)) except OSError: # Such a location does not exist, ignore it. pass return names
def loadAll(): """Load all addons and manifests.""" # Load all the installed addons in the system and user addon # databases. for repository in [paths.ADDONS] + paths.getAddonPaths(): for name in paths.listFiles(repository): # Case insensitive. if re.search("(?i)^([^.#].*)\.(" + \ string.join(ao.EXTENSIONS, '|') + ")$", os.path.basename(name)): load(name) # Load all the manifests. for folder in [paths.getSystemPath(paths.MANIFESTS), paths.getUserPath(paths.MANIFESTS)] + \ paths.getAddonPaths(): for name in paths.listFiles(folder): # Case insensitive. if paths.hasExtension('manifest', name): loadManifest(name)