@@ -132,19 +132,13 @@ def _add_credit_args(parser, use_gui=False):
132132
133133def _save_corrected (corrected , input_path , args ):
134134 outfile = args .output_directory / (input_path .stem + "_corrected.chi" )
135- if outfile .exists () and not args .force :
136- print (f"WARNING: { outfile } exists. Use --force to overwrite." )
137- return
138135 corrected .metadata = corrected .metadata or {}
139136 corrected .dump (str (outfile ), xtype = args .xtype )
140137 print (f"Saved corrected data to { outfile } " )
141138
142139
143140def _save_correction (correction , input_path , args ):
144141 corrfile = args .output_directory / (input_path .stem + "_cve.chi" )
145- if corrfile .exists () and not args .force :
146- print (f"WARNING: { corrfile } exists. Use --force to overwrite." )
147- return
148142 correction .metadata = correction .metadata or {}
149143 correction .dump (str (corrfile ), xtype = args .xtype )
150144 print (f"Saved correction data to { corrfile } " )
@@ -310,16 +304,45 @@ def get_args_gui():
310304 return parser .parse_args ()
311305
312306
307+ # def get_args_cli(override=None):
308+ # parser = create_parser(use_gui=False)
309+ # return parser.parse_args(override)
310+
311+
313312def get_args_cli (override = None ):
314313 parser = create_parser (use_gui = False )
315- return parser .parse_args (override )
314+ argv = override if override is not None else sys .argv [1 :]
315+ argv = [arg for arg in argv if arg != "--ignore-gooey" ]
316+ return parser .parse_args (argv )
317+
318+
319+ def _check_saved_file_exists (args ):
320+ """Check if the output files already exist based on the input paths
321+ and output directory."""
322+ existing_files = []
323+ for path in args .input_paths :
324+ outfile = args .output_directory / (path .stem + "_corrected.chi" )
325+ if outfile .exists () and not args .force :
326+ existing_files .append (outfile )
327+ if args .output_correction :
328+ corrfile = args .output_directory / (path .stem + "_cve.chi" )
329+ if corrfile .exists () and not args .force :
330+ existing_files .append (corrfile )
331+ if existing_files :
332+ existing_files_str = "\n " .join (str (f ) for f in existing_files )
333+ raise FileExistsError (
334+ "The following output files already exist:"
335+ f"\n { existing_files_str } \n "
336+ "Use --force to overwrite them."
337+ )
316338
317339
318340def main ():
319341 use_gui = len (sys .argv ) == 1 or "--gui" in sys .argv
320342 args = get_args_gui () if use_gui else get_args_cli ()
321343 args = _handle_old_api_conversion (args )
322344 args = preprocessing_args (args )
345+ _check_saved_file_exists (args )
323346 apply_absorption_correction (args )
324347
325348
0 commit comments