From 94553812cc9c94f3f368194a661108f1b295ba13 Mon Sep 17 00:00:00 2001 From: Fred Wright Date: Sun, 5 Jan 2020 15:25:23 -0800 Subject: [PATCH] Tolerate inability to write settings file. It's questionable that the unsolicited write of the settings is reasonable at all, but at the very least it shouldn't crash if it can't, e.g., when outputting to /dev/null for testing. TESTED: Now prints message and continues on failed attempt to write /dev/null.settings. Writes settings successfully with real output file specified. --- getmyancestors.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/getmyancestors.py b/getmyancestors.py index 28f84e6..f0a57a1 100755 --- a/getmyancestors.py +++ b/getmyancestors.py @@ -1189,12 +1189,17 @@ def main(): return str(getattr(value, "name", value)) formatting = "{:74}{:\t>1}\n" - with open(args.outfile.name.split(".")[0] + ".settings", "w") as settings_file: - settings_file.write(formatting.format("time stamp: ", time.strftime("%X %x %Z"))) - for action in parser._actions: - settings_file.write( - formatting.format(action.option_strings[-1], parse_action(action)) - ) + settings_name = args.outfile.name.split(".")[0] + ".settings" + try: + with open(settings_name, "w") as settings_file: + settings_file.write(formatting.format("time stamp: ", time.strftime("%X %x %Z"))) + for action in parser._actions: + settings_file.write( + formatting.format(action.option_strings[-1], parse_action(action)) + ) + except OSError as exc: + print("Unable to write %s: %s" % (settings_name, repr(exc)), + file=sys.stderr) # initialize a FamilySearch session and a family tree object print("Login to FamilySearch...") -- 2.52.0