55from dm_job_utilities .dm_log import DmLog
66
77
8- def find_files (files_glob ):
9- files = glob .glob (files_glob )
8+ def find_files (input_file , dirs_glob ):
9+
10+ files = glob .glob (f"{ dirs_glob } /{ input_file } " )
1011 DmLog .emit_event ("Found {} files using {}" .format (len (files ), files_glob ))
1112 return files
1213
1314
14- def concat_binary (files_glob , output ):
15- files = find_files (files_glob )
15+ def concat_binary (input_file , dirs_glob , output ):
16+ files = find_files (input_file , dirs_glob )
1617 with (open (output , 'wb' ) as outfile ):
1718 file_count = 0
1819 for file in files :
@@ -23,8 +24,8 @@ def concat_binary(files_glob, output):
2324 DmLog .emit_event ("Wrote {} files" .format (file_count ))
2425
2526
26- def concat_text (files_glob , header , output ):
27- files = find_files (files_glob )
27+ def concat_text (input_file , dirs_glob , header , output ):
28+ files = find_files (input_file , dirs_glob )
2829 output_count = 0
2930 with (open (output , 'w' ) as outfile ):
3031 file_count = 0
@@ -48,18 +49,16 @@ def concat_text(files_glob, header, output):
4849def main ():
4950
5051 # Examples:
51- # python -m concatenator -f "*.sdf"
52- # python -m concatenator -f "abcd*/output.sdf"
53- # python -m concatenator -f "*.smi" --header ignore
54- # python -m concatenator -f "*.bin" --binary
52+ # python -m concatenator -f "output.sdf" -d "input-*"
5553 #
56- # NOTE: that if using globs for the files argument this must be escaped (e.g. abcd\*) or put in
54+ # NOTE: when using globs for the files argument this must be escaped (e.g. abcd\*) or put in
5755 # quotes (e.g. "abcd*") so that they are not expanded by the shell.
5856 # NOTE: when using the --binary argument the --header argument is ignored.
5957
6058 # command line args definitions #########################################
6159 parser = argparse .ArgumentParser (description = 'Concatenate files' )
62- parser .add_argument ('-f' , '--files' , required = True , help = "Name(s) of files to look for (glob allowed)" )
60+ parser .add_argument ('-f' , '--input-file' , required = True , help = "Name of the file to concatenate" )
61+ parser .add_argument ('-d' , '--dirs-glob' , required = True , help = "Glob of directories to search" )
6362 parser .add_argument ('-o' , '--output' , required = True , help = "Name(s) of output file" )
6463 parser .add_argument ('--header' , choices = ["ignore" , "retain" ],
6564 help = "Files have a header line, and what to do with it. If 'retain' the header of the first file is retained" )
@@ -69,9 +68,9 @@ def main():
6968 DmLog .emit_event ("Concatenate files: " , args )
7069
7170 if args .binary :
72- concat_binary (args .files , args .output )
71+ concat_binary (args .input_file , args . dirs_glob , args .output )
7372 else :
74- concat_text (args .files , args .header , args .output )
73+ concat_text (args .input_file , args . dirs_glob , args .header , args .output )
7574
7675
7776if __name__ == "__main__" :
0 commit comments