@@ -46,26 +46,38 @@ def main():
4646 print (f"Usage: { sys .argv [0 ]} <original> <renamed> [files...]" )
4747 sys .exit (1 )
4848
49- original = sys .argv [1 ]
50- renamed = sys .argv [2 ]
49+ original = sys .argv [1 ]. split ( " " )
50+ renamed = sys .argv [2 ]. split ( " " )
5151 files = sys .argv [3 :]
5252
53- print ( f"Copying { original } to { renamed } " )
54-
55- original_re , renamed_re = _glob_to_regex ( original , renamed )
53+ if len ( original ) != len ( renamed ):
54+ print ( f"Error: { len ( original ) } original and { len ( renamed ) } renamed" )
55+ sys . exit ( 1 )
5656
57- print (f"Copying { original_re } to { renamed_re } " )
5857 print (f"Found { len (files )} files: { files } " )
58+
5959 outputs : list [str ] = []
60- for f in files :
61- new_name = re .sub (original_re , renamed_re , f )
62- print (f"Copying { f } to { new_name } " )
63- try :
64- with open (f , "rb" ) as src , open (new_name , "wb" ) as dst :
65- dst .write (src .read ())
66- outputs .append (new_name )
67- except Exception as e :
68- print (f"Error Copying { f } to { new_name } : { e } " )
60+ for o , r in zip (original , renamed ):
61+ print (f"Copying glob { o } to { r } " )
62+
63+ o_re , r_re = _glob_to_regex (o , r )
64+
65+ print (f"Copying regex { o_re } to { r_re } " )
66+ o_files = [f for f in files if re .match (o_re , f )]
67+ if not o_files :
68+ print (f"Error: no files match { o_re } " )
69+ sys .exit (1 )
70+ for f in o_files :
71+ if not re .match (o_re , f ):
72+ continue
73+ new_name = re .sub (o_re , r_re , f )
74+ print (f"Copying file { f } to { new_name } " )
75+ try :
76+ with open (f , "rb" ) as src , open (new_name , "wb" ) as dst :
77+ dst .write (src .read ())
78+ outputs .append (new_name )
79+ except Exception as e :
80+ print (f"Error Copying { f } to { new_name } : { e } " )
6981
7082 print (f"Renamed { len (outputs )} files: { outputs } " )
7183 _write_github_outputs (outputs )
0 commit comments