Example #1
0
    def loadFile(self, ruleset_context, filetype, name,
    editable=False, from_template=None, action=None, ruleset_id=0,
    filename=None, content=None):
        # Log the action
        logger = ruleset_context.logger
        text = "Load %s: %s" % (filetype, name)
        if ruleset_id == 0:
            logger.info(text)
        else:
            logger.debug(text)

        if not content:
            # Get the filename
            if not filename:
                if filetype == "library":
                    filename = LIBRARY_FILENAME
                else:
                    filename = rulesetFilename(filetype, name)

            # Parse the XML file
            try:
                with open(filename) as fp:
                    ruleset = etree.parse(fp).getroot()
            except IOError, err:
                if err.errno == ENOENT:
                    if filetype == 'template':
                        message = tr('The "%s" template does not exist. It has been deleted or renamed.')
                    else:
                        message = tr('The "%s" rule set does not exist. It has been deleted or renamed.')
                    raise RulesetError(message, name)
                else:
                    raise RulesetError(
                        tr('Unable to open file "%s" (%s): %s'),
                        basename(filename), filetype, exceptionAsUnicode(err))
Example #2
0
 def load(self):
     if not exists(self.filename):
         return
     try:
         with open(self.filename) as fp:
             xml = etree.parse(fp).getroot()
     except IOError, err:
         raise RulesetError(
             tr('Unable to open the generic links file: %s'),
             exceptionAsUnicode(err))
Example #3
0
 def load(self, filename):
     """
     Loads an xml file and fills this VariablesStore object with it.
     """
     try:
         with open(filename) as fp:
             tree = ET.parse(fp)
         root = tree.getroot()
     except IOError, err:
         raise ConfigError(CONFIG_NO_SUCH_FILE,
             tr('Unable to open %s XML file: %s!'),
             filename, exceptionAsUnicode(err))