#NEWLINE# def main( ) : #NEWLINE# #INDENT# parser = argparse . ArgumentParser ( usage = USAGE , description = DESCRIPTION , epilog = EPILOG , formatter_class = argparse . RawDescriptionHelpFormatter ) #NEWLINE# for param in COMMAND_LINE_PARAMETERS : #NEWLINE# #INDENT# if ( param [ 'short' ] is None ) : #NEWLINE# #INDENT# parser . add_argument ( param [ 'long' ] , help = param [ 'help' ] , action = param [ 'action' ] , default = argparse . SUPPRESS ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# parser . add_argument ( param [ 'short' ] , param [ 'long' ] , help = param [ 'help' ] , action = param [ 'action' ] , default = argparse . SUPPRESS ) #NEWLINE# #UNINDENT# #UNINDENT# arguments = parser . parse_args ( ) #NEWLINE# if ( len ( sys . argv ) < 2 ) : #NEWLINE# #INDENT# parser . print_help ( ) #NEWLINE# sys . exit ( 0 ) #NEWLINE# #UNINDENT# if ( 'version' in arguments ) : #NEWLINE# #INDENT# print_info ( ( 'Penelope v%s' % __version__ ) ) #NEWLINE# sys . exit ( 0 ) #NEWLINE# #UNINDENT# check_arguments ( arguments ) #NEWLINE# set_default_values ( arguments ) #NEWLINE# print_debug ( ( 'Running with the command line arguments:\n%s' % str ( arguments ) ) , arguments . debug ) #NEWLINE# print_info ( 'Reading input file(s)...' ) #NEWLINE# dictionary = read_dictionary ( arguments ) #NEWLINE# if ( dictionary is None ) : #NEWLINE# #INDENT# print_error ( 'Unable to read the input file(s)' ) #NEWLINE# sys . exit ( 8 ) #NEWLINE# #UNINDENT# print_info ( 'Reading input file(s)... done' ) #NEWLINE# if ( arguments . input_parser is not None ) : #NEWLINE# #INDENT# input_parser = load_input_parser ( arguments . input_parser ) #NEWLINE# if ( input_parser is not None ) : #NEWLINE# #INDENT# print_info ( 'Applying the specified input parser...' ) #NEWLINE# dictionary = input_parser . parse ( dictionary , arguments ) #NEWLINE# print_info ( 'Applying the specified input parser... done' ) #NEWLINE# #UNINDENT# #UNINDENT# if arguments . sort_before : #NEWLINE# #INDENT# print_info ( 'Sorting before...' ) #NEWLINE# dictionary . sort ( arguments . sort_by_headword , arguments . sort_by_definition , arguments . sort_reverse , arguments . sort_ignore_case ) #NEWLINE# print_info ( 'Sorting before... done' ) #NEWLINE# #UNINDENT# if arguments . merge_definitions : #NEWLINE# #INDENT# print_info ( 'Merging...' ) #NEWLINE# dictionary . merge_definitions ( merge_separator = arguments . merge_separator ) #NEWLINE# print_info ( 'Merging... done' ) #NEWLINE# #UNINDENT# if arguments . flatten_synonyms : #NEWLINE# #INDENT# print_info ( 'Flattening synonyms...' ) #NEWLINE# dictionary . flatten_synonyms ( ) #NEWLINE# print_info ( 'Flattening synonyms... done' ) #NEWLINE# #UNINDENT# if arguments . sort_after : #NEWLINE# #INDENT# print_info ( 'Sorting after...' ) #NEWLINE# dictionary . sort ( arguments . sort_by_headword , arguments . sort_by_definition , arguments . sort_reverse , arguments . sort_ignore_case ) #NEWLINE# print_info ( 'Sorting after... done' ) #NEWLINE# #UNINDENT# print_info ( 'Writing output file(s)...' ) #NEWLINE# output_paths = write_dictionary ( dictionary , arguments ) #NEWLINE# if ( output_paths is None ) : #NEWLINE# #INDENT# print_error ( 'Unable to write the output file(s)' ) #NEWLINE# sys . exit ( 16 ) #NEWLINE# #UNINDENT# print_info ( 'Writing output file(s)... done' ) #NEWLINE# print_info ( 'The following file(s) have been created:' ) #NEWLINE# for op in output_paths : #NEWLINE# #INDENT# print_info ( ( '  %s' % op ) ) #NEWLINE# #UNINDENT# sys . exit ( 0 )