Пример #1
0
    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
Пример #2
0
def processSettingBlock(e):
    """Process a Block that contains the definition of a setting.

    @param e A cfparser.BlockElement object.
    """
    if not e.isBlock():
        return

    # First check for generic configuration options.  These can't be
    # changed in the user interface.
    if e.getType() == 'appearance' or e.getType() == 'configure':
        # Insert the keys into the system configuration dictionary.
        for key in e.getContents():
            if e.getName() == 'addon-path':
                # A custom addon path.
                paths.addAddonPath(key.getValue())
            else:
                # Regular sysConfig string.
                fullName = e.getName() + '-' + key.getName()
                sysConfig[fullName] = key.getValue()
        return
        
    # Check for languages.
    if e.getType() == 'language':
        language.processLanguageBlock(e)
        return
    
    setting = None

    # Each block represents either a component or a setting.
    if e.getType() == 'component':
        # Create a new component.
        _newComponent(conf.Component(e.getName(),
                                     e.findValue('setting'),
                                     e.findValue('option')))

    elif e.getType() == 'toggle':
        setting = conf.ToggleSetting(e.getName(),
                                     e.findValue('option'),
                                     e.findValue('default'),
                                     e.findValue('option-inactive'))

    elif e.getType() == 'implicit':
        setting = conf.Setting(e.getType(), e.getName(), e.findValue('option'))

    elif e.getType() == 'range':
        setting = conf.RangeSetting(e.getName(),
                                    e.findValue('option'),
                                    e.findValue('min'),
                                    e.findValue('max'),
                                    e.findValue('default'),
                                    e.findValue('suffix'))

    elif e.getType() == 'slider':
        setting = conf.SliderSetting(e.getName(),
                                     e.findValue('option'),
                                     e.findValue('min'),
                                     e.findValue('max'),
                                     e.findValue('step'),
                                     e.findValue('default'),
                                     e.findValue('suffix'))

    elif e.getType() == 'text':
        setting = conf.TextSetting(e.getName(),
                                   e.findValue('option'),
                                   e.findValue('default'))

    elif e.getType() == 'file':
        # Is there a list of allowed file types?
        allowedTypes = []
        typeBlock = e.find('types')
        if typeBlock and typeBlock.isBlock() and \
           typeBlock.getType() == 'allowed':
            for typeKey in typeBlock.getContents():
                allowedTypes.append((typeKey.getName(), typeKey.getValue()))
        
        setting = conf.FileSetting(e.getName(),
                                   e.findValue('option'),
                                   e.findValue('must-exist'),
                                   allowedTypes,
                                   e.findValue('default'))

    elif e.getType() == 'folder':
        setting = conf.FolderSetting(e.getName(),
                                     e.findValue('option'),
                                     e.findValue('must-exist'),
                                     e.findValue('default'))
                                      
    elif e.getType() == 'choice':
        # Identifiers of the choices.
        altsElement = e.find('alts')
        if altsElement:
            alts = altsElement.getContents()
        else:
            alts = []
            
        # Command line parameters of each choice.
        optsElement = e.find('opts')
        if optsElement:
            opts = optsElement.getContents()
        else:
            opts = []
                
        # Check what to do if existing choices are already defined.
        existing = e.findValue('existing')
        if existing == 'merge' and isSettingDefined(e.getName()):
            oldSetting = getSetting(e.getName())
            oldSetting.merge(alts, opts)
        else:
            # A totally new setting.
            setting = conf.ChoiceSetting(e.getName(),
                                         e.findValue('option'),
                                         alts, opts,
                                         e.findValue('default'))
                                     
    if setting:    
        # Any required values?
        req = e.find('equals')
        if req and req.getType() == 'require':
            for r in req.getContents():
                setting.addRequiredValue(r.getName(), r.getValue())
            
        # Grouping information?
        if e.find('group'):
            setting.setGroup(e.findValue('group'))
        if e.find('subgroup'):
            setting.setSubGroup(e.findValue('subgroup'))

        # Automatically append value after option on the command line?
        if e.find('value-after-option'):
            setting.setValueAfterOption(e.findValue('value-after-option'))
            
        # Any required components or addons?
        setting.addRequiredComponent(e.findValue('component'))
        setting.addRequiredAddon(e.findValue('addon'))
            
        # Add the setting to the dictionary of all settings.
        _newSetting(setting)
Пример #3
0
    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