From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1Qo1Wr-0006Ta-Rt for garchives@archives.gentoo.org; Mon, 01 Aug 2011 23:04:11 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id BDE3521C0B0; Mon, 1 Aug 2011 23:04:02 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 7EC5021C0A0 for ; Mon, 1 Aug 2011 23:04:02 +0000 (UTC) Received: from pelican.gentoo.org (unknown [66.219.59.40]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id E43FF2AC001 for ; Mon, 1 Aug 2011 23:04:01 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id 13D123C004 for ; Mon, 1 Aug 2011 23:04:01 +0000 (UTC) From: "Vikraman Choudhury" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Vikraman Choudhury" Message-ID: Subject: [gentoo-commits] proj/gentoostats:master commit in: client/gentoostats/, client/ X-VCS-Repository: proj/gentoostats X-VCS-Files: client/gentoostats-cli client/gentoostats/search.py X-VCS-Directories: client/gentoostats/ client/ X-VCS-Committer: vikraman X-VCS-Committer-Name: Vikraman Choudhury X-VCS-Revision: a1a9949f57f294cd001d8589fdc727de9c19aae8 Date: Mon, 1 Aug 2011 23:04:01 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: X-Archives-Hash: 83a6e6831ad5338da5ee6c4c2839440f commit: a1a9949f57f294cd001d8589fdc727de9c19aae8 Author: Vikraman Choudhury gmail com> AuthorDate: Mon Aug 1 23:03:09 2011 +0000 Commit: Vikraman Choudhury gmail com> CommitDate: Mon Aug 1 23:03:09 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/gentoostats.g= it;a=3Dcommit;h=3Da1a9949f add search to gentoostats-cli --- client/gentoostats-cli | 4 ++-- client/gentoostats/search.py | 37 ++++++++++++++++++++++++++++++++++++= + 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 =20 from gentoostats import list -#from gentoostats import search +from gentoostats import search =20 def main(): parser =3D argparse.ArgumentParser() @@ -13,7 +13,7 @@ def main(): subparsers =3D parser.add_subparsers() =20 list.add_parser(subparsers) -# search.add_parser(subparsers) + search.add_parser(subparsers) =20 args =3D 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 =3D 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=3Dint) + search_parser.add_argument('--max_hosts', type=3Dint) + search_parser.set_defaults(func=3Dsearch) + +def search(args): + url_base =3D '/search' + url_extra =3D '' + + url_extra +=3D ('?', '&')[bool(url_extra)] + 'cat=3D' + args.categor= y if args.category else '' + url_extra +=3D ('?', '&')[bool(url_extra)] + 'pkg=3D' + args.package= if args.package else '' + url_extra +=3D ('?', '&')[bool(url_extra)] + 'ver=3D' + args.version= if args.version else '' + url_extra +=3D ('?', '&')[bool(url_extra)] + 'repo=3D' + args.repo i= f args.repo else '' + url_extra +=3D ('?', '&')[bool(url_extra)] + 'min_hosts=3D' + str(ar= gs.min_hosts) if args.min_hosts else '' + url_extra +=3D ('?', '&')[bool(url_extra)] + 'max_hosts=3D' + str(ar= gs.max_hosts) if args.max_hosts else '' + + print args.server + args.url + url_base + url_extra + + get_data =3D utils.GET(server =3D args.server, url =3D args.url + ur= l_base + url_extra, headers =3D utils.headers) + data =3D utils.deserialize(get_data) + + pprint ('Search results', data)