Gentoo Archives: gentoo-commits

From: Vikraman Choudhury <vikraman.choudhury@×××××.com>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/gentoostats:master commit in: client/gentoostats/, client/
Date: Mon, 01 Aug 2011 23:04:11
Message-Id: a1a9949f57f294cd001d8589fdc727de9c19aae8.vikraman@gentoo
1 commit: a1a9949f57f294cd001d8589fdc727de9c19aae8
2 Author: Vikraman Choudhury <vikraman.choudhury <AT> gmail <DOT> com>
3 AuthorDate: Mon Aug 1 23:03:09 2011 +0000
4 Commit: Vikraman Choudhury <vikraman.choudhury <AT> gmail <DOT> com>
5 CommitDate: Mon Aug 1 23:03:09 2011 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoostats.git;a=commit;h=a1a9949f
7
8 add search to gentoostats-cli
9
10 ---
11 client/gentoostats-cli | 4 ++--
12 client/gentoostats/search.py | 37 +++++++++++++++++++++++++++++++++++++
13 2 files changed, 39 insertions(+), 2 deletions(-)
14
15 diff --git a/client/gentoostats-cli b/client/gentoostats-cli
16 index 6a237fc..a22ccc7 100755
17 --- a/client/gentoostats-cli
18 +++ b/client/gentoostats-cli
19 @@ -3,7 +3,7 @@
20 import argparse
21
22 from gentoostats import list
23 -#from gentoostats import search
24 +from gentoostats import search
25
26 def main():
27 parser = argparse.ArgumentParser()
28 @@ -13,7 +13,7 @@ def main():
29 subparsers = parser.add_subparsers()
30
31 list.add_parser(subparsers)
32 -# search.add_parser(subparsers)
33 + search.add_parser(subparsers)
34
35 args = parser.parse_args()
36 args.func(args)
37
38 diff --git a/client/gentoostats/search.py b/client/gentoostats/search.py
39 new file mode 100644
40 index 0000000..165733e
41 --- /dev/null
42 +++ b/client/gentoostats/search.py
43 @@ -0,0 +1,37 @@
44 +
45 +import utils
46 +
47 +def pprint(title, object):
48 + # TODO: write a custom pretty printer here
49 + import pprint
50 + print title
51 + pprint.pprint(object)
52 +
53 +def add_parser(subparsers):
54 + # TODO: add help and descriptions for all opts
55 + search_parser = subparsers.add_parser('search')
56 + search_parser.add_argument('-c', '--category')
57 + search_parser.add_argument('-p', '--package')
58 + search_parser.add_argument('-v', '--version')
59 + search_parser.add_argument('-r', '--repo')
60 + search_parser.add_argument('--min_hosts', type=int)
61 + search_parser.add_argument('--max_hosts', type=int)
62 + search_parser.set_defaults(func=search)
63 +
64 +def search(args):
65 + url_base = '/search'
66 + url_extra = ''
67 +
68 + url_extra += ('?', '&')[bool(url_extra)] + 'cat=' + args.category if args.category else ''
69 + url_extra += ('?', '&')[bool(url_extra)] + 'pkg=' + args.package if args.package else ''
70 + url_extra += ('?', '&')[bool(url_extra)] + 'ver=' + args.version if args.version else ''
71 + url_extra += ('?', '&')[bool(url_extra)] + 'repo=' + args.repo if args.repo else ''
72 + url_extra += ('?', '&')[bool(url_extra)] + 'min_hosts=' + str(args.min_hosts) if args.min_hosts else ''
73 + url_extra += ('?', '&')[bool(url_extra)] + 'max_hosts=' + str(args.max_hosts) if args.max_hosts else ''
74 +
75 + print args.server + args.url + url_base + url_extra
76 +
77 + get_data = utils.GET(server = args.server, url = args.url + url_base + url_extra, headers = utils.headers)
78 + data = utils.deserialize(get_data)
79 +
80 + pprint ('Search results', data)