From: <bl...@us...> - 2003-05-01 08:12:33
|
Update of /cvsroot/cpptool/rfta/bin In directory sc8-pr-cvs1:/tmp/cvs-serv6500/bin Modified Files: lister.py Log Message: * now generated an index.html page with link to all parsed result and statistics. Index: lister.py =================================================================== RCS file: /cvsroot/cpptool/rfta/bin/lister.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** lister.py 30 Apr 2003 22:10:49 -0000 1.1 --- lister.py 1 May 2003 08:12:30 -0000 1.2 *************** *** 46,49 **** --- 46,141 ---- os.makedirs( directory ) + class Tag: + def __init__( self, name, content = None ): + self.name = name + self.attributes = {} + if content == None: + self.content = '' + else: + self.content = content + self.children = [] + self.new_line_after = False + + def write( self, file ): + file.write( '<' + self.name + self.makeAttributesDeclaration() + '>' ) + file.write( self.getContent() ) + for child in self.children: + child.write( file ) + file.write( '</' + self.name + '>' ) + if self.new_line_after: + file.write( os.linesep ) + + def __repr__( self ): + return str( ["<" + self.name + self.makeAttributesDeclaration() + ">", self.content, self.children ] ) + + def makeAttributesDeclaration( self ): + if len( self.attributes ) == 0: + return '' + declaration = '' + for attribute in self.attributes.iteritems(): + declaration += ' ' + attribute[0] + '="' + attribute[1] + '"' + return declaration + + def getContent( self ): + content = '' + escaped_char = { '&' : '&', '<' : '<', '>' : '>', '"' : '"' } + for c in self.content: + if c in escaped_char: + content += escaped_char[c] + else: + content += c + return content + + def setAttribute( self, name, value ): + self.attributes[name] = value + return self + + def setAttributes( self, values ): + self.attributes.update( values ) + return self + + def addChild( self, child ): + self.children.append( child ) + return self + + def addChildren( self, children ): + self.children.extend( children ) + return self + + class ParagraphTag(Tag): + def __init__( self, content ): + Tag.__init__( self, 'P', content ) + self.new_line_after = True + + class LinkTag(Tag): + def __init__( self, url, content ): + Tag.__init__( self, 'A', content ) + self.setAttribute( 'HREF', url ) + + class LocalLinkTag(Tag): + def __init__( self, anchor_name, content ): + Tag.__init__( self, 'A', content ) + self.setAttribute( 'HREF', '#' + anchor_name ) + + class AnchorTag(Tag): + def __init__( self, anchor_name ): + Tag.__init__( self, 'A' ) + self.setAttribute( 'name', anchor_name ) + self.new_line_after = True + + class H2Tag(Tag): + def __init__( self, title ): + Tag.__init__( self, 'H2', title ) + + + PARSE_OK = 'Ok' + PARSE_FAILED = 'Failed' + PARSE_CRASH = "Crashed" + + class ParseResult: + def __init__( self, status, source_path, output_path ): + self.status = status + self.source_path = source_path + self.output_path = output_path class ASTGenerator: *************** *** 51,54 **** --- 143,147 ---- self.source_dir = source_dir self.output_dir = output_dir + self.parse_result = { } def generate( self, source_path ): *************** *** 59,66 **** Path(output_path).ensure_dir_exists() exit_code = os.spawnl( os.P_WAIT, "astdump", "astdump", source_path, output_path ) ! if exit_code != 0: ! print "Failed to generate AST for ", source_path ! --- 152,215 ---- Path(output_path).ensure_dir_exists() exit_code = os.spawnl( os.P_WAIT, "astdump", "astdump", source_path, output_path ) ! self.parse_result[ source_path ] = ParseResult( self.convertParseExitCode(exit_code), ! source_path, ! output_path ) ! ! def convertParseExitCode( self, code ): ! if code == 0: ! return PARSE_OK ! elif code == 2: ! return PARSE_FAILED ! else: ! return PARSE_CRASH ! ! def generateIndexPage( self, index_filename ): ! index_path = os.path.join( self.output_dir, index_filename ) ! html_file = open( index_path, 'w' ) ! title = 'AST dump of self.source_dir' ! html_tag = Tag('HTML') ! html_tag.addChild( Tag('HEAD').addChild( Tag('TITLE', title ) ) ) ! body_tag = Tag( 'BODY' ) ! html_tag.addChild( body_tag ) ! ! body_tag.addChildren( self.generateStatistics() ) ! body_tag.addChildren( self.generateResult() ) ! html_tag.write( html_file ) ! html_file.close() ! ! def generateStatistics( self ): ! test_passed = 0 ! test_failed = 0 ! test_crashed = 0 ! for test in self.parse_result.itervalues(): ! if test.status == PARSE_OK: ! test_passed += 1 ! elif test.status == PARSE_FAILED: ! test_failed += 1 ! else: ! test_crashed += 1 ! test_count = test_passed + test_failed + test_crashed ! ! if test_count == 0: ! return [ H2Tag( 'No test!' ) ] ! ! return [ H2Tag( 'Statistics:' ), ! ParagraphTag( 'Passed %d : %3d%%' % (test_passed, test_passed * 100 / test_count) ), ! ParagraphTag( 'Failed %d : %3d%%' % (test_failed, test_failed * 100 / test_count) ), ! ParagraphTag( 'Crashed %d : %3d%%' % (test_crashed, test_crashed * 100 / test_count) ), ! ParagraphTag( 'Total tests: %d' % test_count ) ] ! ! def generateResult( self ): ! tags = [ H2Tag( 'Results:' ) ] ! table_tag = Tag( 'TABLE' ).setAttributes( { 'WIDTH' : '100%', 'BORDER' : '0', 'COLS' : '2' } ) ! tags.append( table_tag ) ! for test in self.parse_result.itervalues(): ! row_tag = Tag( 'TR' ).setAttribute( 'ALIGN', 'left' ) ! relative_url = Path( test.output_path ).make_relative_to( self.output_dir ) ! row_tag.addChild( Tag( 'TD' ).addChild( LinkTag( relative_url, test.status ) ) ) ! row_tag.addChild( Tag( 'TD' ).addChild( ParagraphTag( test.source_path ) ) ) ! table_tag.addChild( row_tag ) ! return tags *************** *** 76,81 **** # os.path.walk(sys.argv[1], lister, None) # dir name in cmdline ! input_dir = "testdata" ! output_dir = "ast" x = Path( "tata" ) --- 225,230 ---- # os.path.walk(sys.argv[1], lister, None) # dir name in cmdline ! input_dir = 'testdata' ! output_dir = 'ast' x = Path( "tata" ) *************** *** 84,85 **** --- 233,236 ---- os.path.walk( input_dir, listFilesIgnoreCVSDir, generator ) + + generator.generateIndexPage( 'index.html' ) \ No newline at end of file |