crypt to another folder
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
__version__ = "1.0"
|
__version__ = "1.1"
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
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("--name", help="Name of the owner of the key", required=False, default="recipient@address")
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--recursive","-r",
|
"--recursive",
|
||||||
|
"-r",
|
||||||
default=False,
|
default=False,
|
||||||
action="store_true",
|
action="store_true",
|
||||||
help="Recursive encryption or decryption. Processes full folder structures",
|
help="Recursive encryption or decryption. Processes full folder structures",
|
||||||
@@ -141,10 +142,8 @@ Usage
|
|||||||
choices=["k", "e", "d", "keygen", "encrypt", "decrypt"],
|
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("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()
|
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"):
|
for cmd in ("keygen", "encrypt", "decrypt"):
|
||||||
if parsed.command == cmd[0]:
|
if parsed.command == cmd[0]:
|
||||||
parsed.command = cmd
|
parsed.command = cmd
|
||||||
@@ -260,6 +259,10 @@ class Processor:
|
|||||||
auto_path = in_file + self.suffix
|
auto_path = in_file + self.suffix
|
||||||
if self.opts.command == "decrypt":
|
if self.opts.command == "decrypt":
|
||||||
auto_path = in_file[: -len(self.suffix)]
|
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
|
out_file = self.opts.out_path if self.opts.out_path else auto_path
|
||||||
if os.path.exists(out_file):
|
if os.path.exists(out_file):
|
||||||
print(f"{out_file} already exists", file=sys.stderr)
|
print(f"{out_file} already exists", file=sys.stderr)
|
||||||
|
|||||||
Reference in New Issue
Block a user