Commit 1c6a9828 authored by Nicolas Wavrant's avatar Nicolas Wavrant

repozo: simplify the handling of Errors in the main function

parent b94910cb
...@@ -108,16 +108,22 @@ READCHUNK = 16 * 1024 ...@@ -108,16 +108,22 @@ READCHUNK = 16 * 1024
VERBOSE = False VERBOSE = False
class WouldOverwriteFiles(Exception): class RepozoError(Exception):
pass pass
class NoFiles(Exception): class WouldOverwriteFiles(RepozoError):
pass pass
class VerificationFail(Exception):
class NoFiles(RepozoError):
pass
class VerificationFail(RepozoError):
pass pass
class _GzipCloser(object): class _GzipCloser(object):
def __init__(self, fqn, mode): def __init__(self, fqn, mode):
...@@ -785,23 +791,15 @@ def main(argv=None): ...@@ -785,23 +791,15 @@ def main(argv=None):
if argv is None: if argv is None:
argv = sys.argv[1:] argv = sys.argv[1:]
options = parseargs(argv) options = parseargs(argv)
if options.mode == BACKUP:
try: try:
if options.mode == BACKUP:
do_backup(options) do_backup(options)
except WouldOverwriteFiles as e:
sys.exit(str(e))
except VerificationFail as e:
sys.exit(str(e))
elif options.mode == RECOVER: elif options.mode == RECOVER:
try:
do_recover(options) do_recover(options)
except NoFiles as e:
sys.exit(str(e))
else: else:
assert options.mode == VERIFY assert options.mode == VERIFY
try:
do_verify(options) do_verify(options)
except NoFiles as e: except (RepozoError, OSError) as e:
sys.exit(str(e)) sys.exit(str(e))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment