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,24 +791,16 @@ def main(argv=None): ...@@ -785,24 +791,16 @@ 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: elif options.mode == RECOVER:
sys.exit(str(e))
except VerificationFail as e:
sys.exit(str(e))
elif options.mode == RECOVER:
try:
do_recover(options) do_recover(options)
except NoFiles as e: else:
sys.exit(str(e)) assert options.mode == VERIFY
else:
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))
if __name__ == '__main__': if __name__ == '__main__':
......
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