mirror of
https://github.com/josegonzalez/python-github-backup.git
synced 2025-12-05 16:18:02 +01:00
Fix accidental system exit with better logging strategy
This commit is contained in:
@@ -40,16 +40,17 @@ FNULL = open(os.devnull, 'w')
|
|||||||
|
|
||||||
|
|
||||||
def log_error(message):
|
def log_error(message):
|
||||||
if type(message) == str:
|
"""
|
||||||
message = [message]
|
Log message (str) or messages (List[str]) to stderr and exit with status 1
|
||||||
|
"""
|
||||||
for msg in message:
|
log_warning(message)
|
||||||
sys.stderr.write("{0}\n".format(msg))
|
|
||||||
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
def log_info(message):
|
def log_info(message):
|
||||||
|
"""
|
||||||
|
Log message (str) or messages (List[str]) to stdout
|
||||||
|
"""
|
||||||
if type(message) == str:
|
if type(message) == str:
|
||||||
message = [message]
|
message = [message]
|
||||||
|
|
||||||
@@ -57,6 +58,17 @@ def log_info(message):
|
|||||||
sys.stdout.write("{0}\n".format(msg))
|
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,
|
def logging_subprocess(popenargs,
|
||||||
logger,
|
logger,
|
||||||
stdout_log_level=logging.DEBUG,
|
stdout_log_level=logging.DEBUG,
|
||||||
@@ -525,7 +537,7 @@ def retrieve_repositories(args, authenticated_user):
|
|||||||
get_github_api_host(args))
|
get_github_api_host(args))
|
||||||
else:
|
else:
|
||||||
if args.private:
|
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(
|
template = 'https://{0}/users/{1}/repos'.format(
|
||||||
get_github_api_host(args),
|
get_github_api_host(args),
|
||||||
args.user)
|
args.user)
|
||||||
|
|||||||
Reference in New Issue
Block a user