<s> import optparse <EOL> import ConfigParser <EOL> import os <EOL> import sys <EOL> import traceback <EOL> import csv <EOL> import sql2graph . export <EOL> from sql2graph . schema import Field , IntField , Relation , Reference , Column , Entity , Property <EOL> SCHEMA = ( <EOL> Entity ( '<STR_LIT>' , <EOL> fields = [ <EOL> IntField ( '<STR_LIT>' , Column ( '<STR_LIT:id>' ) , primary_key = True , index = '<STR_LIT>' ) , <EOL> Field ( '<STR_LIT:name>' , Column ( '<STR_LIT:name>' ) , index = '<STR_LIT>' ) , <EOL> Field ( '<STR_LIT>' , Column ( '<STR_LIT>' ) , index = '<STR_LIT>' ) , <EOL> Field ( '<STR_LIT:end>' , Column ( '<STR_LIT:end>' ) , index = '<STR_LIT>' ) , <EOL> ] , <EOL> relations = [ <EOL> Relation ( Reference ( '<STR_LIT>' , '<STR_LIT:id>' ) , <EOL> Reference ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> [ Property ( '<STR_LIT>' , '<STR_LIT>' ) ] ) <EOL> ] <EOL> ) , <EOL> Entity ( '<STR_LIT>' , <EOL> fields = [ <EOL> IntField ( '<STR_LIT>' , Column ( '<STR_LIT:id>' ) , primary_key = True , index = '<STR_LIT>' ) , <EOL> Field ( '<STR_LIT:name>' , Column ( '<STR_LIT:name>' ) , index = '<STR_LIT>' ) , <EOL> ] , <EOL> ) <EOL> ) <EOL> DEFAULT_NODES_FILE = '<STR_LIT>' <EOL> DEFAULT_RELATIONS_FILE = '<STR_LIT>' <EOL> def main ( ) : <EOL> option_parser = optparse . OptionParser ( ) <EOL> option_parser . add_option ( "<STR_LIT:-c>" , "<STR_LIT>" , dest = "<STR_LIT>" , help = "<STR_LIT>" , default = None ) <EOL> option_parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , action = "<STR_LIT:store_true>" , dest = "<STR_LIT>" , help = "<STR_LIT>" , default = False ) <EOL> option_parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , help = "<STR_LIT>" , default = None ) <EOL> option_parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , help = "<STR_LIT>" , default = None ) <EOL> ( options , args ) = option_parser . parse_args ( ) <EOL> config_parser = ConfigParser . RawConfigParser ( ) <EOL> if options . configfile : <EOL> config_parser . read ( options . configfile ) <EOL> else : <EOL> print "<STR_LIT>" <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> if config_parser . has_section ( '<STR_LIT>' ) : <EOL> dump_tables = dict ( ( <EOL> ( entity , dump_file ) <EOL> for entity , dump_file in config_parser . items ( '<STR_LIT>' ) <EOL> ) ) <EOL> else : <EOL> print "<STR_LIT>" <EOL> raise SystemExit <EOL> if config_parser . has_option ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> entity_order = [ entity . strip ( ) <EOL> for entity in config_parser . get ( '<STR_LIT>' , '<STR_LIT>' ) . split ( '<STR_LIT:U+002C>' ) ] <EOL> else : <EOL> print "<STR_LIT>" <EOL> raise SystemExit <EOL> if config_parser . has_section ( '<STR_LIT>' ) : <EOL> index_files = dict ( ( <EOL> ( index_name , index_file ) <EOL> for index_name , index_file in config_parser . items ( '<STR_LIT>' ) <EOL> ) ) <EOL> else : <EOL> print "<STR_LIT>" <EOL> index_files = None <EOL> for entity in entity_order : <EOL> if dump_tables . get ( entity ) : <EOL> if not os . path . isfile ( dump_tables . get ( entity ) ) : <EOL> print "<STR_LIT>" % dump_tables . get ( entity ) <EOL> raise RuntimeError <EOL> exporter = sql2graph . export . GraphExporter ( <EOL> schema = SCHEMA , format = '<STR_LIT>' , dialect = csv . excel ) <EOL> exporter . set_output_nodes_file ( <EOL> entity = sql2graph . export . MERGED , <EOL> filename = options . nodes_file or DEFAULT_NODES_FILE ) <EOL> exporter . set_output_relations_file ( <EOL> entity = sql2graph . export . MERGED , <EOL> filename = options . relations_file or DEFAULT_RELATIONS_FILE ) <EOL> for index_name , index_file in index_files . iteritems ( ) : <EOL> exporter . set_output_indexes_file ( entity = index_name , filename = index_file ) <EOL> for entity_name in entity_order : <EOL> if dump_tables . get ( entity ) : <EOL> exporter . feed_dumpfile ( entity = entity_name , filename = dump_tables . get ( entity_name ) ) <EOL> exporter . run ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
