From b70ea87db7a1e823e261a1d57c30ae42143f0457 Mon Sep 17 00:00:00 2001 From: "W. Harrison Wright" Date: Thu, 27 Dec 2018 12:53:21 -0600 Subject: [PATCH 1/3] Fix accidental system exit with better logging strategy --- bin/github-backup | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/bin/github-backup b/bin/github-backup index 0996092..097ba1c 100755 --- a/bin/github-backup +++ b/bin/github-backup @@ -40,16 +40,17 @@ FNULL = open(os.devnull, 'w') def log_error(message): - if type(message) == str: - message = [message] - - for msg in message: - sys.stderr.write("{0}\n".format(msg)) - + """ + Log message (str) or messages (List[str]) to stderr and exit with status 1 + """ + log_warning(message) sys.exit(1) def log_info(message): + """ + Log message (str) or messages (List[str]) to stdout + """ if type(message) == str: message = [message] @@ -57,6 +58,17 @@ def log_info(message): sys.stdout.write("{0}\n".format(msg)) +def log_warning(message): + """ + Log message (str) or messages (List[str]) to stderr + """ + if type(message) == str: + message = [message] + + for msg in message: + sys.stderr.write("{0}\n".format(msg)) + + def logging_subprocess(popenargs, logger, stdout_log_level=logging.DEBUG, @@ -525,7 +537,7 @@ def retrieve_repositories(args, authenticated_user): get_github_api_host(args)) else: if args.private: - log_error('Authenticated user is different from user being backed up, thus private repositories cannot be accessed') + log_warning('Authenticated user is different from user being backed up, thus private repositories cannot be accessed') template = 'https://{0}/users/{1}/repos'.format( get_github_api_host(args), args.user) From 4b459f9af80909fbefcc34b33f6bc63c41a780c4 Mon Sep 17 00:00:00 2001 From: "W. Harrison Wright" Date: Thu, 27 Dec 2018 12:58:57 -0600 Subject: [PATCH 2/3] Add org check to avoid incorrect log output --- bin/github-backup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/github-backup b/bin/github-backup index 097ba1c..55b77ae 100755 --- a/bin/github-backup +++ b/bin/github-backup @@ -536,7 +536,7 @@ def retrieve_repositories(args, authenticated_user): template = 'https://{0}/user/repos'.format( get_github_api_host(args)) else: - if args.private: + if args.private and not args.organization: log_warning('Authenticated user is different from user being backed up, thus private repositories cannot be accessed') template = 'https://{0}/users/{1}/repos'.format( get_github_api_host(args), From 9e472b74e6e8f551d98dc43fb693334153240195 Mon Sep 17 00:00:00 2001 From: "W. Harrison Wright" Date: Thu, 27 Dec 2018 13:07:13 -0600 Subject: [PATCH 3/3] Remove unnecessary sys.exit call --- bin/github-backup | 1 - 1 file changed, 1 deletion(-) diff --git a/bin/github-backup b/bin/github-backup index 55b77ae..0245ba1 100755 --- a/bin/github-backup +++ b/bin/github-backup @@ -525,7 +525,6 @@ def check_git_lfs_install(): exit_code = subprocess.call(['git', 'lfs', 'version']) if exit_code != 0: log_error('The argument --lfs requires you to have Git LFS installed.\nYou can get it from https://git-lfs.github.com.') - sys.exit(1) def retrieve_repositories(args, authenticated_user):