-
Notifications
You must be signed in to change notification settings - Fork 12
/
chase.py
executable file
·124 lines (109 loc) · 2.87 KB
/
chase.py
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env python3
import argparse
import sys
from cases import Cases
#########################################################################
def set_verbosity(a):
p = 0
if a.v != None:
p += len(a.v)
if a.s != None:
p -= len(a.s)
return p
#########################################################################
def main(argv):
parser = argparse.ArgumentParser(
description="DE_330 Case Meta DataBase handler at your service"
)
parser.add_argument(
"-case",
dest="case",
required=False,
default=None,
help="Specify name of case(s) to work with. Use as -case case1[:case2:...:caseN]",
)
parser.add_argument(
"-exp",
dest="exp",
required=False,
default=None,
help="Specify name of exp(s) to work with within a case. Use as -exp exp1[:exp2:...:expN]",
)
parser.add_argument(
"-host",
dest="host",
help="Set host to check, default is current",
required=False,
default=None,
)
parser.add_argument(
"-list",
action="store_true",
help="List content of given case(s)",
required=False,
default=False,
)
parser.add_argument(
"-scan",
action="store_true",
help="Scan case for data",
required=False,
default=False,
)
parser.add_argument(
"-toc",
action="store_true",
help="Create TOC for give filetypes",
required=False,
default=False,
)
parser.add_argument(
"-path",
dest="path",
help="Path to directory with cases",
required=False,
default="cases",
)
parser.add_argument(
"-v",
action="append_const",
const=int,
help="Increase verbosity for list command in particular",
)
parser.add_argument(
"-s",
action="append_const",
const=int,
help="Decrease verbosity for list command in particular",
)
# Handle arguments
if len(argv) == 1:
parser.print_help()
sys.exit(1)
args = parser.parse_args()
case = args.case.split(":") if args.case is not None else None
if args.exp is not None and case is not None:
if len(case) > 1:
print("Only give one case if exp is given")
sys.exit(1)
selection = {k: args.exp.split(":") for k in case}
elif case is not None:
selection = {k: [] for k in case}
else:
selection = []
# Construct the case structure
myc = Cases(
selection=selection,
printlev=set_verbosity(args),
path=args.path,
host=args.host,
)
# Run the actions
if args.scan:
myc.scan()
elif args.list:
myc.print()
elif args.toc:
myc.toc()
if __name__ == "__main__":
sys.exit(main(sys.argv))