Пример #1
0
    def parseFile(self, file):
        try:
            self.logger.error('#### Start parsing the "%s" file.####\n' % file)
            self.tree = eparse(file)
            self.treeRoot = self.tree.getroot()
        except:
            raise Exception, 'Couln\'t parse the "%s" file.' % file
        self.startID = 0
        self.getUniqueCos()
        self.setStartID()
        self.synCosToProfileId()

        splitPath = (self.config['ProfilePath']).split('/')
        if os.path.basename(self.currentFile).startswith('conf.Gw'):
            basePath = splitPath[0] + '/' + splitPath[1]
        elif os.path.basename(self.currentFile).startswith('conf.sm'):
            basePath = splitPath[0]
        elem = self.treeRoot.find(basePath)

        if elem != None:
            self.createNewProfiles(elem)
            self.setStates()
            self.Formatter(elem = self.treeRoot)
            self.Writer(self.tree)
            self.logger.error('')
            self.logger.error('#### Finish to parse the "%s" file. ####\n' % file)
        else:
            raise Exception, 'Element "%s" not found.' % basePath
Пример #2
0
    def __ParseXmlFile(self, fileName):
        '''
        Parses a given file and returns the tree and it's root.
        Gets: (editFile) path to the file to parse, as string.
        Returns: (tree) element tree instance, (treeRoot) root as
                 xml node.
        '''
        __name__ = '__ParseXmlFile()'
        self.logger.debug('[%s] Accessing %s...' % (self.__Blu('i'), __name__))

        tree = eparse(fileName)
        treeRoot = tree.getroot()
        return tree, treeRoot