aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVikraman Choudhury <vikraman.choudhury@gmail.com>2011-08-02 04:33:09 +0530
committerVikraman Choudhury <vikraman.choudhury@gmail.com>2011-08-02 04:33:09 +0530
commita1a9949f57f294cd001d8589fdc727de9c19aae8 (patch)
treee0edf036bbd20fce999c08599dcc01ddbe9c0c86
parentreworked gentoostats-cli code (diff)
downloadgentoostats-a1a9949f57f294cd001d8589fdc727de9c19aae8.tar.gz
gentoostats-a1a9949f57f294cd001d8589fdc727de9c19aae8.tar.bz2
gentoostats-a1a9949f57f294cd001d8589fdc727de9c19aae8.zip
add search to gentoostats-cli
-rwxr-xr-xclient/gentoostats-cli4
-rw-r--r--client/gentoostats/search.py37
2 files changed, 39 insertions, 2 deletions
diff --git a/client/gentoostats-cli b/client/gentoostats-cli
index 6a237fc..a22ccc7 100755
--- a/client/gentoostats-cli
+++ b/client/gentoostats-cli
@@ -3,7 +3,7 @@
import argparse
from gentoostats import list
-#from gentoostats import search
+from gentoostats import search
def main():
parser = argparse.ArgumentParser()
@@ -13,7 +13,7 @@ def main():
subparsers = parser.add_subparsers()
list.add_parser(subparsers)
-# search.add_parser(subparsers)
+ search.add_parser(subparsers)
args = parser.parse_args()
args.func(args)
diff --git a/client/gentoostats/search.py b/client/gentoostats/search.py
new file mode 100644
index 0000000..165733e
--- /dev/null
+++ b/client/gentoostats/search.py
@@ -0,0 +1,37 @@
+
+import utils
+
+def pprint(title, object):
+ # TODO: write a custom pretty printer here
+ import pprint
+ print title
+ pprint.pprint(object)
+
+def add_parser(subparsers):
+ # TODO: add help and descriptions for all opts
+ search_parser = subparsers.add_parser('search')
+ search_parser.add_argument('-c', '--category')
+ search_parser.add_argument('-p', '--package')
+ search_parser.add_argument('-v', '--version')
+ search_parser.add_argument('-r', '--repo')
+ search_parser.add_argument('--min_hosts', type=int)
+ search_parser.add_argument('--max_hosts', type=int)
+ search_parser.set_defaults(func=search)
+
+def search(args):
+ url_base = '/search'
+ url_extra = ''
+
+ url_extra += ('?', '&')[bool(url_extra)] + 'cat=' + args.category if args.category else ''
+ url_extra += ('?', '&')[bool(url_extra)] + 'pkg=' + args.package if args.package else ''
+ url_extra += ('?', '&')[bool(url_extra)] + 'ver=' + args.version if args.version else ''
+ url_extra += ('?', '&')[bool(url_extra)] + 'repo=' + args.repo if args.repo else ''
+ url_extra += ('?', '&')[bool(url_extra)] + 'min_hosts=' + str(args.min_hosts) if args.min_hosts else ''
+ url_extra += ('?', '&')[bool(url_extra)] + 'max_hosts=' + str(args.max_hosts) if args.max_hosts else ''
+
+ print args.server + args.url + url_base + url_extra
+
+ get_data = utils.GET(server = args.server, url = args.url + url_base + url_extra, headers = utils.headers)
+ data = utils.deserialize(get_data)
+
+ pprint ('Search results', data)