annotate shelltools/query-pr/query.py @ 46:73e6dac29391

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