-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
39 lines (32 loc) · 1.28 KB
/
main.py
File metadata and controls
39 lines (32 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# FILE: __main__.py
# PROJECT: crypto
# PROGRAMMER: Samuel Lagunju
# DESCRIPTION: This file is the main for the module
import os
import click
from crypto.crypter import Crypter, CrypterFactory
from crypto.fileio import validate_file, file_deconstruct
@click.command()
@click.option(
"--encrypt", "-e", multiple=True, default="", help="Produces an encrypted file\n"
)
@click.option(
"--decrypt", "-d", multiple=True, default="", help="Produces a decrypted file\n"
)
@click.argument("files", nargs=-1, type=click.Path())
def main(encrypt, decrypt, files):
all_files = [*encrypt, *decrypt, *files]
valid_files = [file for file in all_files if validate_file(file) == True]
invalid_files = [file for file in all_files if (validate_file(file) == False)]
if valid_files:
crypter_factory = CrypterFactory()
file_stems, file_extensions, file_names = file_deconstruct(valid_files)
crypter_ojects = crypter_factory.create(file_extensions)
for crypter_ojects, file_names in zip(crypter_ojects, file_names):
crypter_ojects.execute(file_names)
if invalid_files:
for invalid_file in invalid_files:
print("Invalid File: {0}".format(invalid_file))
print("Exiting...")
if __name__ == "__main__":
main()