crypt to another folder

This commit is contained in:
q
2024-06-26 15:48:57 +03:00
parent fdab7d0bfb
commit 8be7630c77

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env python3
__version__ = "1.0"
__version__ = "1.1"
import argparse
import os
@@ -129,7 +129,8 @@ Usage
)
parser.add_argument("--name", help="Name of the owner of the key", required=False, default="recipient@address")
parser.add_argument(
"--recursive","-r",
"--recursive",
"-r",
default=False,
action="store_true",
help="Recursive encryption or decryption. Processes full folder structures",
@@ -141,10 +142,8 @@ Usage
choices=["k", "e", "d", "keygen", "encrypt", "decrypt"],
)
parser.add_argument("path", help="path to file to encrypt/decrypt, or folder if recursive", nargs="?")
parser.add_argument("out_path", help="output file, if not using recursive.", nargs="?")
parser.add_argument("out_path", help="output file or folder when using recursive.", nargs="?")
parsed = parser.parse_args()
if parsed.out_path and parsed.recursive:
parser.error("Cannot assign output path, when in recursive mode")
for cmd in ("keygen", "encrypt", "decrypt"):
if parsed.command == cmd[0]:
parsed.command = cmd
@@ -260,6 +259,10 @@ class Processor:
auto_path = in_file + self.suffix
if self.opts.command == "decrypt":
auto_path = in_file[: -len(self.suffix)]
if self.opts.recursive and self.opts.out_path:
out_file = os.path.join(self.opts.out_path, os.sep.join(auto_path.split(os.sep)[1:]))
os.makedirs(os.path.dirname(out_file), exist_ok=True)
else:
out_file = self.opts.out_path if self.opts.out_path else auto_path
if os.path.exists(out_file):
print(f"{out_file} already exists", file=sys.stderr)