def parents(self): """root block of this config item""" if hasattr(self, '__parents'): return self.__parents self.__parents = ConfigItems() current = self.block while current and not current.isRoot(): self.__parents.append(current) current = current.block return self.__parents
def parseApacheConf(self, content, contentPath="", contentName=""): """ Parse Apache Config :param content: content of Apache config :param contentPath: the file path of the given content :param contentName: the file name of the given content """ if content is None: return self.rootBlock = Block('', is_root=True) self.items = ConfigItems() self.contentsIterator = self.ContentsIterator() currentBlock = self.rootBlock self.contentsIterator.addContent(self.shell, content, contentPath, contentName) for iterator in self.contentsIterator: line, lineNumber, path, name = iterator if not line: continue line = line.strip() if not line or line[0] == '#': continue try: parserRule = getApacheConfParserRule(line) if parserRule: item = parserRule.parse(line) if item and isinstance(item, ConfigItem): currentBlock.appendChild(item) self.items.append(item) currentBlock = parserRule.getNextBlock(item, currentBlock) parserRule.postParse(self, item, path) else: logger.warn( "cannot find parser rule for config: %s. (%s Line %s)" % (line, getPathOperation(self.shell).join( path, name), lineNumber)) except ApacheConfigParserException, e: raise ApacheConfigParserException( '%s: %s Line %s' % (e.message, getPathOperation( self.shell).join(path, name), lineNumber))
def __init__(self, shell): self.shell = shell self.rootBlock = Block( '', is_root=True) # the root block of the Apache config self.items = ConfigItems() # all the parsed config items self.contentsIterator = self.ContentsIterator()
def __init__(self, name, value=None, block=None, is_root=False): super(Block, self).__init__(name, value, block) self.__configs = ConfigItems() # config items direct in the block self.__is_root = is_root # if this block is root block