From: changeling Date: Wed, 27 Mar 2019 00:05:56 +0000 (-0500) Subject: Update .settings file handling and defaults. X-Git-Url: https://git.nutra.tk/v2?a=commitdiff_plain;h=1662af2e4a0ae20797ce6cd3c728d0a70a87f5b0;p=gamesguru%2Fgetmyancestors.git Update .settings file handling and defaults. Handle non-argparse `username` and `password`. Removed printing of settings to stdout. Remove `redact_password = True` line. Add `--redact-password` argument, defaulting to `False`. Removed `.settings` file creation when output is directed to stdout. --- diff --git a/getmyancestors.py b/getmyancestors.py index 654e2ba..1ec8c0b 100755 --- a/getmyancestors.py +++ b/getmyancestors.py @@ -913,6 +913,7 @@ if __name__ == '__main__': parser.add_argument('-c', action="store_true", default=False, help='Add LDS ordinances (need LDS account) [False]') parser.add_argument("-v", action="store_true", default=False, help="Increase output verbosity [False]") parser.add_argument('-t', metavar='', type=int, default=60, help='Timeout in seconds [60]') + parser.add_argument('--redact-password', action="store_true", default=False, help="Redact password from .settings file [False]") try: parser.add_argument('-o', metavar='', type=argparse.FileType('w', encoding='UTF-8'), default=sys.stdout, help='output GEDCOM file [stdout]') parser.add_argument('-l', metavar='', type=argparse.FileType('w', encoding='UTF-8'), default=sys.stderr, help='output log file [stderr]') @@ -940,25 +941,34 @@ if __name__ == '__main__': time_count = time.time() # Report settings used when getmyancestors.py is executed. - redact_password = True - setting_list = [string for setting in [[ - str('-' + action.dest + ' ' + action.help), - '******' if action.dest == 'p' and redact_password - else str(vars(args)[action.dest].name) if hasattr(vars(args)[action.dest], 'name') + + setting_list = [ + string for setting in [ + [ + str('-' + action.dest + ' ' + action.help), + username + if action.dest is 'u' + else '******' + if action.dest is 'p' and args.redact_password + else password + if action.dest is 'p' + else str(vars(args)[action.dest].name) + if hasattr(vars(args)[action.dest], 'name') else str(vars(args)[action.dest])] for action in vars(parser)['_actions']] for string in setting] - setting_list.insert(0,time.strftime('%X %x %Z')) - setting_list.insert(0,'time stamp: ') + setting_list.insert(0, time.strftime('%X %x %Z')) + setting_list.insert(0, 'time stamp: ') formatting = '{:74}{:\t>1}\n' * int(len(setting_list) / 2) settings_output = (( formatting ).format( *setting_list)) - print(settings_output) - with open(args.o.name.split('.')[0] + '.settings', 'w') as settings_record: - settings_record.write(settings_output) + if not (args.o.name == ''): + with open( + args.o.name.split('.')[0] + '.settings', 'w') as settings_record: + settings_record.write(settings_output) # initialize a FamilySearch session and a family tree object print('Login to FamilySearch...')