def next(self): self.currentLineNumber += 1 # treat multiple line ending with '\'; combine them to one line while self.currentLineNumber < self.maxLineNumber and \ self.contents[self.currentLineNumber] and \ self.contents[self.currentLineNumber].replace('\\\\', '')[-1] == '\\': if self.currentLineNumber + 1 < self.maxLineNumber: self.contents[self.currentLineNumber + 1] = '%s%s' % ( self.contents[self.currentLineNumber][0:-1], self.contents[self.currentLineNumber + 1]) self.currentLineNumber += 1 else: raise ApacheConfigParserException("Illegal content end: '\\'. %s Line %s" % ( getApacheConfParserRule(self.shell).join(self.filePath, self.fileName), self.currentLineNumber)) if self.currentLineNumber < self.maxLineNumber: return self else: raise StopIteration
def next(self): self.currentLineNumber += 1 # treat multiple line ending with '\'; combine them to one line while self.currentLineNumber < self.maxLineNumber and \ self.contents[self.currentLineNumber] and \ self.contents[self.currentLineNumber].replace('\\\\', '')[-1] == '\\': if self.currentLineNumber + 1 < self.maxLineNumber: self.contents[self.currentLineNumber + 1] = '%s%s' % ( self.contents[self.currentLineNumber][0:-1], self.contents[self.currentLineNumber + 1]) self.currentLineNumber += 1 else: raise ApacheConfigParserException( "Illegal content end: '\\'. %s Line %s" % (getApacheConfParserRule(self.shell).join( self.filePath, self.fileName), self.currentLineNumber)) if self.currentLineNumber < self.maxLineNumber: return self else: raise StopIteration
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 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))