Mercurial > ~dholland > hg > swallowtail > index.cgi
changeset 46:73e6dac29391
new stuff (checkpoint when moved between machines)
author | David A. Holland |
---|---|
date | Tue, 12 Aug 2014 21:55:08 -0400 |
parents | 233dcc4d80e1 |
children | bcd1d06838fd |
files | shelltools/query-pr/query.py |
diffstat | 1 files changed, 223 insertions(+), 164 deletions(-) [+] |
line wrap: on
line diff
--- a/shelltools/query-pr/query.py Mon Jun 16 01:27:54 2014 -0400 +++ b/shelltools/query-pr/query.py Tue Aug 12 21:55:08 2014 -0400 @@ -51,9 +51,6 @@ # end querydb ############################################################ -# - -############################################################ # query class for searches class Query: @@ -112,167 +109,6 @@ # end daterange_constraint ############################################################ -# arg handling - -def getargs(classification_schemes, classification_schemetypes): - global outmaterial - global outformat - - p = argparse.ArgumentParser(program_description) - - # note: -h/--help is built in by default - p.add_argument("-v", "--version", - action='version' version=program_version, - help="Print program version and exit") - - p.add_argument("--short", - action='store_const', const="short", - dest='outmaterial', - help="Output in short form (one per line)") - p.add_argument("--headers", - action='store_const', const="headers", - dest='outmaterial', - help="Output in default form (headers only)") - p.add_argument("--full", - action='store_const', const="full", - dest='outmaterial', - help="Output in full form (all material)") - p.add_argument("--attach", nargs=1, - type=int, - action='store', - dest='attach', - help="Output specified attachment") - p.add_argument("--message", nargs=1, - type=int, - action='store', - dest='message', - help="Output specified message") - - p.add_argument("--text", - action='store_const', const="text", - dest='outformat', - help="Output as text (default)") - p.add_argument("--csv", - action='store_const', const="csv", - dest='outformat', - help="Output as comma-separated values") - p.add_argument("--xml", - action='store_const', const="xml", - dest='outformat', - help="Output as XML") - p.add_argument("--json", - action='store_const', const="json", - dest='outformat', - help="Output as JSON") - p.add_argument("--rdf", - action='store_const', const="rdf", - dest='outformat', - help="Output as RDF") - p.add_argument("--rdflike", - action='store_const', const="rdflike", - dest='outformat', - help="Output as RDF-like text") - - p.add_argument("--closed", - action='store_true', - dest='closed', default=False, - help="Search closed PRs as well as open") - p.add_argument("--public", - action='store_true', - dest='public', default=False, - help="Search only public information") - - p.add_argument("--number", nargs=1, - type=intrange, - dest='number', - help="Restrict search to a range of PRs by number") - p.add_argument("--synopsis", nargs=1, - dest='synopsis', - help="Search PRs by their synopsis field") - p.add_argument("--confidential", nargs=1, - type=yesno, choices=["yes", "no"], - dest='confidential', - help="Search PRs by their confidentiality setting") - p.add_argument("--state", nargs=1, - dest='state', - help="Search PRs by their state") - p.add_argument("--locked", nargs=1, - type=yesno, choices=["yes", "no"], - dest='locked', - help="Search PRs by their locked setting") - p.add_argument("--arrival-schemaversion", nargs=1, - type=intrange, - dest='arrival_schemaversion', - help="Search PRs by their original schema version") - p.add_argument("--arrival-date", nargs=1, - type=daterange, - dest='arrival_date', - help="Search PRs by arrival date") - p.add_argument("--closed-date", nargs=1, - type=daterange, - dest='closed_date', - help="Search PRs by the date they were closed") - p.add_argument("--last-modified", nargs=1, - type=daterange, - dest='last_modified', - help="Search PRs by the date they were last modified") - p.add_argument("--release", nargs=1, - dest='release', - help="Search PRs by their release information") - p.add_argument("--environment", nargs=1, - dest='environment', - help="Search PRs by their environment information") - - p.add_argument("--originator-name", nargs=1, - dest='originator_name', - help="Search PRs by the name of their originator") - p.add_argument("--originator-email", nargs=1, - dest='originator_email', - help="Search PRs by the email of their originator") - p.add_argument("--originator-id", nargs=1, - type=intrange, - dest='originator_id', - help="Search PRs by the database ID of their originator") - - - p.add_argument("--responsible", nargs=1, - dest='responsible', - help="Search PRs by who's responsible for them") - p.add_argument("--respondent", nargs=1, - dest='respondent', - help="Search PRs by who's a respondent") - p.add_argument("--subscribed", nargs=1, - dest='subscribed', - help="Search PRs by who's subscribed") - - p.add_argument("--messages", nargs=1, - dest='messages', - help="Search PRs by text in the message log") - p.add_argument("--adminlog", nargs=1, - dest='adminlog', - help="Search PRs by text in the administrative log") - p.add_argument("--anytext", nargs=1, - dest='anytext', - help="Search PRs by text in various fields") - - for scheme in classification_schemes: - p.add_argument("--%s" % scheme, nargs=1, - dest=scheme, - help="Search PRs by the %s classification scheme" % - scheme) - - p.add_argument("prs", nargs='*', metavar="PR", - type=int, - action='append', - dest='prs', - help="Specific PRs to retrieve by number") - - args = p.parse_args() - - if args.outmaterial is not None: - outmaterial = args.outmaterial - if args.outformat is not None: - outformat = args.outformat # If we're doing something other than a search, do it now if args.attach is not None: @@ -431,12 +267,235 @@ querytexts = [q.textify() for q in queries] return "INTERSECT\n".join(querytexts) + + +############################################################ +# arg handling + +class Invocation: + class Op: + # operation codes + OP_FIELDS = 1 + OP_SHOW = 2 + OP_RANGE = 3 + OP_SEARCH = 4 + + def __init__(self, op): + self.op = op + + def dofields(): + return Op(OP_FIELDS) + def doshow(field): + self = Op(OP_SHOW) + self.field = field + return self + def dorange(field): + self = Op(OP_RANGE) + self.field = field + return self + def doquery( + + + # output formats + FMT_TXT = 1 + + def __init__(self): + self.op = OP_SEARCH + self.searchstrings = [] + self.searchsql = [] + +# end Invocation + +def getargs(): + p = argparse.ArgumentParser(program_description) + + # note: -h/--help is built in by default + p.add_argument("-v", "--version", + action='version', version=program_version, + help="Print program version and exit") + + p.add_argument("--show", nargs=1, + action = 'store', dest='show', + help="Show description of field") + p.add_argument("--range", nargs=1, + action = 'store', dest='range', + help="Show range of extant values for field") + + p.add_argument("--search", nargs=1, + action = 'store', dest='search', + help="Force string to be read as a search string") + p.add_argument("-s", "--sql", nargs=1, + action = 'store', dest='sql', + help="Supply explicit sql query as search") + + p.add_argument("--open", + action = 'store_const', const="True", + dest = 'openonly', + help="Exclude closed PRs (default)") + p.add_argument("--closed", + action = 'store_const', const="False", + dest = 'openonly', + help="Include closed PRs in search") + p.add_argument("--public", + action = 'store_const', const="True", + dest = 'publiconly', + help="Exclude confidential PRs") + p.add_argument("--privileged", + action = 'store_const', const="False", + dest = 'publiconly', + help="Allow confidential PRs (default)") + + p.add_argument("--oldest", + action = 'store_const', const="OLDEST", + dest = 'order', + help="Sort output with oldest PRs first") + p.add_argument("--newest", + action = 'store_const', const="NEWEST", + dest = 'order', + help="Sort output with newest PRs first") + p.add_argument("--staleness", + action = 'store_const', const="STALENESS", + dest = 'order', + help="Sort output by time since last modification") + p.add_argument("--orderby", nargs=1, + action = 'store', dest = 'orderfield', + help="Sort output by specific field") + p.add_argument("--revorderby", nargs=1, + action = 'store', dest = 'revorderfield', + help="Sort output by specific field, reversed") + + p.add_argument("-m", "--message", nargs=1, + action = 'store', dest = 'message', + help="Print selected message (single PR only)") + p.add_argument("-a", "--attachment", nargs=1, + action = 'store', dest = 'attachment', + help="Print selected attachment (single PR only)") + + p.add_argument("-r", "--raw", + action = 'store_const', const="RAW", + dest = 'output', + help="Print exactly what the database returns") + p.add_argument("-l", "--list", + action = 'store_const', const="LIST", + dest = 'output', + help="Print in list form (default)") + p.add_argument("--headers", + action = 'store_const', const="HEADERS", + dest = 'output', + help="Print header information only") + p.add_argument("--meta", + action = 'store_const', const="META", + dest = 'output', + help="Print all metadata") + p.add_argument("--metadata", + action = 'store_const', const="META", + dest = 'output') + p.add_argument("-f", "--full", + action = 'store_const', const="FULL", + dest = 'output', + help="Print everything") + + p.add_argument("--text", + action = 'store_const', const="TEXT", + dest = 'outformat', + help="Print in text format (default)") + p.add_argument("--csv", + action = 'store_const', const="CSV", + dest = 'outformat', + help="Print a CSV file") + p.add_argument("--xml", + action = 'store_const', const="XML", + dest = 'outformat', + help="Print in XML") + p.add_argument("--json", + action = 'store_const', const="JSON", + dest = 'outformat', + help="Print in JSON") + p.add_argument("--rdf", + action = 'store_const', const="RDF", + dest = 'outbformat', + help="Print in RDF") + p.add_argument("--rdflike", + action = 'store_const', const="RDFLIKE", + dest = 'outformat', + help="Print RDF-like text") + + args = p.parse_args() + + p = Invocation() + + if args.show is not None: + do_showfield(args.show) + exit(0) + if args.range is not None: + do_fieldrange(args.range) + exit(0) + + searchstring = args.search + explicitsql = args.sql + + openonly = args.openonly + if openonly is None: + openonly = True + publiconly = args.publiconly + if publiconly is None: + publiconly = False + + if args.orderfield is not None: + orderby = args.orderfield + orderrev = False + elif args.revorderfield is not None: + orderby = args.revorderfield + orderrev = True + elif args.order == "OLDEST": + orderby = "number" + orderrev = False + elif args.order == "NEWEST": + orderby = "number" + orderrev = True + elif args.order == "STALENESS": + orderby = "last-modified" + orderrev = True + else: + orderby = "number" + orderrev = False + + if args.message is not None: + printwhat = "MESSAGE" + printwhich = args.message + elif args.attachment is not None: + printwhat = "ATTACHMENT" + printwhich = args.attachment + else: + printwhat = "PR" + printwhich = None + + output = args.output + if output is None: + output = "LIST" + + outformat = args.outformat + if outformat is None: + outformat = "TEXT" + + query = buildquery(searchstring, explicitsql, + orderby=orderby, orderrev=orderrev, + openonly=openonly, publiconly=publiconly) + if printwhat == "PR": + printer = buildprinter(output, outformat) + else if printwhat == "MESSAGE": + printer = getmessage(printwhich) + else if printwhat == "ATTACHMENT": + printer = getattachment(printwhich) + + return (query, printer) # end getargs ############################################################ # main def main(): + opendb() (classification_schemes, classification_schemetypes) = getclassify() query = getargs(classification_schemes, classification_schemetypes)