handle error cases better

This commit is contained in:
Daniel Kahn Gillmor 2021-08-10 21:55:36 -04:00
parent 44b677fdb2
commit 1288f8ca53
2 changed files with 7 additions and 1 deletions

View File

@ -53,7 +53,8 @@ def cli():
help="File containing raw encryption key to use to decrypt the backup",
mutually_exclusive=["password"])
@click.argument("BACKUP_PATH", type=click.Path(exists=True))
def decrypt_backup(destination, password, key_file, backup_path):
@click.pass_context
def decrypt_backup(ctx, destination, password, key_file, backup_path):
backup = DecryptBackup(backup_path, destination)
if key_file:
@ -75,6 +76,8 @@ def decrypt_backup(destination, password, key_file, backup_path):
sekrit = Prompt.ask("Enter backup password", password=True)
backup.decrypt_with_password(sekrit)
if not backup.can_process():
ctx.exit(1)
backup.process_backup()

View File

@ -28,6 +28,9 @@ class DecryptBackup:
self._backup = None
self._decryption_key = None
def can_process(self) -> bool:
return self._backup is not None
def process_backup(self):
if not os.path.exists(self.dest_path):
os.makedirs(self.dest_path)