Mercurial > ~dholland > hg > swallowtail > index.cgi
annotate shelltools/query-pr/query.py @ 46:73e6dac29391
new stuff (checkpoint when moved between machines)
author | David A. Holland |
---|---|
date | Tue, 12 Aug 2014 21:55:08 -0400 |
parents | 298c8a7f5181 |
children | bcd1d06838fd |
rev | line source |
---|---|
7
c013fb703183
Empty placeholder scripts so the build will run.
David A. Holland
parents:
diff
changeset
|
1 #!@PYTHON@ |
33 | 2 |
3 import argparse | |
4 import psycopg2 | |
5 | |
6 program_description = """ | |
7 Search for and retrieve problem reports. | |
8 """ | |
9 program_version = "@VERSION@" | |
10 | |
11 ############################################################ | |
12 # settings | |
13 | |
14 outfile = sys.stdout | |
15 outmaterial = "headers" | |
16 outformat = "text" | |
17 | |
18 ############################################################ | |
19 # database | |
20 | |
21 dblink = None | |
22 | |
23 def opendb(): | |
24 global dblink | |
25 | |
26 host = "localhost" | |
27 user = "swallowtail" | |
28 database = "swallowtail" | |
29 dblink = psycopg2.connect("host=%s user=%s dbname=%s" % | |
30 (host, user, database)) | |
31 # end opendb | |
32 | |
33 def closedb(): | |
34 global dblink | |
35 | |
36 dblink.close() | |
37 dblink = None | |
38 # end closedb | |
39 | |
40 def querydb(qtext, args): | |
41 print "Executing this query:" | |
42 print qtext | |
43 print "Args are:" | |
44 print args | |
45 | |
46 cursor = dblink.cursor() | |
47 cursor.execute(qtext, args) | |
48 result = cursor.fetchall() | |
49 cursor.close() | |
50 return result | |
51 # end querydb | |
52 | |
53 ############################################################ | |
54 # query class for searches | |
55 | |
56 class Query: | |
57 __init__(self): | |
58 self.selections = [] | |
59 self.tables = [] | |
60 self.constraints = [] | |
61 self.args = [] | |
62 prtables = ["PRs"] | |
63 prconstraints = [] | |
64 | |
65 def select(self, s): | |
66 self.selections.append(s) | |
67 | |
68 def addtable(self, t): | |
69 assert(t not in self.tables) | |
70 self.tables.append(t) | |
71 | |
72 def constrain(self, expr): | |
73 self.constraints.append(t) | |
74 | |
75 def internval(self, val): | |
76 num = len(self.args) | |
77 self.args[num] = val | |
78 return "$%d" % num | |
79 | |
80 def textify(self): | |
81 s = "SELECT %s\n" % ",".join(self.selections) | |
82 f = "FROM %s\n" % ",".join(self.tables) | |
83 w = "WHERE %s\n" % " AND ".join(self.constraints) | |
84 return s + f + w | |
85 # end class Query | |
86 | |
87 def regexp_constraint(q, field, value): | |
88 cleanval = q.internval(value) | |
89 if not isregexp(value): | |
90 return "%s = %s" % (field, cleanval) | |
91 else: | |
92 # XXX what's the right operator again? | |
93 return "%s ~= %s" % (field, cleanval) | |
94 # end regexp_constraint | |
95 | |
96 def intrange_constraint(q, field, value): | |
97 (lower, upper) = args.number | |
98 if lower is not None: | |
99 assert(typeof(lower) == int) | |
100 prq.constrain("%s >= %d" % (field, lower)) | |
101 if upper is not None: | |
102 assert(typeof(upper) == int) | |
103 prq.constrain("%s <= %d" % (field, upper)) | |
104 # end intrange_constraint | |
105 | |
106 def daterange_constraint(q, field, value): | |
107 # XXX | |
108 assert(0) | |
109 # end daterange_constraint | |
110 | |
111 ############################################################ | |
112 | |
113 # If we're doing something other than a search, do it now | |
114 if args.attach is not None: | |
115 get_attachment(args.attach) | |
116 exit(0) | |
117 if args.message is not None: | |
118 get_message(args.message) | |
119 exit(0) | |
120 | |
121 if args.prs is not None and len(args.prs) > 0: | |
122 show_prs(args.prs) | |
123 exit(0) | |
124 | |
125 # | |
126 # Collect up the search constraints | |
127 # | |
128 | |
129 # 1. Constraints on the PRs table | |
130 checkprtable = False | |
131 prq = Query() | |
132 prq.select("PRs.id as id") | |
133 prq.addtable("PRs") | |
134 if not args.closed: | |
135 checkprtable = True | |
136 prq.addtable("states") | |
137 prq.constrain("PRs.state = states.name") | |
138 prq.constrain("states.closed = FALSE") | |
139 if args.public: | |
140 checkprtable = True | |
141 prq.constrain("NOT PRs.confidential") | |
142 if args.number is not None: | |
143 checkprtable = True | |
144 intrange_constraint(prq, "PRs.id", args.number) | |
145 if args.synopsis is not None: | |
146 checkprtable = True | |
147 regexp_constraint(prq, "PRs.synopsis", args.synopsis) | |
148 if args.confidential is not None: | |
149 checkprtable = True | |
150 assert(typeof(args.confidential) == bool) | |
151 if args.confidential: | |
152 prq.constrain("PRs.confidential") | |
153 else: | |
154 prq.constrain("not PRs.confidential") | |
155 if args.state is not None: | |
156 checkprtable = True | |
157 regexp_constraint(prq, "PRs.state", args.state) | |
158 if args.locked is not None: | |
159 checkprtable = True | |
160 assert(typeof(args.locked) == bool) | |
161 if args.locked: | |
162 prq.constrain("PRs.locked") | |
163 else: | |
164 prq.constrain("not PRs.locked") | |
165 if args.arrival_schemaversion is not None: | |
166 checkprtable = True | |
167 intrange_constraint(prq, "PRs.arrival_schemaversion", | |
168 args.arrival_schemaversion) | |
169 if args.arrival_date is not None: | |
170 checkprtable = True | |
171 daterange_constraint(prq, "PRs.arrival_date", | |
172 args.arrival_date) | |
173 if args.closed_date is not None: | |
174 checkprtable = True | |
175 daterange_constraint(prq, "PRs.closed_date", | |
176 args.closed_date) | |
177 if args.last_modified is not None: | |
178 checkprtable = True | |
179 daterange_constraint(prq, "PRs.last_modified", | |
180 args.last_modified) | |
181 if args.release is not None: | |
182 checkprtable = True | |
183 regexp_constraint(prq, "PRs.release", args.release) | |
184 if args.environment is not None: | |
185 checkprtable = True | |
186 regexp_constraint(prq, "PRs.environment", args.environment) | |
187 | |
188 if args.originator_name is not None or | |
189 args.originator_email is not None: | |
190 prq.addtable("usermail as originator") | |
191 prq.constrain("PRs.originator = originator.id") | |
192 if args.originator_name is not None: | |
193 checkprtable = True | |
194 regexp_constraint(prq, "originator.realname", | |
195 args.originator_name) | |
196 if args.originator_email is not None: | |
197 checkprtable = True | |
198 regexp_constraint(prq, "originator.email", | |
199 args.originator_name) | |
200 if args.originator_id is not None: | |
201 checkprtable = True | |
202 intrange_constraint(prq, "PRs.originator", args.originator_id) | |
203 | |
204 queries = [] | |
205 if checkprtable: | |
206 queries.append(prq) | |
207 | |
208 if args.responsible is not None: | |
209 sq = Query() | |
210 sq.select("subscriptions.pr as id") | |
211 sq.addtable("subscriptions") | |
212 sq.addtable("users") | |
213 sq.constrain("subscriptions.userid = users.id") | |
214 regexp_constraint(sq, "users.realname", args.responsible) | |
215 sq.constrain("subscriptions.responsible") | |
216 queries.append(sq) | |
217 if args.respondent is not None: | |
218 sq = Query() | |
219 sq.select("subscriptions.pr as id") | |
220 sq.addtable("subscriptions") | |
221 sq.addtable("users as subscribed") | |
222 sq.constrain("subscriptions.userid = users.id") | |
223 regexp_constraint(sq, "users.realname", args.respondent) | |
224 sq.constrain("subscriptions.reporter") | |
225 queries.append(sq) | |
226 if args.subscribed is not None: | |
227 sq = Query() | |
228 sq.select("subscriptions.pr as id") | |
229 sq.addtable("subscriptions") | |
230 sq.addtable("users as subscribed") | |
231 sq.constrain("subscriptions.userid = users.id") | |
232 regexp_constraint(sq, "users.realname", args.subscribed) | |
233 queries.append(sq) | |
234 | |
235 if args.messages is not None: | |
236 mq = Query() | |
237 mq.select("messages.pr as id") | |
238 mq.addtable("messages") | |
239 regexp_constraint(sq, "messages.text", args.messages) | |
240 queries.append(mq) | |
241 | |
242 if args.adminlog is not None: | |
243 aq = Query() | |
244 aq.select("adminlog.pr as id") | |
245 aq.addtable("adminlog") | |
246 regexp_constraint(sq, "adminlog.change", args.adminlog) | |
247 regexp_constraint(sq, "adminlog.comment", args.adminlog) | |
248 assert(len(aq.constraints) == 2) | |
249 x = "%s OR %s" % (aq.constraints[0], aq.constraints[1]) | |
250 aq.constraints = [x] | |
251 queries.append(aq) | |
252 | |
253 if args.anytext is not None: | |
254 choke("--anytext isn't supported yet") | |
255 | |
256 for scheme in classification_schemes: | |
257 if args[scheme] is not None: | |
258 schemetype = classification_schemetypes[scheme] | |
259 tbl = "%sclass_data" % schemetype | |
260 cq = Query() | |
261 cq.select("scheme.pr as id") | |
262 cq.addtable("%s as scheme" % schemetype) | |
263 cq.constrain("scheme.scheme = '%s'" % scheme) | |
264 regexp_constraint(cq, "scheme.value", args[scheme]) | |
265 queries.append(cq) | |
266 # end loop | |
267 | |
268 querytexts = [q.textify() for q in queries] | |
269 return "INTERSECT\n".join(querytexts) | |
46
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
270 |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
271 |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
272 ############################################################ |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
273 # arg handling |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
274 |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
275 class Invocation: |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
276 class Op: |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
277 # operation codes |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
278 OP_FIELDS = 1 |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
279 OP_SHOW = 2 |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
280 OP_RANGE = 3 |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
281 OP_SEARCH = 4 |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
282 |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
283 def __init__(self, op): |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
284 self.op = op |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
285 |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
286 def dofields(): |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
287 return Op(OP_FIELDS) |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
288 def doshow(field): |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
289 self = Op(OP_SHOW) |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
290 self.field = field |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
291 return self |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
292 def dorange(field): |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
293 self = Op(OP_RANGE) |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
294 self.field = field |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
295 return self |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
296 def doquery( |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
297 |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
298 |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
299 # output formats |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
300 FMT_TXT = 1 |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
301 |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
302 def __init__(self): |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
303 self.op = OP_SEARCH |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
304 self.searchstrings = [] |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
305 self.searchsql = [] |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
306 |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
307 # end Invocation |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
308 |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
309 def getargs(): |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
310 p = argparse.ArgumentParser(program_description) |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
311 |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
312 # note: -h/--help is built in by default |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
313 p.add_argument("-v", "--version", |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
314 action='version', version=program_version, |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
315 help="Print program version and exit") |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
316 |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
317 p.add_argument("--show", nargs=1, |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
318 action = 'store', dest='show', |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
319 help="Show description of field") |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
320 p.add_argument("--range", nargs=1, |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
321 action = 'store', dest='range', |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
322 help="Show range of extant values for field") |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
323 |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
324 p.add_argument("--search", nargs=1, |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
325 action = 'store', dest='search', |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
326 help="Force string to be read as a search string") |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
327 p.add_argument("-s", "--sql", nargs=1, |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
328 action = 'store', dest='sql', |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
329 help="Supply explicit sql query as search") |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
330 |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
331 p.add_argument("--open", |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
332 action = 'store_const', const="True", |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
333 dest = 'openonly', |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
334 help="Exclude closed PRs (default)") |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
335 p.add_argument("--closed", |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
336 action = 'store_const', const="False", |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
337 dest = 'openonly', |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
338 help="Include closed PRs in search") |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
339 p.add_argument("--public", |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
340 action = 'store_const', const="True", |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
341 dest = 'publiconly', |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
342 help="Exclude confidential PRs") |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
343 p.add_argument("--privileged", |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
344 action = 'store_const', const="False", |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
345 dest = 'publiconly', |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
346 help="Allow confidential PRs (default)") |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
347 |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
348 p.add_argument("--oldest", |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
349 action = 'store_const', const="OLDEST", |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
350 dest = 'order', |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
351 help="Sort output with oldest PRs first") |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
352 p.add_argument("--newest", |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
353 action = 'store_const', const="NEWEST", |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
354 dest = 'order', |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
355 help="Sort output with newest PRs first") |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
356 p.add_argument("--staleness", |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
357 action = 'store_const', const="STALENESS", |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
358 dest = 'order', |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
359 help="Sort output by time since last modification") |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
360 p.add_argument("--orderby", nargs=1, |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
361 action = 'store', dest = 'orderfield', |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
362 help="Sort output by specific field") |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
363 p.add_argument("--revorderby", nargs=1, |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
364 action = 'store', dest = 'revorderfield', |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
365 help="Sort output by specific field, reversed") |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
366 |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
367 p.add_argument("-m", "--message", nargs=1, |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
368 action = 'store', dest = 'message', |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
369 help="Print selected message (single PR only)") |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
370 p.add_argument("-a", "--attachment", nargs=1, |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
371 action = 'store', dest = 'attachment', |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
372 help="Print selected attachment (single PR only)") |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
373 |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
374 p.add_argument("-r", "--raw", |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
375 action = 'store_const', const="RAW", |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
376 dest = 'output', |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
377 help="Print exactly what the database returns") |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
378 p.add_argument("-l", "--list", |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
379 action = 'store_const', const="LIST", |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
380 dest = 'output', |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
381 help="Print in list form (default)") |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
382 p.add_argument("--headers", |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
383 action = 'store_const', const="HEADERS", |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
384 dest = 'output', |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
385 help="Print header information only") |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
386 p.add_argument("--meta", |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
387 action = 'store_const', const="META", |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
388 dest = 'output', |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
389 help="Print all metadata") |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
390 p.add_argument("--metadata", |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
391 action = 'store_const', const="META", |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
392 dest = 'output') |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
393 p.add_argument("-f", "--full", |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
394 action = 'store_const', const="FULL", |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
395 dest = 'output', |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
396 help="Print everything") |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
397 |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
398 p.add_argument("--text", |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
399 action = 'store_const', const="TEXT", |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
400 dest = 'outformat', |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
401 help="Print in text format (default)") |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
402 p.add_argument("--csv", |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
403 action = 'store_const', const="CSV", |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
404 dest = 'outformat', |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
405 help="Print a CSV file") |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
406 p.add_argument("--xml", |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
407 action = 'store_const', const="XML", |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
408 dest = 'outformat', |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
409 help="Print in XML") |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
410 p.add_argument("--json", |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
411 action = 'store_const', const="JSON", |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
412 dest = 'outformat', |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
413 help="Print in JSON") |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
414 p.add_argument("--rdf", |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
415 action = 'store_const', const="RDF", |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
416 dest = 'outbformat', |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
417 help="Print in RDF") |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
418 p.add_argument("--rdflike", |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
419 action = 'store_const', const="RDFLIKE", |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
420 dest = 'outformat', |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
421 help="Print RDF-like text") |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
422 |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
423 args = p.parse_args() |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
424 |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
425 p = Invocation() |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
426 |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
427 if args.show is not None: |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
428 do_showfield(args.show) |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
429 exit(0) |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
430 if args.range is not None: |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
431 do_fieldrange(args.range) |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
432 exit(0) |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
433 |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
434 searchstring = args.search |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
435 explicitsql = args.sql |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
436 |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
437 openonly = args.openonly |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
438 if openonly is None: |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
439 openonly = True |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
440 publiconly = args.publiconly |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
441 if publiconly is None: |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
442 publiconly = False |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
443 |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
444 if args.orderfield is not None: |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
445 orderby = args.orderfield |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
446 orderrev = False |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
447 elif args.revorderfield is not None: |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
448 orderby = args.revorderfield |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
449 orderrev = True |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
450 elif args.order == "OLDEST": |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
451 orderby = "number" |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
452 orderrev = False |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
453 elif args.order == "NEWEST": |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
454 orderby = "number" |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
455 orderrev = True |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
456 elif args.order == "STALENESS": |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
457 orderby = "last-modified" |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
458 orderrev = True |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
459 else: |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
460 orderby = "number" |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
461 orderrev = False |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
462 |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
463 if args.message is not None: |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
464 printwhat = "MESSAGE" |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
465 printwhich = args.message |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
466 elif args.attachment is not None: |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
467 printwhat = "ATTACHMENT" |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
468 printwhich = args.attachment |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
469 else: |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
470 printwhat = "PR" |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
471 printwhich = None |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
472 |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
473 output = args.output |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
474 if output is None: |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
475 output = "LIST" |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
476 |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
477 outformat = args.outformat |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
478 if outformat is None: |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
479 outformat = "TEXT" |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
480 |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
481 query = buildquery(searchstring, explicitsql, |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
482 orderby=orderby, orderrev=orderrev, |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
483 openonly=openonly, publiconly=publiconly) |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
484 if printwhat == "PR": |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
485 printer = buildprinter(output, outformat) |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
486 else if printwhat == "MESSAGE": |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
487 printer = getmessage(printwhich) |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
488 else if printwhat == "ATTACHMENT": |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
489 printer = getattachment(printwhich) |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
490 |
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
491 return (query, printer) |
33 | 492 # end getargs |
493 | |
494 ############################################################ | |
495 # main | |
496 | |
497 def main(): | |
46
73e6dac29391
new stuff (checkpoint when moved between machines)
David A. Holland
parents:
33
diff
changeset
|
498 |
33 | 499 opendb() |
500 (classification_schemes, classification_schemetypes) = getclassify() | |
501 query = getargs(classification_schemes, classification_schemetypes) | |
502 ids = querydb(query) | |
503 if len(ids) > 0: | |
504 show_prs(ids) | |
505 else: | |
506 sys.stderr.write("No PRs matched.\n") | |
507 exit(1) | |
508 closedb() | |
509 return 0 | |
510 # end main | |
511 | |
512 # real python hackers doubtless laugh at this | |
513 exit(main()) |