Skip to content

Commit 89ee22c

Browse files
authored
Merge pull request #103 from whwright/98-better-logging
Fix accidental system exit with better logging strategy
2 parents f8be345 + 9e472b7 commit 89ee22c

1 file changed

Lines changed: 19 additions & 8 deletions

File tree

‎bin/github-backup‎

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,33 @@ FNULL = open(os.devnull, 'w')
4040

4141

4242
def log_error(message):
43+
"""
44+
Log message (str) or messages (List[str]) to stderr and exit with status 1
45+
"""
46+
log_warning(message)
47+
sys.exit(1)
48+
49+
50+
def log_info(message):
51+
"""
52+
Log message (str) or messages (List[str]) to stdout
53+
"""
4354
if type(message) == str:
4455
message = [message]
4556

4657
for msg in message:
47-
sys.stderr.write("{0}\n".format(msg))
48-
49-
sys.exit(1)
58+
sys.stdout.write("{0}\n".format(msg))
5059

5160

52-
def log_info(message):
61+
def log_warning(message):
62+
"""
63+
Log message (str) or messages (List[str]) to stderr
64+
"""
5365
if type(message) == str:
5466
message = [message]
5567

5668
for msg in message:
57-
sys.stdout.write("{0}\n".format(msg))
69+
sys.stderr.write("{0}\n".format(msg))
5870

5971

6072
def logging_subprocess(popenargs,
@@ -513,7 +525,6 @@ def check_git_lfs_install():
513525
exit_code = subprocess.call(['git', 'lfs', 'version'])
514526
if exit_code != 0:
515527
log_error('The argument --lfs requires you to have Git LFS installed.\nYou can get it from https://git-lfs.github.com.')
516-
sys.exit(1)
517528

518529

519530
def retrieve_repositories(args, authenticated_user):
@@ -524,8 +535,8 @@ def retrieve_repositories(args, authenticated_user):
524535
template = 'https://{0}/user/repos'.format(
525536
get_github_api_host(args))
526537
else:
527-
if args.private:
528-
log_error('Authenticated user is different from user being backed up, thus private repositories cannot be accessed')
538+
if args.private and not args.organization:
539+
log_warning('Authenticated user is different from user being backed up, thus private repositories cannot be accessed')
529540
template = 'https://{0}/users/{1}/repos'.format(
530541
get_github_api_host(args),
531542
args.user)

0 commit comments

Comments
 (0)