<s> """<STR_LIT>""" <EOL> import argparse <EOL> import importlib <EOL> import os <EOL> import sys <EOL> import h5py <EOL> import fuel <EOL> from fuel import converters <EOL> from fuel . converters . base import MissingInputFiles <EOL> from fuel . datasets import H5PYDataset <EOL> class CheckDirectoryAction ( argparse . Action ) : <EOL> def __call__ ( self , parser , namespace , values , option_string = None ) : <EOL> if os . path . isdir ( values ) : <EOL> setattr ( namespace , self . dest , values ) <EOL> else : <EOL> raise ValueError ( '<STR_LIT>' . format ( values ) ) <EOL> def main ( args = None ) : <EOL> """<STR_LIT>""" <EOL> built_in_datasets = dict ( converters . all_converters ) <EOL> if fuel . config . extra_converters : <EOL> for name in fuel . config . extra_converters : <EOL> extra_datasets = dict ( <EOL> importlib . import_module ( name ) . all_converters ) <EOL> if any ( key in built_in_datasets for key in extra_datasets . keys ( ) ) : <EOL> raise ValueError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> built_in_datasets . update ( extra_datasets ) <EOL> parser = argparse . ArgumentParser ( <EOL> description = '<STR_LIT>' ) <EOL> subparsers = parser . add_subparsers ( ) <EOL> parent_parser = argparse . ArgumentParser ( add_help = False ) <EOL> parent_parser . add_argument ( <EOL> "<STR_LIT>" , "<STR_LIT>" , help = "<STR_LIT>" , <EOL> type = str , default = os . getcwd ( ) ) <EOL> convert_functions = { } <EOL> for name , fill_subparser in built_in_datasets . items ( ) : <EOL> subparser = subparsers . add_parser ( <EOL> name , parents = [ parent_parser ] , <EOL> help = '<STR_LIT>' . format ( name ) ) <EOL> subparser . add_argument ( <EOL> "<STR_LIT>" , "<STR_LIT>" , help = "<STR_LIT>" , <EOL> type = str , default = os . getcwd ( ) , action = CheckDirectoryAction ) <EOL> subparser . add_argument ( <EOL> "<STR_LIT>" , "<STR_LIT>" , help = "<STR_LIT>" , <EOL> type = str , default = None ) <EOL> subparser . set_defaults ( which_ = name ) <EOL> convert_functions [ name ] = fill_subparser ( subparser ) <EOL> args = parser . parse_args ( args ) <EOL> args_dict = vars ( args ) <EOL> if args_dict [ '<STR_LIT>' ] is not None and os . path . splitext ( args_dict [ '<STR_LIT>' ] ) [ <NUM_LIT:1> ] not in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> args_dict [ '<STR_LIT>' ] += '<STR_LIT>' <EOL> if args_dict [ '<STR_LIT>' ] is None : <EOL> args_dict . pop ( '<STR_LIT>' ) <EOL> convert_function = convert_functions [ args_dict . pop ( '<STR_LIT>' ) ] <EOL> try : <EOL> output_paths = convert_function ( ** args_dict ) <EOL> except MissingInputFiles as e : <EOL> intro = "<STR_LIT>" <EOL> message = "<STR_LIT:\n>" . join ( [ intro ] + [ "<STR_LIT>" + f for f in e . filenames ] ) <EOL> message += "<STR_LIT>" <EOL> parser . error ( message ) <EOL> for output_path in output_paths : <EOL> h5file = h5py . File ( output_path , '<STR_LIT:a>' ) <EOL> interface_version = H5PYDataset . interface_version . encode ( '<STR_LIT:utf-8>' ) <EOL> h5file . attrs [ '<STR_LIT>' ] = interface_version <EOL> fuel_convert_version = converters . __version__ . encode ( '<STR_LIT:utf-8>' ) <EOL> h5file . attrs [ '<STR_LIT>' ] = fuel_convert_version <EOL> command = [ os . path . basename ( sys . argv [ <NUM_LIT:0> ] ) ] + sys . argv [ <NUM_LIT:1> : ] <EOL> h5file . attrs [ '<STR_LIT>' ] = ( <EOL> '<STR_LIT:U+0020>' . join ( command ) . encode ( '<STR_LIT:utf-8>' ) ) <EOL> h5file . flush ( ) <EOL> h5file . close ( ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( ) </s>
