<s> import os <EOL> import sys <EOL> def convert ( ifilename , ofilename ) : <EOL> ifile = open ( ifilename , '<STR_LIT:r>' ) <EOL> ofile = open ( ofilename , '<STR_LIT:w>' ) <EOL> for line in iter ( ifile . readline , "<STR_LIT>" ) : <EOL> sline = line . split ( ) <EOL> if sline [ <NUM_LIT:0> ] == '<STR_LIT:c>' : <EOL> continue <EOL> if sline [ <NUM_LIT:0> ] == '<STR_LIT:p>' : <EOL> num_nodes = sline [ <NUM_LIT:2> ] <EOL> num_edges = sline [ <NUM_LIT:3> ] <EOL> ofile . write ( "<STR_LIT>" % ( num_nodes , num_edges ) ) <EOL> continue <EOL> from_node = sline [ <NUM_LIT:1> ] <EOL> to_node = sline [ <NUM_LIT:2> ] <EOL> cost = sline [ <NUM_LIT:3> ] <EOL> ofile . write ( "<STR_LIT>" % ( from_node , to_node , cost ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> from optparse import OptionParser <EOL> INFO = "<STR_LIT>" <EOL> VERSION = "<STR_LIT>" <EOL> USAGE = "<STR_LIT>" <EOL> def showVersion ( ) : <EOL> print ( INFO ) <EOL> print ( VERSION ) <EOL> print ( USAGE ) <EOL> sys . exit ( ) <EOL> optparser = OptionParser ( ) <EOL> optparser . add_option ( "<STR_LIT>" , "<STR_LIT>" , action = "<STR_LIT:store_true>" , dest = "<STR_LIT>" , <EOL> default = False , help = "<STR_LIT>" ) <EOL> optparser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> default = "<STR_LIT>" , help = "<STR_LIT>" ) <EOL> ( options , args ) = optparser . parse_args ( ) <EOL> filelist = args <EOL> if options . showversion : <EOL> showVersion ( ) <EOL> for f in filelist : <EOL> if not os . path . exists ( f ) : raise IOError ( "<STR_LIT>" % f ) <EOL> if len ( filelist ) == <NUM_LIT:0> : <EOL> showVersion ( ) <EOL> convert ( filelist [ <NUM_LIT:0> ] , options . outputfile ) </s>
