def __init__(self, identifier, source): """Construct a new Addon object. @param identifier The identifier of the addon. @param source The full path name of the source file. """ self.id = identifier self.name = '' self.category = aodb.getRootCategory() self.source = source self.priority = 'z' self.requiredComponents = [] self.excludedCategories = [] self.box = None # When an addon is uninstalled, it will be hidden in the user # interface. self.uninstalled = False # Contains tuples: (type, identifier). self.keywords = {} for t in [EXCLUDES, REQUIRES, PROVIDES, OFFERS]: self.keywords[t] = [] # Every addon provides itself. self.keywords[PROVIDES].append(identifier) self.lastModified = None # If no other translation is given, the identifier of the # addon is shown as the base name of the source. if not language.isDefined(identifier): language.define('english', identifier, os.path.basename(source))
def readMetaData(self): """Read the metadata files (e.g. Contents/Info).""" try: for info in META_NAMES: try: conf = file(self.__makePath(info)).read() self.parseConfiguration(conf) except OSError: pass except IOError: pass except Exception, x: logger.add(logger.HIGH, 'error-read-info-file', self.__makePath(info), self.getId()) except: # Log a warning? traceback.print_exc() # Load a readme from a separate file. readme = self.__makePath('Readme.html') if not os.path.exists(readme): readme = self.__makePath('readme.html') if os.path.exists(readme): language.define('english', self.makeLocalId('readme'), file(readme).read())
def parseConfiguration(self, configSource): """Parse the given configuration data and process it as this addon's metadata. @param configSource The raw configuration data. """ try: p = cfparser.Parser(configSource) while True: elem = p.get() if elem.isBlock() and elem.getType() == 'language': language.processLanguageBlock(elem, self.getId()) elif elem.isKey() and elem.getName() == 'name': self.setName(elem.getValue()) # A shortcut for defining the name of the addon. language.define('english', self.getId(), self.getName()) # Automatically define the name of a box part. if self.getBox(): language.define('english', self.getBox().getId() + '-' + self.getId(), self.getName()) elif elem.getName() == 'component': self.requiredComponents += elem.getContents() elif elem.isKey() and elem.getName() == 'category': # The category of an addon inside a box is # relative to the box. if self.getBox(): catPath = self.getBox().getCategory().getPath() + \ '/' + self.getBox().getId() + '/' else: catPath = '' catPath += elem.getValue() self.category = aodb._getCategory(catPath) elif elem.isKey() and elem.getName() == 'order': self.setPriority(elem.getValue()) elif elem.getName() == 'excludes-category': identifiers = elem.getContents() for id in identifiers: self.excludedCategories.append(aodb._getCategory(id)) elif elem.getName() == 'excludes': self.addKeywords(EXCLUDES, elem.getContents()) elif elem.getName() == 'requires': self.addKeywords(REQUIRES, elem.getContents()) elif elem.getName() == 'provides': self.addKeywords(PROVIDES, elem.getContents()) elif elem.getName() == 'offers': self.addKeywords(OFFERS, elem.getContents()) elif elem.isBlock(): # Convert the identifier to local form. elem.setName(self.makeLocalId(elem.getName())) # Determine the owner of this setting. if self.getBox() == None: ownerId = self.getId() else: ownerId = self.getBox().getId() # The addon's identifier determines the group. elem.add(cfparser.KeyElement('group', self.getId())) elem.add(cfparser.KeyElement('addon', ownerId)) import confdb confdb.processSettingBlock(elem) except cfparser.OutOfElements: pass
def parseConfiguration(self, configSource): """Parse the given configuration data and process it as this addon's metadata. @param configSource The raw configuration data. """ try: p = cfparser.Parser(configSource) while True: elem = p.get() if elem.isBlock() and elem.getType() == 'language': language.processLanguageBlock(elem, self.getId()) elif elem.isKey() and elem.getName() == 'name': self.setName(elem.getValue()) # A shortcut for defining the name of the addon. language.define('english', self.getId(), self.getName()) # Automatically define the name of a box part. if self.getBox(): language.define( 'english', self.getBox().getId() + '-' + self.getId(), self.getName()) elif elem.getName() == 'component': self.requiredComponents += elem.getContents() elif elem.isKey() and elem.getName() == 'category': # The category of an addon inside a box is # relative to the box. if self.getBox(): catPath = self.getBox().getCategory().getPath() + \ '/' + self.getBox().getId() + '/' else: catPath = '' catPath += elem.getValue() self.category = aodb._getCategory(catPath) elif elem.isKey() and elem.getName() == 'order': self.setPriority(elem.getValue()) elif elem.getName() == 'excludes-category': identifiers = elem.getContents() for id in identifiers: self.excludedCategories.append(aodb._getCategory(id)) elif elem.getName() == 'excludes': self.addKeywords(EXCLUDES, elem.getContents()) elif elem.getName() == 'requires': self.addKeywords(REQUIRES, elem.getContents()) elif elem.getName() == 'provides': self.addKeywords(PROVIDES, elem.getContents()) elif elem.getName() == 'offers': self.addKeywords(OFFERS, elem.getContents()) elif elem.isBlock(): # Convert the identifier to local form. elem.setName(self.makeLocalId(elem.getName())) # Determine the owner of this setting. if self.getBox() == None: ownerId = self.getId() else: ownerId = self.getBox().getId() # The addon's identifier determines the group. elem.add(cfparser.KeyElement('group', self.getId())) elem.add(cfparser.KeyElement('addon', ownerId)) import confdb confdb.processSettingBlock(elem) except cfparser.OutOfElements: pass
# Should be use an existing profile? profile = get(identifier) if not profile: # Create a new blank profile. profile = sb.profile.Profile(identifier) # Add it to the main list of profiles. global profiles profiles.append(profile) # Process all the elements. for e in elements: if e.isKey() and e.getName() == 'name': # The user-provided name. profile.setName(e.getValue()) language.define('english', identifier, profile.getName()) elif e.isKey() and e.getName() == 'active': # The identifier of the active profile. This is stored in # the Defaults profile and restore() uses it to return to # the active profile that was used when save() was called. global restoredActiveId restoredActiveId = e.getValue() elif e.isKey() and e.getName() == 'hidden': profile.setHidden(e.getValue() == 'yes') elif e.isList() and e.getName() == 'load-order': profile.setLoadOrder(e.getContents()) elif e.isKey() and e.getName() == 'story':
def setName(self, name): self.name = name # Define this in the english language so it will available for # translation. language.define('english', self.identifier, name)