-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse.py
More file actions
executable file
·131 lines (112 loc) · 3.11 KB
/
Copy pathparse.py
File metadata and controls
executable file
·131 lines (112 loc) · 3.11 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
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
125
126
127
128
129
130
131
#!/usr/bin/env python
"""
Main runnable module.
"""
import optparse
import logging
from cartconf.parser import Parser
LOG = logging.getLogger("avocado." + __name__)
options = None
def print_dicts_default(options, dicts):
"""Print dictionaries in the default mode"""
for count, d in enumerate(dicts):
if options.fullname:
print("dict %4d: %s" % (count + 1, d["name"]))
else:
print("dict %4d: %s" % (count + 1, d["shortname"]))
if options.contents:
keys = list(d.keys())
keys.sort()
for key in keys:
print(" %s = %s" % (key, d[key]))
# pylint: disable=W0613
def print_dicts_repr(options, dicts):
import pprint
print("[")
for d in dicts:
print("%s," % (pprint.pformat(d)))
print("]")
def print_dicts(options, dicts):
if options.repr_mode:
print_dicts_repr(options, dicts)
else:
print_dicts_default(options, dicts)
if __name__ == "__main__":
parser = optparse.OptionParser(
"usage: %prog [options] filename "
"[extra code] ...\n\nExample:\n\n "
'%prog tests.cfg "only my_set" "no qcow2"'
)
parser.add_option(
"-v",
"--verbose",
dest="debug",
action="store_true",
default=False,
help="include debug messages in console output",
)
parser.add_option(
"-f",
"--fullname",
dest="fullname",
action="store_true",
default=False,
help="show full dict names instead of short names",
)
parser.add_option(
"-c",
"--contents",
dest="contents",
action="store_true",
default=False,
help="show dict contents",
)
parser.add_option(
"-r",
"--repr",
dest="repr_mode",
action="store_true",
default=False,
help="output parsing results Python format",
)
parser.add_option(
"-d",
"--defaults",
dest="defaults",
action="store_true",
default=False,
help="use only default variant of variants if there" " is some",
)
parser.add_option(
"-e",
"--expand",
dest="expand",
type="string",
help="list of vartiant which should be expanded when"
' defaults is enabled. "name, name, name"',
)
parser.add_option(
"-s",
"--skip-dups",
dest="skipdups",
action="store_false",
default=True,
help="Don't drop variables with different suffixes and same val",
)
options, args = parser.parse_args()
if not args:
parser.error("filename required")
if options.debug:
LOG.setLevel(logging.DEBUG)
expand = []
if options.expand:
expand = [x.strip() for x in options.expand.split(",")]
c = Parser(
args[0], defaults=options.defaults, expand_defaults=expand, debug=options.debug
)
for s in args[1:]:
c.parse_string(s)
if options.debug:
print(c.node.dump(0, True))
dicts = c.get_dicts_gen(skipdups=options.skipdups)
print_dicts(options, dicts)