#NEWLINE# def main( ) : #NEWLINE# #INDENT# if ( len ( sys . argv ) < 2 ) : #NEWLINE# #INDENT# print ( 'usage: python prepgml4ogr.py file [[prep_module.]prep_class]' ) #NEWLINE# sys . exit ( 1 ) #NEWLINE# #UNINDENT# inputfile = sys . argv [ 1 ] #NEWLINE# if os . path . exists ( inputfile ) : #NEWLINE# #INDENT# prep_class = 'prep_gml' #NEWLINE# try : #NEWLINE# #INDENT# prep_class = sys . argv [ 2 ] #NEWLINE# #UNINDENT# except IndexError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# prep_class = get_preparer ( prep_class ) #NEWLINE# preparer = prep_class ( inputfile ) #NEWLINE# parser = make_parser ( ) #NEWLINE# parser . setContentHandler ( gmlhandler ( preparer ) ) #NEWLINE# if ( os . path . splitext ( inputfile ) [ 1 ] . lower ( ) == '.zip' ) : #NEWLINE# #INDENT# archive = zipfile . ZipFile ( inputfile , 'r' ) #NEWLINE# for filename in archive . namelist ( ) : #NEWLINE# #INDENT# file = archive . open ( filename ) #NEWLINE# try : #NEWLINE# #INDENT# parser . parse ( file ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( os . path . splitext ( inputfile ) [ 1 ] . lower ( ) == '.gz' ) : #NEWLINE# #INDENT# file = gzip . open ( inputfile , 'r' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# file = open ( inputfile , 'r' ) #NEWLINE# #UNINDENT# parser . parse ( file ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# print ( ( 'Could not find input file: ' + inputfile ) )