5 A short script to list defects.
10 from argparse
import ArgumentParser
12 from DQDefects
import DefectsDB
13 from DQDefects.db
import DEFAULT_CONNECTION_STRING
16 return ddb.defect_names
18 return ddb.virtual_defect_names
20 return ddb.defect_names | ddb.virtual_defect_names
23 ddb = DefectsDB(connection_string)
25 nspec =
sum(
bool(x)
for x
in (args.tags, args.defect_tags, args.logic_tags))
26 assert nspec == 1,
"Only one of --tags, --logic-tags and --defect-tags can be specified."
31 tags = ddb.logics_tags
33 tags = ddb.defects_tags
38 def show_defects(connection_string, tag, get_defects, patterns, args):
39 ddb = DefectsDB(connection_string, tag=tag)
41 all_defects = get_defects(ddb)
43 for pattern
in patterns:
44 if len(patterns) != 1:
47 for defect
in sorted(fnmatch.filter(all_defects, pattern)):
51 ddb = DefectsDB(connection_string, tag=tag)
53 descriptions = ddb.all_defect_descriptions
if args.descriptions
else {}
55 all_defects = get_defects(ddb)
56 all_matching = [d
for pat
in patterns
for d
in fnmatch.filter(all_defects, pat)]
60 get_virtuality =
lambda defect:
""
61 if args.show_virtuality:
62 primary_defects = ddb.defect_names
63 def get_virtuality(defect):
64 if defect
in primary_defects:
68 ldl = longest_defect_length =
max(len(d)
for d
in all_matching)
70 for pattern
in patterns:
71 if len(patterns) != 1:
73 for defect
in sorted(fnmatch.filter(all_defects, pattern)):
74 desc = descriptions.get(defect,
"")
76 defect, desc, width=ldl, virtuality=get_virtuality(defect)))
80 ddb = DefectsDB(connection_string, tag=tag)
82 defects = ddb.virtual_defect_names
83 logics = ddb.virtual_defect_logics
85 all_matching = [d
for pat
in patterns
for d
in fnmatch.filter(defects, pat)]
89 ldl = longest_defect_length =
max(len(d)
for d
in all_matching)
91 for pattern
in patterns:
92 if len(patterns) != 1:
94 for defect
in sorted(fnmatch.filter(defects, pattern)):
96 defect,
", ".
join(logics[defect].clauses), width=ldl))
100 parser = ArgumentParser(description=
"List information from the defects "
102 a = parser.add_argument
103 add_group = parser.add_argument_group
105 a(
"-c",
"--connection-string", default=DEFAULT_CONNECTION_STRING,
106 help=
"Database connection to use (default: %s)" % DEFAULT_CONNECTION_STRING)
111 tag_group = add_group(
"tags",
"Show information about tags")
112 a = tag_group.add_argument
114 a(
"--tags", action=
"store_true",
115 help=
"List all available hierarchical tags")
117 a(
"--logic-tags", action=
"store_true",
118 help=
"Show all logic tags")
120 a(
"--defect-tags", action=
"store_true",
121 help=
"Show all defect tags")
126 defect_group = add_group(
"defects",
"Show information about defects")
127 a = defect_group.add_argument
129 a(
"-t",
"--tag", default=
None,
130 help=
"Tag to use (default: HEAD)")
132 a(
"-l",
"--logic", action=
"store_true",
133 help=
"Show logic used for virtual flags (use -v)")
135 a(
"-V",
"--show-virtuality", action=
"store_true",
136 help=
"Indicate virtual vs nonvirtual flags")
138 a(
"-v",
"--virtual", action=
"store_true",
139 help=
"Show only virtual flags")
141 a(
"-p",
"--primary", action=
"store_true",
142 help=
"Show only primary flags")
144 a(
"-d",
"--descriptions", action=
"store_true",
145 help=
"Show descriptions")
147 a(
"patterns", metavar=
"defect", type=str, nargs=
"*", default=[],
148 help=
"One or more defect globs")
151 DEFECT_OPTIONS = [
"logic",
"show_virtuality",
"virtual",
"primary",
152 "descriptions",
"patterns",
"tag"]
154 args = parser.parse_args()
158 if args.tags
or args.logic_tags
or args.defect_tags:
160 for arg
in DEFECT_OPTIONS:
161 if getattr(args, arg):
162 raise RuntimeError(
"--%s doesn't work with any --tags options" % arg)
167 if not args.patterns:
169 args.patterns = [
"*"]
174 assert not args.primary,
"--primary doesn't work with --logic"
175 assert not args.descriptions,
"--descriptions doesn't work with --logic"
176 assert not args.show_virtuality,
"--show-virtuality doesn't work with --logic"
178 arguments = args.connection_string, args.tag, args.patterns, args
183 get_defects = get_both
184 if args.primary
or args.virtual:
185 if args.primary
and not args.virtual:
186 get_defects = get_primary
188 get_defects = get_virtual
190 arguments = args.connection_string, args.tag, get_defects, args.patterns, args
192 if args.descriptions:
197 if __name__ ==
"__main__":