mirror of https://github.com/borgbackup/borg.git
commit
37a02a89ab
|
@ -571,6 +571,8 @@ Type "Yes I am sure" if you understand this and want to continue.\n""")
|
||||||
common_parser = argparse.ArgumentParser(add_help=False, prog=prog)
|
common_parser = argparse.ArgumentParser(add_help=False, prog=prog)
|
||||||
common_parser.add_argument('-v', '--verbose', dest='verbose', action='store_true', default=False,
|
common_parser.add_argument('-v', '--verbose', dest='verbose', action='store_true', default=False,
|
||||||
help='verbose output')
|
help='verbose output')
|
||||||
|
common_parser.add_argument('--show-rc', dest='show_rc', action='store_true', default=False,
|
||||||
|
help='show/log the return code (rc)')
|
||||||
common_parser.add_argument('--no-files-cache', dest='cache_files', action='store_false',
|
common_parser.add_argument('--no-files-cache', dest='cache_files', action='store_false',
|
||||||
help='do not load/update the file metadata cache used to detect unchanged files')
|
help='do not load/update the file metadata cache used to detect unchanged files')
|
||||||
common_parser.add_argument('--umask', dest='umask', type=lambda s: int(s, 8), default=RemoteRepository.umask, metavar='M',
|
common_parser.add_argument('--umask', dest='umask', type=lambda s: int(s, 8), default=RemoteRepository.umask, metavar='M',
|
||||||
|
@ -985,7 +987,21 @@ Type "Yes I am sure" if you understand this and want to continue.\n""")
|
||||||
help='additional help on TOPIC')
|
help='additional help on TOPIC')
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def run(self, args=None):
|
def parse_args(self, args=None):
|
||||||
|
# We can't use argparse for "serve" since we don't want it to show up in "Available commands"
|
||||||
|
if args:
|
||||||
|
args = self.preprocess_args(args)
|
||||||
|
parser = self.build_parser(args)
|
||||||
|
args = parser.parse_args(args or ['-h'])
|
||||||
|
update_excludes(args)
|
||||||
|
return args
|
||||||
|
|
||||||
|
def run(self, args):
|
||||||
|
os.umask(args.umask) # early, before opening files
|
||||||
|
self.verbose = args.verbose
|
||||||
|
RemoteRepository.remote_path = args.remote_path
|
||||||
|
RemoteRepository.umask = args.umask
|
||||||
|
setup_logging()
|
||||||
check_extension_modules()
|
check_extension_modules()
|
||||||
keys_dir = get_keys_dir()
|
keys_dir = get_keys_dir()
|
||||||
if not os.path.exists(keys_dir):
|
if not os.path.exists(keys_dir):
|
||||||
|
@ -1002,19 +1018,6 @@ Type "Yes I am sure" if you understand this and want to continue.\n""")
|
||||||
# For information about cache directory tags, see:
|
# For information about cache directory tags, see:
|
||||||
# http://www.brynosaurus.com/cachedir/
|
# http://www.brynosaurus.com/cachedir/
|
||||||
""").lstrip())
|
""").lstrip())
|
||||||
|
|
||||||
# We can't use argparse for "serve" since we don't want it to show up in "Available commands"
|
|
||||||
if args:
|
|
||||||
args = self.preprocess_args(args)
|
|
||||||
parser = self.build_parser(args)
|
|
||||||
|
|
||||||
args = parser.parse_args(args or ['-h'])
|
|
||||||
self.verbose = args.verbose
|
|
||||||
setup_logging()
|
|
||||||
os.umask(args.umask)
|
|
||||||
RemoteRepository.remote_path = args.remote_path
|
|
||||||
RemoteRepository.umask = args.umask
|
|
||||||
update_excludes(args)
|
|
||||||
if is_slow_msgpack():
|
if is_slow_msgpack():
|
||||||
logger.warning("Using a pure-python msgpack! This will result in lower performance.")
|
logger.warning("Using a pure-python msgpack! This will result in lower performance.")
|
||||||
return args.func(args)
|
return args.func(args)
|
||||||
|
@ -1060,9 +1063,10 @@ def main(): # pragma: no cover
|
||||||
sys.stderr = io.TextIOWrapper(sys.stderr.buffer, sys.stderr.encoding, 'replace', line_buffering=True)
|
sys.stderr = io.TextIOWrapper(sys.stderr.buffer, sys.stderr.encoding, 'replace', line_buffering=True)
|
||||||
setup_signal_handlers()
|
setup_signal_handlers()
|
||||||
archiver = Archiver()
|
archiver = Archiver()
|
||||||
|
msg = None
|
||||||
|
args = archiver.parse_args(sys.argv[1:])
|
||||||
try:
|
try:
|
||||||
msg = None
|
exit_code = archiver.run(args)
|
||||||
exit_code = archiver.run(sys.argv[1:])
|
|
||||||
except Error as e:
|
except Error as e:
|
||||||
msg = e.get_message()
|
msg = e.get_message()
|
||||||
if e.traceback:
|
if e.traceback:
|
||||||
|
@ -1079,16 +1083,17 @@ def main(): # pragma: no cover
|
||||||
exit_code = EXIT_ERROR
|
exit_code = EXIT_ERROR
|
||||||
if msg:
|
if msg:
|
||||||
logger.error(msg)
|
logger.error(msg)
|
||||||
exit_msg = 'terminating with %s status, rc %d'
|
if args.show_rc:
|
||||||
if exit_code == EXIT_SUCCESS:
|
exit_msg = 'terminating with %s status, rc %d'
|
||||||
logger.info(exit_msg % ('success', exit_code))
|
if exit_code == EXIT_SUCCESS:
|
||||||
elif exit_code == EXIT_WARNING:
|
logger.info(exit_msg % ('success', exit_code))
|
||||||
logger.warning(exit_msg % ('warning', exit_code))
|
elif exit_code == EXIT_WARNING:
|
||||||
elif exit_code == EXIT_ERROR:
|
logger.warning(exit_msg % ('warning', exit_code))
|
||||||
logger.error(exit_msg % ('error', exit_code))
|
elif exit_code == EXIT_ERROR:
|
||||||
else:
|
logger.error(exit_msg % ('error', exit_code))
|
||||||
# if you see 666 in output, it usually means exit_code was None
|
else:
|
||||||
logger.error(exit_msg % ('abnormal', exit_code or 666))
|
# if you see 666 in output, it usually means exit_code was None
|
||||||
|
logger.error(exit_msg % ('abnormal', exit_code or 666))
|
||||||
sys.exit(exit_code)
|
sys.exit(exit_code)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -93,7 +93,8 @@ def exec_cmd(*args, archiver=None, fork=False, exe=None, **kw):
|
||||||
sys.stdout = sys.stderr = output = StringIO()
|
sys.stdout = sys.stderr = output = StringIO()
|
||||||
if archiver is None:
|
if archiver is None:
|
||||||
archiver = Archiver()
|
archiver = Archiver()
|
||||||
ret = archiver.run(list(args))
|
args = archiver.parse_args(list(args))
|
||||||
|
ret = archiver.run(args)
|
||||||
return ret, output.getvalue()
|
return ret, output.getvalue()
|
||||||
finally:
|
finally:
|
||||||
sys.stdin, sys.stdout, sys.stderr = stdin, stdout, stderr
|
sys.stdin, sys.stdout, sys.stderr = stdin, stdout, stderr
|
||||||
|
|
Loading…
Reference in New Issue