-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess_img.py
More file actions
executable file
·47 lines (35 loc) · 1.26 KB
/
process_img.py
File metadata and controls
executable file
·47 lines (35 loc) · 1.26 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
40
41
42
43
44
45
46
#!/usr/bin/python3
'''
Wrapper for the scripts that interacts with the user.
'''
import sys
import os
import argparse
from actions import modules
def call_action(namespace):
'''
Calls one of the scripts on the 'actions/' package to process the
image/images on the given namespace.path
The namespace argument is the output of the main parser.
'''
## Execute script on a single file.
if os.path.isfile(namespace.path):
modules[namespace.command].run(namespace.path, namespace)
## Execute script on all image files in a directory.
elif os.path.isdir(namespace.path):
file_list = os.listdir(namespace.path)
for file_ in file_list:
f_path = os.path.join(namespace.path, file_)
if os.path.isfile(f_path):
print("\n...Processing {} file".format(f_path))
modules[namespace.command].run(f_path, namespace)
else:
msg = "{} is not a valid file path or directory."
print(msg.format(path))
if __name__ == '__main__':
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers()
for module in modules.keys():
modules[module].subparser(subparsers)
namespace = parser.parse_args(sys.argv[1:])
call_action(namespace)