-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
93 lines (73 loc) · 2.73 KB
/
Copy pathrun.py
File metadata and controls
93 lines (73 loc) · 2.73 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import getopt
import sys
from refacdir.batch import BatchArgs, BatchJob
from refacdir.utils.utils import Utils
help_text = """Edit configuration YAML files in configs directory to configure file management batch actions.
Once desired configurations are set, run with:
python run.py [args]
-h, --help
Print this help text
-v, --verbose
Run in verbose mode
-t, --test
Run file management actions in test mode, without taking any action
-s, --skip-confirm
Run file management actions without confirming
--configs
Specify comma-separated list of config files to run
-o, --only-observers
Load configs but only run any Directory Observer actions defined in them
--persist-definition-caches
Keep filename_mapping_functions / filetype_definitions registries across batch runs
in the same process (default is to clear them at each run for a clean YAML-only view)
"""
def main(args):
batch_job = BatchJob(args)
batch_job.run()
batch_job.log_results()
if __name__ == "__main__":
batch_args = BatchArgs()
try:
opts, args = getopt.getopt(sys.argv[1:], ":hstvo", [
"help",
"verbose",
"test",
"skip-confirm",
"only-observers",
"configs=",
"persist-definition-caches",
])
except getopt.GetoptError as err:
# print help information and exit:
print(err) # will print something like "option -a not recognized"
print(help_text)
sys.exit(2)
for o, a in opts:
# basic options
if o in ("-h", "--help"):
print(help_text)
exit()
elif o in ("-v", "--verbose"):
batch_args.verbose = True
elif o in ("-t", "--test"):
batch_args.test = True
elif o in ("-s", "--skip-confirm"):
batch_args.skip_confirm = True
elif o in ("-c", "--configs"):
string_list = a.strip()
if string_list == "":
raise Exception("Expected config file paths list not found")
try:
config_list = Utils.get_list_from_string(string_list)
batch_args.configs = {
str(path).strip(): True
for path in config_list
if str(path).strip()
}
except Exception as e:
raise Exception(f"Invalid config list provided: {e}")
elif o in ("-o", "--only-observers"):
batch_args.only_observers = True
elif o == "--persist-definition-caches":
batch_args.persist_definition_caches_across_batch_runs = True
main(batch_args)