Allow saving attachment without running a plumber

Add a second (optional) positional argument to specify the destination
file. If a file has been specified, just save without running the
default plumber.

Specifying a custom plumber allows to both save and run the plumber.
This commit is contained in:
Yuri D'Elia 2020-10-12 01:41:05 +02:00
parent e43edbcbc9
commit fc69f77923

View file

@ -44,6 +44,7 @@ def main():
description='Download and decrypt matrix attachments'
)
parser.add_argument('url', help='the url of the attachment')
parser.add_argument('file', nargs='?', help='save attachment to <file>')
parser.add_argument('--plumber',
help='program that gets called with the '
'dowloaded file')
@ -68,10 +69,18 @@ def main():
print("Error downloading file")
return -2
plumber = args.plumber or "/usr/bin/rifle"
plumber = args.plumber
plaintext = decrypt_attachment(request.content, key, hash, iv)
file_name = save_file(plaintext)
if args.file is None:
file_name = save_file(plaintext)
if plumber is None:
plumber = "/usr/bin/rifle"
else:
file_name = args.file
open(file_name, "wb").write(plaintext)
if plumber is not None:
subprocess.run([plumber, "{file}".format(file=file_name)])
return 0