def decorateResult(self, session, decorator_helper=None): if (not session): raise Exception("Can not decorate result without valid session.") if (session.getResult() == None): return (decorator_helper.pre(defaults.STRING_EMPTY), 1) if ((not session.getRouter()) or (not decorator_helper)): return "<pre>\n%s\n</pre>" % session.getResult() table = [] table_header = [ 'Prefix', 'Next-hop', 'Interface', 'Since', 'Status', 'Metric', 'Info', ] lines = str.splitlines(session.getResult()) result_len = len(lines) lines = lines[session.getRange():session.getRange() + defaults.range_step] table = self._genTable(lines, decorator_helper, session.getRouter()) return (ulgmodel.TableDecorator(table, table_header).decorate(), result_len)
def decorateResult(self, session, decorator_helper=None): if (not session): raise Exception("Can not decorate result without valid session.") if (session.getResult() == None): return (decorator_helper.pre(defaults.STRING_EMPTY), 1) if ((not session.getRouter()) or (not decorator_helper)): return "<pre>\n%s\n</pre>" % session.getResult() else: pr = parseBirdShowProtocols(session.getResult()) table_header = pr[0] table = [] for tl in pr[1][session.getRange():session.getRange() + defaults.range_step]: # skip when there is a filter and it does not match the protocol type if (self.fltr) and (not re.match(self.fltr, tl[1])): continue table.append( self._decorateTableLine(tl, session.getRouter(), decorator_helper)) return (ulgmodel.TableDecorator(table, table_header).decorate(), pr[2])
def decorateResult(self, session, decorator_helper=None): if (not session): raise Exception('Can not decorate result without valid session.') if (session.getResult() == None): return (decorator_helper.pre(defaults.STRING_EMPTY), 1) if ((not session.getRouter()) or (not decorator_helper)): return "<pre>\n%s\n</pre>" % session.getResult() lines = [] res = '' for l in normalizeBGPIPv6SumSplitLines( str.splitlines(session.getResult())): lines.append(l) before = '' after = '' table = [] table_header = [] tb = False header_regexp = re.compile(self.TABLE_HEADER_REGEXP) line_regexp = re.compile(self.TABLE_LINE_REGEXP) for l in lines: if (tb): # inside table body table.append( self._decorateTableLine(l, decorator_helper, session.getRouter())) else: # should we switch to table body? thrm = header_regexp.match(l) if (thrm): tb = True table_header = [g for g in thrm.groups()] else: # not yet in the table body, append before-table section before = before + l + '\n' result_len = len(table) table = table[session.getRange():session.getRange() + defaults.range_step] return (ulgmodel.TableDecorator( table, table_header, before=decorator_helper.pre(before)).decorate(), result_len)
def decorateResult(self, session, decorator_helper=None): def restrict(lines, start, count): res = [] s = start r = re.compile("^\s{6,}.*") while (r.match(lines[s]) and s > 0): s = s - 1 e = s + count if (e >= len(lines)): e = len(lines) - 1 while (r.match(lines[e]) and e < (len(lines) - 1)): e = e + 1 return lines[s:e] if (not session): raise Exception( "Can not decorate result without valid session passed.") if (session.getResult() == None): return (decorator_helper.pre(defaults.STRING_EMPTY), 1) if ((not session.getRouter()) or (not decorator_helper)): return "<pre>\n%s\n</pre>" % session.getResult() lines = str.splitlines(session.getResult()) before = '' after = None table = [] table_header_descr = [] tb = False header_regexp = re.compile(self.TABLE_HEADER_REGEXP) lastline_regexp = re.compile(self.LASTLINE_REGEXP) table_lines = [] for l in lines: if (tb): # inside table body if (lastline_regexp.match(l)): after = l else: table_lines.append(l) else: # should we switch to table body? thrm = header_regexp.match(l) if (thrm): # set header accoring to the local router alignment # include (unnamed) states (=S) self.table_header = 'S' + (l[1:].replace( 'Next Hop', 'Next_Hop', 1)) tb = True table_header_descr = [g for g in thrm.groups()] else: # not yet in the table body, append before-table section before = before + l + '\n' result_len = len(table_lines) if (table_lines): table = self._genTable( restrict(table_lines, session.getRange(), defaults.range_step), decorator_helper, session.getRouter()) if (after): after = decorator_helper.pre(after) return (ulgmodel.TableDecorator(table, table_header_descr, before=decorator_helper.pre(before), after=after).decorate(), result_len)