Skip to content

Commit

Permalink
make sure the args log file is not overwritten
Browse files Browse the repository at this point in the history
  • Loading branch information
javierggt committed Feb 23, 2024
1 parent aee7a57 commit 7920122
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion agasc/scripts/update_mag_supplement.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def get_args():
report_date += ((7 - report_date.datetime.weekday()) % 7) * u.day
report_date = CxoTime(report_date.date[:8])

args_log_file = args.output_dir / "call_args.yml"
args_log_file = get_next_file_name(args.output_dir / "call_args.yml")
if not args.output_dir.exists():
args.output_dir.mkdir(parents=True)

Expand All @@ -209,6 +209,7 @@ def get_args():
}
yaml_args["report_date"] = report_date.date
yaml_args["agasc_ids"] = agasc_ids
logger.info(f"Writing input arguments to {args_log_file}")
with open(args_log_file, "w") as fh:
yaml.dump(yaml_args, fh)

Expand All @@ -232,6 +233,16 @@ def get_args():
}


def get_next_file_name(file_name):
if not file_name.exists():
return file_name
i = 1
while True:
new_file_name = file_name.with_suffix(f".{i}{file_name.suffix}")
if not new_file_name.exists():
return new_file_name
i += 1

def main():
import kadi.commands

Expand Down

0 comments on commit 7920122

Please sign in to comment.