annotate shelltools/query-pr/query.py @ 56:42d7888272a0 default tip

Implement fetch_classifications().
author David A. Holland
date Sun, 10 Apr 2022 19:37:18 -0400
parents 40f64a96481f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
c013fb703183 Empty placeholder scripts so the build will run.
David A. Holland
parents:
diff changeset
1 #!@PYTHON@
33
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
2
48
3d5adf5a59d0 Fix python2.7 syntax errors.
David A. Holland
parents: 47
diff changeset
3 import sys
33
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
4 import argparse
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
5 import psycopg2
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
6
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
7 program_version = "@VERSION@"
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
8
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
9 ############################################################
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
10 # settings
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
11
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
12 outfile = sys.stdout
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
13 outmaterial = "headers"
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
14 outformat = "text"
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
15
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
16 ############################################################
52
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
17 # simple dump widget
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
18
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
19 class Dumper:
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
20 def __init__(self, f):
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
21 self.f = f
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
22 self.indentation = 0
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
23 def indent(self):
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
24 self.indentation += 3
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
25 def unindent(self):
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
26 self.indentation -= 3
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
27 def write(self, msg):
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
28 self.f.write(" " * self.indentation + msg + "\n")
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
29
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
30 ############################################################
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
31 # database field access
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
32
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
33 #
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
34 # Fields of PRs that we might search are spread across a number of
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
35 # tables and require varying joins to get them. And, because of
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
36 # classication schemes, the set of fields isn't static and we can't
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
37 # just assemble a massive view with one column for each field.
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
38 #
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
39 # The QueryBuilder class knows how to arrange for all known fields to
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
40 # be present.
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
41 #
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
42
56
42d7888272a0 Implement fetch_classifications().
David A. Holland
parents: 55
diff changeset
43 # loaded below
42d7888272a0 Implement fetch_classifications().
David A. Holland
parents: 55
diff changeset
44 hierclasses = []
42d7888272a0 Implement fetch_classifications().
David A. Holland
parents: 55
diff changeset
45 flatclasses = []
42d7888272a0 Implement fetch_classifications().
David A. Holland
parents: 55
diff changeset
46 textclasses = []
42d7888272a0 Implement fetch_classifications().
David A. Holland
parents: 55
diff changeset
47 tagclasses = []
42d7888272a0 Implement fetch_classifications().
David A. Holland
parents: 55
diff changeset
48
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
49 class QueryBuilder:
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
50 # these fields are in the PRs table
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
51 prtable_fields = [
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
52 "id", "synopsis", "confidential", "state", "locked",
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
53 "timeout_date", "timeout_state",
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
54 "arrival_schemaversion", "arrival_date", "modified_date",
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
55 "closed_date",
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
56 "release", "environment"
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
57 ]
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
58
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
59 # these fields are aliases for others
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
60 alias_fields = {
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
61 "number" : "id",
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
62 "date" : "arrival_date",
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
63 }
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
64
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
65 def __init__(self):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
66 self.present = {}
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
67 self.joined = {}
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
68 self.fromitems = []
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
69 self.whereitems = []
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
70 self.order = None
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
71
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
72 def setorder(self, order):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
73 self.order = order
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
74
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
75 # add to present{} and return the value for convenience (internal)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
76 def makepresent(self, field, name):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
77 self.present[field] = name
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
78 return name
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
79
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
80 # add a join item (once only) (internal)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
81 def addjoin(self, table, as_ = None):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
82 if as_ is not None:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
83 key = table + "-" + as_
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
84 val = table + " AS " + as_
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
85 else:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
86 key = table
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
87 val = table
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
88 if key not in self.joined:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
89 self.joined[key] = True
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
90 self.fromitems.append(val)
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
91
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
92 # returns a sql expression for the field
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
93 def getfield(self, field):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
94 # already-fetched fields
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
95 if field in self.present:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
96 return self.present[field]
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
97
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
98 # aliases for other fields
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
99 if field in alias_fields:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
100 return self.getfield(alias_fields[field])
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
101
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
102 # simple fields directly in the PRs table
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
103 if field in prtable_fields:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
104 self.addjoin("PRs")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
105 return self.makepresent(field, "PRs." + field)
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
106
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
107 # now it gets more interesting...
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
108 if field == "closed":
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
109 self.addjoin("PRs")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
110 self.addjoin("states")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
111 self.addwhere("PRs.state = states.name")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
112 return self.makepresent(field, "states.closed")
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
113
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
114 # XXX let's pick one set of names and use them everywhere
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
115 # (e.g. change "posttime" in the schema to "message_date"
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
116 # or something)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
117 if field == "comment_date" or field == "posttime":
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
118 self.addjoin("PRs")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
119 self.addjoin("messages")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
120 self.addwhere("PRs.id = messages.pr")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
121 return self.makepresent(field, "messages.posttime")
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
122
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
123 if field == "comment" or field == "message" or field == "post":
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
124 self.addjoin("PRs")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
125 self.addjoin("messages")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
126 self.addwhere("PRs.id = messages.pr")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
127 return self.makepresent(field, "messages.body")
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
128
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
129 if field == "attachment":
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
130 self.addjoin("PRs")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
131 self.addjoin("messages")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
132 self.addjoin("attachments")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
133 self.addwhere("PRs.id = messages.pr")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
134 self.addwhere("messages.id = attachments.msgid")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
135 return self.makepresent(field, "attachments.body")
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
136
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
137 if field == "patch":
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
138 self.addjoin("PRs")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
139 self.addjoin("messages")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
140 self.addjoin("attachments", "patches")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
141 self.addwhere("PRs.id = messages.pr")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
142 self.addwhere("messages.id = patches.msgid")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
143 self.addwhere("patches.mimetype = " +
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
144 "'application/x-patch'")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
145 return self.makepresent(field, "patches.body")
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
146
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
147 if field == "mimetype":
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
148 subquery = "((SELECT mtmessages1.pr as pr, " + \
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
149 "mtmessages1.mimetype as mimetype " + \
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
150 "FROM messages as mtmessages1) " + \
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
151 "UNION " + \
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
152 "(SELECT mtmessages2.pr as pr, " + \
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
153 "mtattach2.mimetype as mimetype " + \
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
154 "FROM messages as mtmessages2, " + \
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
155 " attachments as mtattach2 " + \
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
156 "WHERE mtmessages2.id = mtattach2.msgid))"
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
157 self.addjoin("PRs")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
158 self.addjoin(subquery, "mimetypes")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
159 self.addwhere("PRs.id = mimetypes.pr")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
160 return self.makepresent(field, "mimetypes.mimetype")
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
161
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
162 # XXX: need view userstrings
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
163 # select (id, username as name) from users
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
164 # union select (id, realname as name) from users
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
165 # (allow searching emails? ugh)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
166 if field == "originator" or field == "submitter":
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
167 self.addjoin("PRs")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
168 self.addjoin("userstrings", "originators")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
169 self.addwhere("PRs.originator = originators.id")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
170 return self.makepresent(field, "originators.name")
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
171
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
172 if field == "reporter" or field == "respondent":
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
173 self.addjoin("PRs")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
174 self.addjoin("subscriptions")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
175 self.addjoin("userstrings", "reporters")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
176 self.addwhere("subscriptions.userid = reporters.id")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
177 self.addwhere("subscriptions.reporter")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
178 return self.makepresent(field, "reporters.name")
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
179
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
180 if field == "responsible":
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
181 self.addjoin("PRs")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
182 self.addjoin("subscriptions")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
183 self.addjoin("userstrings", "responsibles")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
184 self.addwhere("subscriptions.userid = responsibles.id")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
185 self.addwhere("subscriptions.responsible")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
186 return self.makepresent(field, "responsibles.name")
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
187
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
188 if field in hierclasses:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
189 col = field + "_data"
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
190 self.addjoin("PRs")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
191 self.addjoin("hierclass_data", col)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
192 self.addwhere("PRs.id = %s.pr" % col)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
193 self.addwhere("%s.scheme = '%s'" % (col, field))
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
194 return self.makepresent(field, "%s.value" % col)
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
195
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
196 if field in flatclasses:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
197 col = field + "_data"
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
198 self.addjoin("PRs")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
199 self.addjoin("flatclass_data", col)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
200 self.addwhere("PRs.id = %s.pr" % col)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
201 self.addwhere("%s.scheme = '%s'" % (col, field))
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
202 return self.makepresent(field, "%s.value" % col)
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
203
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
204 if field in textclasses:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
205 col = field + "_data"
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
206 self.addjoin("PRs")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
207 self.addjoin("textclass_data", col)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
208 self.addwhere("PRs.id = %s.pr" % col)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
209 self.addwhere("%s.scheme = '%s'" % (col, field))
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
210 return self.makepresent(field, "%s.value" % col)
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
211
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
212 if field in tagclasses:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
213 col = field + "_data"
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
214 self.addjoin("PRs")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
215 self.addjoin("tagclass_data", col)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
216 self.addwhere("PRs.id = %s.pr" % col)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
217 self.addwhere("%s.scheme = '%s'" % (col, field))
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
218 return self.makepresent(field, "%s.value" % col)
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
219
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
220 sys.stderr.write("Unknown field %s" % field)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
221 exit(1)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
222 # end getfield
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
223
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
224 # emit sql
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
225 def build(self, sels):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
226 s = ", ".join(sels)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
227 f = ", ".join(self.fromitems)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
228 w = " and ".join(self.whereitems)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
229 q = "SELECT %s\nFROM %s\nWHERE %s\n" % (s, f, w)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
230 if self.order is not None:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
231 q = q + "ORDER BY " + self.order + "\n"
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
232 return q
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
233 # endif
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
234
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
235 # end class QueryBuilder
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
236
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
237 # XXX we need to add dynamically:
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
238 # hierclass_names.name to hierclasses[]
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
239 # flatclass_names.name to flatclasses[]
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
240 # textclass_names.name to textclasses[]
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
241 # tagclass_names.name to tagclasses[]
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
242
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
243 ############################################################
33
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
244 # database
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
245
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
246 dblink = None
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
247
55
40f64a96481f Adjust database user arrangements and grant schema privs.
David A. Holland
parents: 52
diff changeset
248 def opendb(paranoid):
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
249 global dblink
33
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
250
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
251 host = "localhost"
55
40f64a96481f Adjust database user arrangements and grant schema privs.
David A. Holland
parents: 52
diff changeset
252 user = "swallowtail_public" if paranoid else "swallowtail_reader"
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
253 database = "swallowtail"
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
254 dblink = psycopg2.connect("host=%s user=%s dbname=%s" %
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
255 (host, user, database))
33
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
256 # end opendb
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
257
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
258 def closedb():
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
259 global dblink
33
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
260
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
261 dblink.close()
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
262 dblink = None
33
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
263 # end closedb
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
264
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
265 def querydb(qtext, args):
51
ef6d572c4e1e switch to python3 style print()
David A. Holland
parents: 50
diff changeset
266 print("Executing this query:")
ef6d572c4e1e switch to python3 style print()
David A. Holland
parents: 50
diff changeset
267 print(qtext)
ef6d572c4e1e switch to python3 style print()
David A. Holland
parents: 50
diff changeset
268 print("Args are:")
ef6d572c4e1e switch to python3 style print()
David A. Holland
parents: 50
diff changeset
269 print(args)
33
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
270
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
271 cursor = dblink.cursor()
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
272 cursor.execute(qtext, args)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
273 result = cursor.fetchall()
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
274 cursor.close()
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
275 return result
33
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
276 # end querydb
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
277
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
278 ############################################################
56
42d7888272a0 Implement fetch_classifications().
David A. Holland
parents: 55
diff changeset
279 # classification schemes
42d7888272a0 Implement fetch_classifications().
David A. Holland
parents: 55
diff changeset
280
42d7888272a0 Implement fetch_classifications().
David A. Holland
parents: 55
diff changeset
281 #
42d7888272a0 Implement fetch_classifications().
David A. Holland
parents: 55
diff changeset
282 # Load the available classification schemes from the database.
42d7888272a0 Implement fetch_classifications().
David A. Holland
parents: 55
diff changeset
283 # We only need their names up front.
42d7888272a0 Implement fetch_classifications().
David A. Holland
parents: 55
diff changeset
284 #
42d7888272a0 Implement fetch_classifications().
David A. Holland
parents: 55
diff changeset
285 def fetch_classifications():
42d7888272a0 Implement fetch_classifications().
David A. Holland
parents: 55
diff changeset
286 global hierclasses, flatclasses, textclasses, tagclasses
42d7888272a0 Implement fetch_classifications().
David A. Holland
parents: 55
diff changeset
287 hierclasses = querydb('''
42d7888272a0 Implement fetch_classifications().
David A. Holland
parents: 55
diff changeset
288 ------------------------------
42d7888272a0 Implement fetch_classifications().
David A. Holland
parents: 55
diff changeset
289 SELECT name FROM hierclass_names ORDER BY ordering;
42d7888272a0 Implement fetch_classifications().
David A. Holland
parents: 55
diff changeset
290 ------------------------------
42d7888272a0 Implement fetch_classifications().
David A. Holland
parents: 55
diff changeset
291 ''', [])
42d7888272a0 Implement fetch_classifications().
David A. Holland
parents: 55
diff changeset
292 flatclasses = querydb('''
42d7888272a0 Implement fetch_classifications().
David A. Holland
parents: 55
diff changeset
293 ------------------------------
42d7888272a0 Implement fetch_classifications().
David A. Holland
parents: 55
diff changeset
294 SELECT name FROM flatclass_names ORDER BY ordering;
42d7888272a0 Implement fetch_classifications().
David A. Holland
parents: 55
diff changeset
295 ------------------------------
42d7888272a0 Implement fetch_classifications().
David A. Holland
parents: 55
diff changeset
296 ''', [])
42d7888272a0 Implement fetch_classifications().
David A. Holland
parents: 55
diff changeset
297 textclasses = querydb('''
42d7888272a0 Implement fetch_classifications().
David A. Holland
parents: 55
diff changeset
298 ------------------------------
42d7888272a0 Implement fetch_classifications().
David A. Holland
parents: 55
diff changeset
299 SELECT name FROM textclass_names ORDER BY ordering;
42d7888272a0 Implement fetch_classifications().
David A. Holland
parents: 55
diff changeset
300 ------------------------------
42d7888272a0 Implement fetch_classifications().
David A. Holland
parents: 55
diff changeset
301 ''', [])
42d7888272a0 Implement fetch_classifications().
David A. Holland
parents: 55
diff changeset
302 tagclasses = querydb('''
42d7888272a0 Implement fetch_classifications().
David A. Holland
parents: 55
diff changeset
303 ------------------------------
42d7888272a0 Implement fetch_classifications().
David A. Holland
parents: 55
diff changeset
304 SELECT name FROM tagclass_names ORDER BY ordering;
42d7888272a0 Implement fetch_classifications().
David A. Holland
parents: 55
diff changeset
305 ------------------------------
42d7888272a0 Implement fetch_classifications().
David A. Holland
parents: 55
diff changeset
306 ''', [])
42d7888272a0 Implement fetch_classifications().
David A. Holland
parents: 55
diff changeset
307 # The results come back as monoples, unwrap that
42d7888272a0 Implement fetch_classifications().
David A. Holland
parents: 55
diff changeset
308 hierclasses = [name for (name,) in hierclasses]
42d7888272a0 Implement fetch_classifications().
David A. Holland
parents: 55
diff changeset
309 flatclasses = [name for (name,) in flatclasses]
42d7888272a0 Implement fetch_classifications().
David A. Holland
parents: 55
diff changeset
310 textclasses = [name for (name,) in textclasses]
42d7888272a0 Implement fetch_classifications().
David A. Holland
parents: 55
diff changeset
311 tagclasses = [name for (name,) in tagclasses]
42d7888272a0 Implement fetch_classifications().
David A. Holland
parents: 55
diff changeset
312
42d7888272a0 Implement fetch_classifications().
David A. Holland
parents: 55
diff changeset
313 ############################################################
33
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
314 # query class for searches
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
315 # XXX: obsolete, remove
33
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
316
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
317 class Query:
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
318 def __init__(self):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
319 self.selections = []
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
320 self.tables = []
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
321 self.constraints = []
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
322 self.args = []
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
323 prtables = ["PRs"]
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
324 prconstraints = []
33
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
325
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
326 def select(self, s):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
327 self.selections.append(s)
33
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
328
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
329 def addtable(self, t):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
330 assert(t not in self.tables)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
331 self.tables.append(t)
33
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
332
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
333 def constrain(self, expr):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
334 self.constraints.append(t)
33
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
335
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
336 def internval(self, val):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
337 num = len(self.args)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
338 self.args[num] = val
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
339 return "$%d" % num
33
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
340
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
341 def textify(self):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
342 s = "SELECT %s\n" % ",".join(self.selections)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
343 f = "FROM %s\n" % ",".join(self.tables)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
344 w = "WHERE %s\n" % " AND ".join(self.constraints)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
345 return s + f + w
33
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
346 # end class Query
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
347
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
348 def regexp_constraint(q, field, value):
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
349 cleanval = q.internval(value)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
350 if not isregexp(value):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
351 return "%s = %s" % (field, cleanval)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
352 else:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
353 # XXX what's the right operator again?
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
354 return "%s ~= %s" % (field, cleanval)
33
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
355 # end regexp_constraint
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
356
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
357 def intrange_constraint(q, field, value):
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
358 (lower, upper) = args.number
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
359 if lower is not None:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
360 assert(typeof(lower) == int)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
361 prq.constrain("%s >= %d" % (field, lower))
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
362 if upper is not None:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
363 assert(typeof(upper) == int)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
364 prq.constrain("%s <= %d" % (field, upper))
33
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
365 # end intrange_constraint
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
366
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
367 def daterange_constraint(q, field, value):
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
368 # XXX
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
369 assert(0)
33
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
370 # end daterange_constraint
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
371
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
372 ############################################################
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
373
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
374 # this is old code that needs to be merged or deleted into the new stuff
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
375 def oldstuff():
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
376
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
377 # If we're doing something other than a search, do it now
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
378 if args.attach is not None:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
379 get_attachment(args.attach)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
380 exit(0)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
381 if args.message is not None:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
382 get_message(args.message)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
383 exit(0)
33
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
384
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
385 if args.prs is not None and len(args.prs) > 0:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
386 show_prs(args.prs)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
387 exit(0)
33
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
388
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
389 #
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
390 # Collect up the search constraints
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
391 #
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
392
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
393 # 1. Constraints on the PRs table
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
394 checkprtable = False
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
395 prq = Query()
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
396 prq.select("PRs.id as id")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
397 prq.addtable("PRs")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
398 if not args.closed:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
399 checkprtable = True
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
400 prq.addtable("states")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
401 prq.constrain("PRs.state = states.name")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
402 prq.constrain("states.closed = FALSE")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
403 if args.public:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
404 checkprtable = True
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
405 prq.constrain("NOT PRs.confidential")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
406 if args.number is not None:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
407 checkprtable = True
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
408 intrange_constraint(prq, "PRs.id", args.number)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
409 if args.synopsis is not None:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
410 checkprtable = True
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
411 regexp_constraint(prq, "PRs.synopsis", args.synopsis)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
412 if args.confidential is not None:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
413 checkprtable = True
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
414 assert(typeof(args.confidential) == bool)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
415 if args.confidential:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
416 prq.constrain("PRs.confidential")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
417 else:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
418 prq.constrain("not PRs.confidential")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
419 if args.state is not None:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
420 checkprtable = True
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
421 regexp_constraint(prq, "PRs.state", args.state)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
422 if args.locked is not None:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
423 checkprtable = True
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
424 assert(typeof(args.locked) == bool)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
425 if args.locked:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
426 prq.constrain("PRs.locked")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
427 else:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
428 prq.constrain("not PRs.locked")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
429 if args.arrival_schemaversion is not None:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
430 checkprtable = True
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
431 intrange_constraint(prq, "PRs.arrival_schemaversion",
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
432 args.arrival_schemaversion)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
433 if args.arrival_date is not None:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
434 checkprtable = True
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
435 daterange_constraint(prq, "PRs.arrival_date",
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
436 args.arrival_date)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
437 if args.closed_date is not None:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
438 checkprtable = True
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
439 daterange_constraint(prq, "PRs.closed_date",
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
440 args.closed_date)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
441 if args.last_modified is not None:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
442 checkprtable = True
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
443 daterange_constraint(prq, "PRs.last_modified",
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
444 args.last_modified)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
445 if args.release is not None:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
446 checkprtable = True
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
447 regexp_constraint(prq, "PRs.release", args.release)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
448 if args.environment is not None:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
449 checkprtable = True
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
450 regexp_constraint(prq, "PRs.environment", args.environment)
33
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
451
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
452 if args.originator_name is not None or \
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
453 args.originator_email is not None:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
454 prq.addtable("usermail as originator")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
455 prq.constrain("PRs.originator = originator.id")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
456 if args.originator_name is not None:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
457 checkprtable = True
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
458 regexp_constraint(prq, "originator.realname",
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
459 args.originator_name)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
460 if args.originator_email is not None:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
461 checkprtable = True
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
462 regexp_constraint(prq, "originator.email",
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
463 args.originator_name)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
464 if args.originator_id is not None:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
465 checkprtable = True
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
466 intrange_constraint(prq, "PRs.originator", args.originator_id)
33
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
467
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
468 queries = []
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
469 if checkprtable:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
470 queries.append(prq)
33
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
471
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
472 if args.responsible is not None:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
473 sq = Query()
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
474 sq.select("subscriptions.pr as id")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
475 sq.addtable("subscriptions")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
476 sq.addtable("users")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
477 sq.constrain("subscriptions.userid = users.id")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
478 regexp_constraint(sq, "users.realname", args.responsible)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
479 sq.constrain("subscriptions.responsible")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
480 queries.append(sq)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
481 if args.respondent is not None:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
482 sq = Query()
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
483 sq.select("subscriptions.pr as id")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
484 sq.addtable("subscriptions")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
485 sq.addtable("users as subscribed")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
486 sq.constrain("subscriptions.userid = users.id")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
487 regexp_constraint(sq, "users.realname", args.respondent)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
488 sq.constrain("subscriptions.reporter")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
489 queries.append(sq)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
490 if args.subscribed is not None:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
491 sq = Query()
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
492 sq.select("subscriptions.pr as id")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
493 sq.addtable("subscriptions")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
494 sq.addtable("users as subscribed")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
495 sq.constrain("subscriptions.userid = users.id")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
496 regexp_constraint(sq, "users.realname", args.subscribed)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
497 queries.append(sq)
33
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
498
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
499 if args.messages is not None:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
500 mq = Query()
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
501 mq.select("messages.pr as id")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
502 mq.addtable("messages")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
503 regexp_constraint(sq, "messages.text", args.messages)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
504 queries.append(mq)
33
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
505
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
506 if args.adminlog is not None:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
507 aq = Query()
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
508 aq.select("adminlog.pr as id")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
509 aq.addtable("adminlog")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
510 regexp_constraint(sq, "adminlog.change", args.adminlog)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
511 regexp_constraint(sq, "adminlog.comment", args.adminlog)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
512 assert(len(aq.constraints) == 2)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
513 x = "%s OR %s" % (aq.constraints[0], aq.constraints[1])
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
514 aq.constraints = [x]
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
515 queries.append(aq)
33
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
516
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
517 if args.anytext is not None:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
518 choke("--anytext isn't supported yet")
33
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
519
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
520 for scheme in classification_schemes:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
521 if args[scheme] is not None:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
522 schemetype = classification_schemetypes[scheme]
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
523 tbl = "%sclass_data" % schemetype
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
524 cq = Query()
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
525 cq.select("scheme.pr as id")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
526 cq.addtable("%s as scheme" % schemetype)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
527 cq.constrain("scheme.scheme = '%s'" % scheme)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
528 regexp_constraint(cq, "scheme.value", args[scheme])
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
529 queries.append(cq)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
530 # end loop
33
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
531
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
532 querytexts = [q.textify() for q in queries]
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
533 return "INTERSECT\n".join(querytexts)
46
73e6dac29391 new stuff (checkpoint when moved between machines)
David A. Holland
parents: 33
diff changeset
534
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
535 ############################################################
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
536 # printing
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
537
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
538 class PrintText:
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
539 def __init__(self, output):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
540 self.lines = (output == "RAW" or output == "LIST")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
541 def printheader(self, row):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
542 # nothing
48
3d5adf5a59d0 Fix python2.7 syntax errors.
David A. Holland
parents: 47
diff changeset
543 pass
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
544 def printrow(self, row):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
545 # XXX
51
ef6d572c4e1e switch to python3 style print()
David A. Holland
parents: 50
diff changeset
546 print(row)
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
547 def printfooter(self, row):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
548 # nothing
48
3d5adf5a59d0 Fix python2.7 syntax errors.
David A. Holland
parents: 47
diff changeset
549 pass
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
550 # end class PrintText
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
551
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
552 class PrintCsv:
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
553 def __init__(self, output):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
554 # nothing
48
3d5adf5a59d0 Fix python2.7 syntax errors.
David A. Holland
parents: 47
diff changeset
555 pass
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
556 def printheader(self, row):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
557 # XXX
48
3d5adf5a59d0 Fix python2.7 syntax errors.
David A. Holland
parents: 47
diff changeset
558 pass
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
559 def printrow(self, row):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
560 # XXX
48
3d5adf5a59d0 Fix python2.7 syntax errors.
David A. Holland
parents: 47
diff changeset
561 pass
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
562 def printfooter(self, row):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
563 # nothing
48
3d5adf5a59d0 Fix python2.7 syntax errors.
David A. Holland
parents: 47
diff changeset
564 pass
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
565 # end class PrintCsv
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
566
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
567 class PrintXml:
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
568 def __init__(self, output):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
569 # nothing
48
3d5adf5a59d0 Fix python2.7 syntax errors.
David A. Holland
parents: 47
diff changeset
570 pass
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
571 def printheader(self, row):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
572 # XXX
48
3d5adf5a59d0 Fix python2.7 syntax errors.
David A. Holland
parents: 47
diff changeset
573 pass
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
574 def printrow(self, row):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
575 # XXX
48
3d5adf5a59d0 Fix python2.7 syntax errors.
David A. Holland
parents: 47
diff changeset
576 pass
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
577 def printfooter(self, row):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
578 # XXX
48
3d5adf5a59d0 Fix python2.7 syntax errors.
David A. Holland
parents: 47
diff changeset
579 pass
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
580 # end class PrintXml
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
581
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
582 class PrintJson:
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
583 def __init__(self, output):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
584 # nothing
48
3d5adf5a59d0 Fix python2.7 syntax errors.
David A. Holland
parents: 47
diff changeset
585 pass
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
586 def printheader(self, row):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
587 # XXX
48
3d5adf5a59d0 Fix python2.7 syntax errors.
David A. Holland
parents: 47
diff changeset
588 pass
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
589 def printrow(self, row):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
590 # XXX
48
3d5adf5a59d0 Fix python2.7 syntax errors.
David A. Holland
parents: 47
diff changeset
591 pass
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
592 def printfooter(self, row):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
593 # XXX
48
3d5adf5a59d0 Fix python2.7 syntax errors.
David A. Holland
parents: 47
diff changeset
594 pass
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
595 # end class PrintJson
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
596
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
597 class PrintRdf:
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
598 def __init__(self, output):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
599 # nothing
48
3d5adf5a59d0 Fix python2.7 syntax errors.
David A. Holland
parents: 47
diff changeset
600 pass
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
601 def printheader(self, row):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
602 # XXX
48
3d5adf5a59d0 Fix python2.7 syntax errors.
David A. Holland
parents: 47
diff changeset
603 pass
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
604 def printrow(self, row):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
605 # XXX
48
3d5adf5a59d0 Fix python2.7 syntax errors.
David A. Holland
parents: 47
diff changeset
606 pass
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
607 def printfooter(self, row):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
608 # XXX
48
3d5adf5a59d0 Fix python2.7 syntax errors.
David A. Holland
parents: 47
diff changeset
609 pass
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
610 # end class PrintRdf
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
611
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
612 class PrintRdflike:
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
613 def __init__(self, output):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
614 # nothing
48
3d5adf5a59d0 Fix python2.7 syntax errors.
David A. Holland
parents: 47
diff changeset
615 pass
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
616 def printheader(self, row):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
617 # XXX
48
3d5adf5a59d0 Fix python2.7 syntax errors.
David A. Holland
parents: 47
diff changeset
618 pass
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
619 def printrow(self, row):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
620 # XXX
48
3d5adf5a59d0 Fix python2.7 syntax errors.
David A. Holland
parents: 47
diff changeset
621 pass
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
622 def printfooter(self, row):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
623 # XXX
48
3d5adf5a59d0 Fix python2.7 syntax errors.
David A. Holland
parents: 47
diff changeset
624 pass
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
625 # end class PrintRdflike
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
626
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
627 def print_prs(ids):
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
628 if sel.outformat == "TEXT":
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
629 mkprinter = PrintText
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
630 elif sel.outformat == "CSV":
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
631 mkprinter = PrintCsv
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
632 elif sel.outformat == "XML":
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
633 mkprinter = PrintXml
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
634 elif sel.outformat == "JSON":
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
635 mkprinter = PrintJson
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
636 elif sel.outformat == "RDF":
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
637 mkprinter = PrintRdf
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
638 elif sel.outformat == "RDFLIKE":
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
639 mkprinter = PrintRdflike
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
640 else:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
641 assert(False)
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
642
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
643 # reset the printer
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
644 printer = mkprinter(sel.output)
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
645
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
646 if sel.output == "RAW":
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
647 printer.printheader(ids[0])
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
648 for id in ids:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
649 printer(id)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
650 printer.printfooter(ids[0])
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
651 return
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
652 elif sel.output == "LIST":
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
653 # XXX is there a clean way to do this passing the
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
654 # whole list of ids at once?
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
655 query = "SELECT id, synopsis\n" + \
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
656 "FROM PRs\n" + \
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
657 "WHERE id = $1"
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
658 elif sel.output == "HEADERS":
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
659 query = None # XXX
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
660 elif sel.output == "META":
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
661 query = None # XXX
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
662 elif sel.output == "FULL":
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
663 query = None # XXX
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
664 else:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
665 assert(False)
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
666
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
667 first = True
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
668 for id in ids:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
669 results = querydb(query, [id])
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
670 if first:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
671 printer.printheader(results[0])
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
672 first = False
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
673 for r in results:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
674 printer.printrow(r)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
675 printer.printfooter(results[0])
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
676 # end print_prs
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
677
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
678 # XXX if in public mode we need to check if the PR is public
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
679 def print_message(pr, msgnum):
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
680 query = "SELECT users.username AS username,\n" + \
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
681 " users.realname AS realname,\n" + \
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
682 " messages.id AS id, parent_id,\n" + \
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
683 " posttime, mimetype, body\n" + \
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
684 "FROM messages, users\n" + \
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
685 "WHERE messages.who = users.id\n" + \
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
686 " AND messages.pr = $1\n" + \
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
687 " AND messages.number_in_pr = $2\n"
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
688 # Note that while pr is safe, msgnum came from the commandline
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
689 # and may not be.
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
690 results = querydb(query, [pr, msgnum])
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
691 [result] = results
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
692 (username, realname, id, parent_id, posttime, mimetype, body) = result
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
693 # XXX honor mimetype
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
694 # XXX honor output format (e.g. html)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
695 sys.stdout.write("From swallowtail@%s %s\n" % (organization,posttime))
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
696 sys.stdout.write("From: %s (%s)\n" % (username, realname))
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
697 sys.stdout.write("References: %s\n" % parent_id)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
698 sys.stdout.write("Date: %s\n" % posttime)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
699 sys.stdout.write("Content-Type: %s\n" % mimetype)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
700 sys.stdout.write("\n")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
701 sys.stdout.write(body)
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
702 # end print_message
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
703
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
704 # XXX if in public mode we need to check if the PR is public
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
705 def print_attachment(pr, attachnum):
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
706 query = "SELECT a.mimetype as mimetype, a.body as body\n" + \
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
707 "FROM messages, attachments as a\n" + \
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
708 "WHERE messages.pr = $1\n" + \
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
709 " AND messages.id = a.msgid\n" + \
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
710 " AND a.number_in_pr = $2\n"
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
711 # Note that while pr is safe, attachnum came from the
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
712 # commandline and may not be.
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
713 results = querydb(query, [pr, msgnum])
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
714 [result] = results
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
715 (mimetype, body) = result
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
716 # XXX honor mimetype
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
717 # XXX need an http output mode so we can send the mimetype!
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
718 sys.stdout.write(body)
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
719 # end print_attachment
46
73e6dac29391 new stuff (checkpoint when moved between machines)
David A. Holland
parents: 33
diff changeset
720
73e6dac29391 new stuff (checkpoint when moved between machines)
David A. Holland
parents: 33
diff changeset
721 ############################################################
52
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
722 # AST for input query
46
73e6dac29391 new stuff (checkpoint when moved between machines)
David A. Holland
parents: 33
diff changeset
723
73e6dac29391 new stuff (checkpoint when moved between machines)
David A. Holland
parents: 33
diff changeset
724 class Invocation:
52
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
725 Q_TERM = 1
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
726 Q_SQL = 2
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
727 class Query:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
728 def __init__(self, type):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
729 self.type = type
52
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
730 def dump(self, d):
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
731 if self.type == Invocation.Q_TERM:
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
732 d.write("query.term({})".format(self.term))
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
733 else:
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
734 d.write("query.sql({})".format(self.sql))
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
735 def mkterm(term):
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
736 self = Invocation.Query(Invocation.Q_TERM)
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
737 self.term = term
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
738 return self
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
739 def mksql(s):
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
740 self = Invocation.Query(Invocation.Q_SQL)
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
741 self.sql = s
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
742 return self
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
743
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
744 class Order:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
745 def __init__(self, field, rev = False):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
746 self.field = field
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
747 self.rev = rev
52
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
748 def dump(self, d):
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
749 d.write("order({}, {})".format(self.field, self.rev))
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
750 def mkoldest():
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
751 return Invocation.Order("number")
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
752 def mknewest():
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
753 return Invocation.Order("number", True)
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
754 def mkstaleness():
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
755 return Invocation.Order("modified_date", True)
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
756 def mkfield(field):
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
757 return Invocation.Order(field)
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
758 def mkrevfield(field):
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
759 return Invocation.Order(field, True)
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
760
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
761 class Search:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
762 def __init__(self, qs, openonly, publiconly, os):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
763 self.queries = qs
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
764 self.openonly = openonly
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
765 self.publiconly = publiconly
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
766 self.orders = os
52
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
767 def dump(self, d):
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
768 d.write("search({}, {})".format(
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
769 "open" if self.openonly else "closed",
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
770 "public" if self.publiconly else "privileged"))
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
771 d.indent()
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
772 d.write("queries")
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
773 d.indent()
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
774 for query in self.queries:
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
775 query.dump(d)
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
776 d.unindent()
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
777 d.write("orders")
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
778 d.indent()
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
779 for order in self.orders:
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
780 order.dump(d)
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
781 d.unindent()
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
782 d.unindent()
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
783
52
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
784 S_PR = 1
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
785 S_MESSAGE = 2
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
786 S_ATTACHMENT = 3
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
787 class Selection:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
788 def __init__(self, type):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
789 self.type = type
52
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
790 def dump(self, d):
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
791 if self.type == Invocation.S_PR:
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
792 d.write("selection.pr({}, {})".format(
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
793 self.output, self.outformat))
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
794 elif self.type == Invocation.S_MESSAGE:
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
795 d.write("selection.message({})".format(
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
796 self.message))
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
797 else:
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
798 d.write("selection.attachment({})".format(
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
799 self.attachment))
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
800 def mkpr(output, outformat):
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
801 self = Invocation.Selection(Invocation.S_PR)
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
802 self.output = output
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
803 self.outformat = outformat
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
804 return self
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
805 def mkmessage(arg):
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
806 self = Invocation.Selection(Invocation.S_MESSAGE)
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
807 self.message = arg
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
808 return self
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
809 def mkattachment(arg):
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
810 self = Invocation.Selection(Invocation.S_ATTACHMENT)
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
811 self.attachment = arg
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
812 return self
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
813
52
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
814 OP_FIELDS = 1
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
815 OP_SHOW = 2
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
816 OP_RANGE = 3
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
817 OP_SEARCH = 4
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
818 class Op:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
819 def __init__(self, type):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
820 self.type = type
52
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
821 def dump(self, d):
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
822 if self.type == Invocation.OP_FIELDS:
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
823 d.write("op.fields")
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
824 elif self.type == Invocation.OP_SHOW:
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
825 d.write("op.show({})".format(self.field))
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
826 elif self.type == Invocation.OP_RANGE:
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
827 d.write("op.range({})".format(self.field))
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
828 else:
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
829 d.write("op.search:")
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
830 d.indent()
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
831 self.search.dump(d)
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
832 for sel in self.sels:
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
833 sel.dump(d)
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
834 d.unindent()
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
835 def mkfields():
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
836 return Invocation.Op(Invocation.OP_FIELDS)
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
837 def mkshow(field):
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
838 self = Invocation.Op(Invocation.OP_SHOW)
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
839 self.field = field
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
840 return self
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
841 def mkrange(field):
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
842 self = Invocation.Op(Invocation.OP_RANGE)
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
843 self.field = field
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
844 return self
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
845 def mksearch(s, sels):
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
846 self = Invocation.Op(Invocation.OP_SEARCH)
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
847 self.search = s
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
848 self.sels = sels
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
849 return self
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
850
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
851 def __init__(self, ops):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
852 self.ops = ops
52
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
853 def dump(self, d):
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
854 d.write("invocation: {} ops".format(len(self.ops)))
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
855 d.indent()
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
856 for op in self.ops:
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
857 op.dump(d)
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
858 d.unindent()
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
859 # end class Invocation
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
860
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
861 ############################################################
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
862 # run (eval the SQL and print the results)
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
863
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
864 def run_sel(sel, ids):
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
865 if sel.type == S_PR:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
866 if ids == []:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
867 sys.stderr.write("No PRs matched.\n")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
868 exit(1)
46
73e6dac29391 new stuff (checkpoint when moved between machines)
David A. Holland
parents: 33
diff changeset
869
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
870 print_prs(ids)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
871 elif sel.type == S_MESSAGE:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
872 if len(ids) != 1:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
873 sys.stderr.write("Cannot retrieve messages " +
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
874 "from multiple PRs.")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
875 exit(1)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
876 print_message(ids[0], sel.message)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
877 elif sel.type == S_ATTACHMENT:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
878 if len(ids) != 1:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
879 sys.stderr.write("Cannot retrieve attachments " +
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
880 "from multiple PRs.")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
881 exit(1)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
882 print_message(ids[0], sel.attachment)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
883 else:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
884 assert(False)
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
885
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
886 def run_op(op):
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
887 if op.type == OP_FIELDS:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
888 list_fields()
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
889 elif op.type == OP_SHOW:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
890 describe_field(op.field)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
891 elif op.type == OP_RANGE:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
892 print_field_range(op.field)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
893 elif op.type == OP_SEARCH:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
894 sql = op.search
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
895 args = op.args # XXX not there!
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
896 ids = querydb(op.search, args)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
897 for s in op.sels:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
898 run_sel(s, ids)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
899 else:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
900 assert(False)
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
901
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
902 def run(ast):
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
903 for op in ast.ops:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
904 run_op(op)
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
905
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
906 ############################################################
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
907 # compile (convert the AST so the searches are pure SQL)
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
908
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
909 #
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
910 # XXX this doesn't work, we need to keep the interned strings
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
911 # on return from compile_query.
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
912 #
46
73e6dac29391 new stuff (checkpoint when moved between machines)
David A. Holland
parents: 33
diff changeset
913
48
3d5adf5a59d0 Fix python2.7 syntax errors.
David A. Holland
parents: 47
diff changeset
914 def matches(s, rx):
3d5adf5a59d0 Fix python2.7 syntax errors.
David A. Holland
parents: 47
diff changeset
915 # XXX
3d5adf5a59d0 Fix python2.7 syntax errors.
David A. Holland
parents: 47
diff changeset
916 return True
3d5adf5a59d0 Fix python2.7 syntax errors.
David A. Holland
parents: 47
diff changeset
917
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
918 def compile_query(q):
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
919 if q.type == Q_QSTRING:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
920 # XXX should use a split that honors quotes
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
921 terms = q.string.split()
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
922 terms = [dotstring(t) for t in terms]
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
923 return compile_query(doand(terms))
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
924 if q.type == Q_TSTRING:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
925 qb = QueryBuilder()
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
926 s = q.string
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
927 if matches(s, "^[0-9]+$"):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
928 f = qb.getfield("number")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
929 # Note: s is user-supplied but clean to insert directly
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
930 qb.addwhere("%s = %s" % (f, s))
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
931 elif matches(s, "^[0-9]+-[0-9]+$"):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
932 f = qb.getfield("number")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
933 ss = s.split("-")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
934 # Note: ss[] is user-supplied but clean
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
935 qb.addwhere("%s >= %s" % (f, ss[0]))
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
936 qb.addwhere("%s <= %s" % (f, ss[1]))
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
937 elif matches(s, "^[0-9]+-$"):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
938 f = qb.getfield("number")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
939 ss = s.split("-")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
940 # Note: ss[] is user-supplied but clean
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
941 qb.addwhere("%s >= %s" % (f, ss[0]))
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
942 elif matches(s, "^-[0-9]+$"):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
943 f = qb.getfield("number")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
944 ss = s.split("-")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
945 # Note: ss[] is user-supplied but clean
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
946 qb.addwhere("%s <= %s" % (f, ss[1]))
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
947 elif matches(s, "^[^:]+:[^:]+$"):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
948 # XXX honor quoted terms
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
949 # XXX = or LIKE?
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
950 ss = s.split(":")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
951 # ss[0] is not clean but if it's crap it won't match
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
952 f = qb.getfield(ss[0])
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
953 # ss[1] is not clean, so intern it for safety
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
954 s = qb.intern(ss[1])
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
955 qb.addwhere("%s = %s" % (f, s))
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
956 elif matches(s, "^-[^:]+:[^:]+$"):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
957 # XXX honor quoted terms
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
958 # XXX <> or NOT LIKE?
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
959 ss = s.split(":")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
960 # ss[0] is not clean but if it's crap it won't match
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
961 f = qb.getfield(ss[0])
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
962 # ss[1] is not clean, so intern it for safety
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
963 s = qb.intern(ss[1])
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
964 qb.addwhere("%s <> %s" % (f, s))
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
965 elif matches(s, "^-"):
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
966 # XXX <> or NOT LIKE?
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
967 f = qb.getfield("alltext")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
968 # s is not clean, so intern it for safety
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
969 s = qb.intern(s)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
970 qb.addwhere("%s <> %s" % (f, s))
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
971 else:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
972 # XXX = or LIKE?
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
973 f = qb.getfield("alltext")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
974 # s is not clean, so intern it for safety
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
975 s = qb.intern(s)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
976 qb.addwhere("%s = %s" % (f, s))
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
977
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
978 # XXX also does not handle:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
979 #
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
980 # field: with no string (supposed to use a default
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
981 # search string)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
982 #
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
983 # generated search fields that parse dates:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
984 # {arrived,closed,modified,etc.}-{before,after}:date
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
985 #
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
986 # stale:time
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
987
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
988 return qb.build("PRs.id")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
989 # end Q_TSTRING case
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
990 if q.type == Q_OR:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
991 subqueries = ["(" + compile_query(sq) + ")" for sq in q.args]
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
992 return " UNION ".join(subqueries)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
993 if q.type == Q_AND:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
994 subqueries = ["(" + compile_query(sq) + ")" for sq in q.args]
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
995 return " INTERSECT ".join(subqueries)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
996 if q.type == Q_SQL:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
997 return q.sql
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
998 assert(False)
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
999 # end compile_query
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
1000
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
1001 def compile_order(qb, o):
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
1002 str = qb.getfield(o.field)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
1003 if o.rev:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
1004 str = str + " DESCENDING"
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
1005 return str
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
1006
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
1007 def compile_search(s):
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
1008 qb2 = QueryBuilder()
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
1009
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
1010 # multiple query strings are treated as OR
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
1011 query = door(s.queries)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
1012 query = compile_query(q)
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
1013
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
1014 if s.openonly:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
1015 qb2.addwhere("not %s" % qb.getfield("closed"))
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
1016 if s.publiconly:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
1017 qb2.addwhere("not %s" % qb.getfield("confidential"))
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
1018
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
1019 orders = [compile_order(qb2, o) for o in s.orders]
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
1020 order = ", ".join(orders)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
1021 if order != "":
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
1022 qb2.setorder(order)
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
1023
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
1024 if qb2.nonempty():
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
1025 qb2.addjoin(query, "search")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
1026 qb2.addjoin("PRs")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
1027 qb2.addwhere("search = PRs.id")
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
1028 query = qb2.build(["search"])
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
1029
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
1030 return query
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
1031 # end compile_search
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
1032
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
1033 def compile_op(op):
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
1034 if op.type == OP_SEARCH:
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
1035 op.search = compile_search(op.search)
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
1036 return op
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
1037
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
1038 def compile(ast):
50
bb0ece71355e Untabify.
David A. Holland
parents: 49
diff changeset
1039 ast.ops = [compile_op(op) for op in ast.ops]
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
1040
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
1041 ############################################################
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
1042 # arg handling
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
1043
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
1044 #
52
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1045 # I swear, all getopt interfaces suck. You have to write your own to
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1046 # not go mad.
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
1047 #
46
73e6dac29391 new stuff (checkpoint when moved between machines)
David A. Holland
parents: 33
diff changeset
1048
52
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1049 # Usage.
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1050 def usage():
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1051 sys.stderr.write("""
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1052 query-pr: search for and retrieve problem reports
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1053 usage: query-pr [options] [searchterms] Query the database.
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1054 query-pr [options] --sql QUERY Execute QUERY as the search.
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1055 query-pr [options] -s QUERY Same as --sql.
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1056 query-pr --fields List database fields.
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1057 query-pr --show FIELD Print info about database field.
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1058 query-pr --range FIELD Print extant range for database field.
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1059 query-pr --help / -h Print this message.
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1060 query-pr --version / -v Print version and exit.
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1061 options:
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1062 --search-string STRING Forcibly treat STRING as a search term.
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1063 --message NUM / -m NUM Print a message by its ID number.
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1064 --attachment NUM / -a NUM Print an attachment by its ID number.
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1065 --paranoid Deny unsafe settings.
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1066 filter options:
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1067 --open Exclude closed PRs. (default)
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1068 --closed Include closed PRs.
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1069 --public Exclude confidential PRs.
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1070 --privileged Include confidential PRs. (default)
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1071 sort options:
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1072 --oldest Sort with oldest PRs first. (default)
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1073 --newest Sort with newest PRs first.
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1074 --staleness Sort by last modification time.
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1075 --orderby FIELD Sort by specific field.
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1076 output options:
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1077 --raw / -r Print raw SQL output.
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1078 --list / -l Print in list form.
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1079 --headers Print headers only.
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1080 --meta / --metadata Print all metadata.
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1081 --full / -f Print entire PR.
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1082 --text Print text. (default)
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1083 --csv Print CSV.
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1084 --xml Print XML.
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1085 --json Print JSON.
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1086 --rdf Print RDF.
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1087 --rdflike Print RDF-like text.
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1088 search terms:
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1089 NUM Single PR by number.
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1090 NUM-[NUM] Range of PRs by number.
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1091 TEXT Search string
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1092 FIELD:TEXT Search string for a particular field.
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1093 FIELD: Use the field's default search string.
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1094 derived fields:
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1095 arrived-before:DATE Arrival date before DATE.
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1096 arrived-after:DATE Arrival date after DATE.
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1097 closed-before:DATE Close date before DATE.
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1098 closed-after:DATE Close date after DATE, or none.
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1099 last-modified-before:DATE Last modified before DATE.
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1100 last-modified-after:DATE Last modified after DATE.
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1101 stale:TIME Last modified at least TIME ago.
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1102 Explicit SQL queries should return lists of PR numbers (only).
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1103 """)
46
73e6dac29391 new stuff (checkpoint when moved between machines)
David A. Holland
parents: 33
diff changeset
1104
52
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1105 # Widget to hold argv and allow peeling args off one at a time.
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1106 class ArgHolder:
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1107 def __init__(self, argv):
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1108 self.argc = len(argv)
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1109 self.argv = argv
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1110 self.pos = 1
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1111 def next(self):
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1112 if self.pos >= self.argc:
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1113 return None
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1114 ret = self.argv[self.pos]
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1115 self.pos += 1
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1116 return ret
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1117 def getarg(self, opt):
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1118 ret = self.next()
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1119 if ret is None:
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1120 msg = "Option {} requires an argument\n".format(opt)
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1121 sys.stderr.write(msg)
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1122 exit(1)
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1123 return ret
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1124
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1125 # Read the argument list and convert it into an Invocation.
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1126 def getargs(argv):
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1127 # Results
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1128 ops = []
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1129 orders = []
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1130 queries = []
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1131 selections = []
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1132 output = "LIST"
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1133 outformat = "TEXT"
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1134 openonly = True
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1135 publiconly = False
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1136 paranoid = False
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1137 nomoreoptions = False
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1138
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1139 #
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1140 # Functions for the options
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1141 #
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1142
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1143 def do_paranoid():
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1144 nonlocal paranoid, publiconly
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1145 paranoid = True
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1146 publiconly = True
46
73e6dac29391 new stuff (checkpoint when moved between machines)
David A. Holland
parents: 33
diff changeset
1147
52
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1148 def do_help():
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1149 usage()
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1150 exit(0)
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1151 def do_version():
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1152 msg = "query-pr {}\n".format(program_version)
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1153 sys.stdout.write(msg)
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1154 exit(0)
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1155 def do_fields():
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1156 ops.append(Invocation.mkfields())
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1157 def do_show(field):
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1158 ops.append(Invocation.mkshow(field))
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1159 def do_range(field):
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1160 ops.append(Invocation.mkrange(field))
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1161
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1162 def do_search(term):
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1163 queries.append(Invocation.mkterm(term))
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1164 def do_sql(text):
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1165 assert(not paranoid)
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1166 queries.append(Invocation.mksql(text))
46
73e6dac29391 new stuff (checkpoint when moved between machines)
David A. Holland
parents: 33
diff changeset
1167
52
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1168 def do_open():
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1169 nonlocal openonly
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1170 openonly = True
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1171 def do_closed():
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1172 nonlocal openonly
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1173 openonly = False
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1174 def do_public():
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1175 nonlocal publiconly
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1176 publiconly = True
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1177 def do_privileged():
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1178 nonlocal publiconly
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1179 assert(not paranoid)
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1180 publiconly = False
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1181
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1182 def do_oldest():
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1183 orders.append(Invocation.mkoldest())
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1184 def do_newest():
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1185 orders.append(Invocation.mknewest())
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1186 def do_staleness():
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1187 orders.append(Invocation.mkstaleness())
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1188 def do_orderby(field):
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1189 orders.append(Invocation.mkfield(field))
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1190 def do_revorderby(field):
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1191 orders.append(Invocation.mkrevfield(field))
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1192
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1193 def do_message(n):
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1194 selections.append(Invocation.mkmessage(n))
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1195 def do_attachment(n):
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1196 selections.append(Invocation.mkattachment(n))
46
73e6dac29391 new stuff (checkpoint when moved between machines)
David A. Holland
parents: 33
diff changeset
1197
52
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1198 def do_raw():
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1199 nonlocal output
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1200 output = "RAW"
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1201 def do_list():
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1202 nonlocal output
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1203 output = "LIST"
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1204 def do_headers():
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1205 nonlocal output
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1206 output = "HEADERS"
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1207 def do_meta():
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1208 nonlocal output
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1209 output = "META"
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1210 def do_full():
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1211 nonlocal output
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1212 output = "FULL"
46
73e6dac29391 new stuff (checkpoint when moved between machines)
David A. Holland
parents: 33
diff changeset
1213
52
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1214 def do_text():
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1215 nonlocal outformat
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1216 outformat = "TEXT"
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1217 def do_csv():
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1218 nonlocal outformat
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1219 outformat = "CSV"
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1220 def do_xml():
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1221 nonlocal outformat
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1222 outformat = "XML"
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1223 def do_json():
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1224 nonlocal outformat
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1225 outformat = "JSON"
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1226 def do_rdf():
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1227 nonlocal outformat
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1228 outformat = "RDF"
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1229 def do_rdflike():
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1230 nonlocal outformat
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1231 outformat = "RDFLIKE"
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1232
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1233 def do_unknown(opt):
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1234 sys.stderr.write("Unknown option {}\n".format(opt))
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1235 exit(1)
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1236
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1237 args = ArgHolder(argv)
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1238 while True:
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1239 arg = args.next()
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1240 if arg is None:
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1241 break
46
73e6dac29391 new stuff (checkpoint when moved between machines)
David A. Holland
parents: 33
diff changeset
1242
52
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1243 if nomoreoptions or arg[0] != "-":
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1244 do_search(arg)
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1245 elif arg == "--":
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1246 nomoreoptions = True
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1247 # Long options
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1248 elif arg == "--attachment":
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1249 do_attachment(args.getarg(arg))
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1250 elif arg.startswith("--attachment="):
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1251 do_message(arg[13:])
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1252 elif arg == "--closed":
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1253 do_closed()
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1254 elif arg == "--csv":
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1255 do_csv()
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1256 elif arg == "--fields":
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1257 do_fields()
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1258 elif arg == "--full":
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1259 do_full()
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1260 elif arg == "--headers":
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1261 do_headers()
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1262 elif arg == "--help":
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1263 do_help()
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1264 elif arg == "--json":
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1265 do_json()
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1266 elif arg == "--list":
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1267 do_list()
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1268 elif arg == "--message":
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1269 do_message(args.getarg(arg))
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1270 elif arg.startswith("--message="):
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1271 do_message(arg[10:])
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1272 elif arg == "--meta":
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1273 do_meta()
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1274 elif arg == "--metadata":
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1275 do_meta()
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1276 elif arg == "--newest":
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1277 do_newest()
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1278 elif arg == "--oldest":
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1279 do_oldest()
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1280 elif arg == "--orderby":
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1281 do_orderby(args.getarg(arg))
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1282 elif arg.startswith("--orderby="):
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1283 do_orderby(arg[10:])
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1284 elif arg == "--open":
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1285 do_open()
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1286 elif arg == "--paranoid":
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1287 do_paranoid()
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1288 elif arg == "--public":
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1289 do_public()
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1290 elif arg == "--privileged" and not paranoid:
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1291 do_privileged()
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1292 elif arg == "--range":
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1293 do_range(args.getarg(arg))
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1294 elif arg.startswith("--range="):
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1295 do_range(arg[8:])
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1296 elif arg == "--raw":
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1297 do_raw()
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1298 elif arg == "--rdf":
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1299 do_rdf()
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1300 elif arg == "--rdflike":
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1301 do_rdflike()
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1302 elif arg == "--revorderby":
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1303 do_revorderby(args.getarg(arg))
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1304 elif arg.startswith("--revorderby="):
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1305 do_revorderby(arg[13:])
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1306 elif arg == "--search":
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1307 do_search(args.getarg(arg))
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1308 elif arg.startswith("--search="):
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1309 do_search(arg[9:])
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1310 elif arg == "--show":
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1311 do_show(args.getarg(arg))
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1312 elif arg.startswith("--show="):
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1313 do_show(arg[7:])
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1314 elif arg == "--sql" and not paranoid:
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1315 do_sql(args.getarg(arg))
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1316 elif arg.startswith("--sql=") and not paranoid:
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1317 do_sql(arg[7:])
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1318 elif arg == "--staleness":
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1319 do_staleness()
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1320 elif arg == "--text":
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1321 do_text()
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1322 elif arg == "--version":
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1323 do_version()
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1324 elif arg == "--xml":
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1325 do_xml()
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1326 elif arg.startswith("--"):
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1327 do_unknown(arg)
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1328 else:
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1329 # short options
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1330 i = 1
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1331 n = len(arg)
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1332 while i < n:
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1333 opt = arg[i]
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1334 i += 1
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1335 def getarg():
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1336 nonlocal i
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1337 if i < n:
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1338 ret = arg[i:]
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1339 else:
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1340 ret = args.getarg("-" + opt)
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1341 i = n
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1342 return ret
46
73e6dac29391 new stuff (checkpoint when moved between machines)
David A. Holland
parents: 33
diff changeset
1343
52
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1344 if opt == "a":
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1345 do_attachment(getarg())
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1346 elif opt == "f":
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1347 do_full()
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1348 elif opt == "h":
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1349 do_help()
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1350 elif opt == "l":
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1351 do_list()
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1352 elif opt == "m":
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1353 do_message(getarg())
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1354 elif opt == "s" and not paranoid:
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1355 do_sql(getarg())
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1356 elif opt == "r":
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1357 do_raw()
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1358 elif opt == "v":
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1359 do_version()
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1360 else:
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1361 do_unknown("-" + opt)
46
73e6dac29391 new stuff (checkpoint when moved between machines)
David A. Holland
parents: 33
diff changeset
1362
52
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1363 # Now convert what we got to a single thing.
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1364 if queries != []:
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1365 if orders == []:
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1366 orders = [Invocation.mkoldest()]
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1367 if selections == []:
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1368 selections = [Invocation.mkpr(output, outformat)]
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1369 search = Invocation.Search(queries, openonly, publiconly, orders)
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1370 ops.append(Invocation.mksearch(search, selections))
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1371 else:
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1372 if orders != []:
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1373 msg = "No queries given for requested orderings\n"
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1374 sys.stderr.write(msg)
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1375 exit(1)
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1376 if selections != []:
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1377 msg = "No queries given for requested selections\n"
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1378 sys.stderr.write(msg)
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1379 exit(1)
46
73e6dac29391 new stuff (checkpoint when moved between machines)
David A. Holland
parents: 33
diff changeset
1380
56
42d7888272a0 Implement fetch_classifications().
David A. Holland
parents: 55
diff changeset
1381 return (Invocation(ops), paranoid)
33
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
1382 # end getargs
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
1383
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
1384 ############################################################
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
1385 # main
298c8a7f5181 begin hacking
David A. Holland
parents: 7
diff changeset
1386
56
42d7888272a0 Implement fetch_classifications().
David A. Holland
parents: 55
diff changeset
1387 (todo, paranoid) = getargs(sys.argv)
52
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1388 #todo.dump(Dumper(sys.stdout))
c0be30249ffe Fix the argument handling.
David A. Holland
parents: 51
diff changeset
1389
56
42d7888272a0 Implement fetch_classifications().
David A. Holland
parents: 55
diff changeset
1390 opendb(paranoid)
47
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
1391 fetch_classifications()
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
1392 todo = compile(todo)
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
1393 run(todo)
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
1394 closedb()
bcd1d06838fd more better stuff
David A. Holland
parents: 46
diff changeset
1395 exit(0)
46
73e6dac29391 new stuff (checkpoint when moved between machines)
David A. Holland
parents: 33
diff changeset
1396