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 1QiZF1-0002Zs-Fc for garchives@archives.gentoo.org; Sun, 17 Jul 2011 21:51:11 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id E956F21C052; Sun, 17 Jul 2011 21:51:03 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id AAB2A21C052 for ; Sun, 17 Jul 2011 21:51:03 +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 080101B400A for ; Sun, 17 Jul 2011 21:51:03 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id 1F27C80038 for ; Sun, 17 Jul 2011 21:51:02 +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: <2dda88db0716efa9a42ab703a70a49533c2852b9.vikraman@gentoo> Subject: [gentoo-commits] proj/gentoostats:master commit in: server/, server/templates/ X-VCS-Repository: proj/gentoostats X-VCS-Files: server/app.py server/search.py server/templates/search.html X-VCS-Directories: server/ server/templates/ X-VCS-Committer: vikraman X-VCS-Committer-Name: Vikraman Choudhury X-VCS-Revision: 2dda88db0716efa9a42ab703a70a49533c2852b9 Date: Sun, 17 Jul 2011 21:51:02 +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: 509807fb2b34f4d8d803ecff83d98271 commit: 2dda88db0716efa9a42ab703a70a49533c2852b9 Author: Vikraman Choudhury gmail com> AuthorDate: Sun Jul 17 21:50:38 2011 +0000 Commit: Vikraman Choudhury gmail com> CommitDate: Sun Jul 17 21:50:38 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/gentoostats.g= it;a=3Dcommit;h=3D2dda88db add package search feature --- server/app.py | 4 ++- server/search.py | 80 ++++++++++++++++++++++++++++++++++++= ++++++ server/templates/search.html | 14 +++++++ 3 files changed, 97 insertions(+), 1 deletions(-) diff --git a/server/app.py b/server/app.py index e957cde..fcef84f 100755 --- a/server/app.py +++ b/server/app.py @@ -14,6 +14,7 @@ from repo import Repo from lang import Lang from package import Package from host import Host +from search import Search =20 urls =3D ( r'', 'Index', @@ -30,7 +31,8 @@ urls =3D ( r'/package', 'Package', r'/use/(.+)', 'Use', r'/use', 'Use', - r'/host/(.+)', 'Host' + r'/host/(.+)', 'Host', + r'/search', 'Search' ) =20 app =3D web.application(urls, globals(), autoreload=3DTrue) diff --git a/server/search.py b/server/search.py new file mode 100644 index 0000000..69170ac --- /dev/null +++ b/server/search.py @@ -0,0 +1,80 @@ + +import web +import string +from config import render, db + +what =3D ['CAT', 'PKG', 'VER', 'REPO', 'COUNT(DISTINCT UUID) AS HOSTS'] +order_by =3D ['HOSTS DESC','CAT', 'PKG', 'VER', 'REPO'] +group_by =3D ['CAT', 'PKG', 'VER', 'REPO'] +which =3D ['PACKAGES','INSTALLED_PACKAGES','REPOSITORIES'] + +class Search(object): + + def GET(self): + self.args =3D web.input(cat=3D'any', pkg=3D'any', ver=3D'any', r= epo=3D'any') + + try: + self.min_hosts =3D int(web.input(min_hosts=3D-1).min_hosts) + except ValueError: + self.min_hosts =3D -1 + + try: + self.max_hosts =3D int(web.input(max_hosts=3D-1).max_hosts) + except ValueError: + self.max_hosts =3D -1 + + where =3D self._build_where() + having =3D self._build_having() + query =3D self._build_query(where, having) + search_tuples =3D db.query(query, vars=3D{ + 'cat':self.args.cat, + 'pkg':self.args.pkg, + 'ver':self.args.ver, + 'repo':self.args.repo, + 'min_hosts':self.min_hosts, + 'max_hosts':self.max_hosts}) + return render.search(search_tuples) + + def _build_query(self, where, having): + sep =3D ' ' + query =3D '' + query +=3D 'SELECT' + sep + ','.join(what) + sep + query +=3D 'FROM' + sep + (sep + 'NATURAL LEFT OUTER JOIN' + sep= ).join(which) + sep + if len(where) !=3D 0: + query +=3D 'WHERE' + sep + query +=3D (sep + 'AND' + sep).join(where) + query +=3D sep + query +=3D 'GROUP BY' + sep + ','.join(group_by) + sep + if len(having) !=3D 0: + query +=3D 'HAVING' + sep + query +=3D (sep + 'AND' + sep).join(having) + query +=3D sep + query +=3D 'ORDER BY' + sep + ','.join(order_by) + sep + return query.strip() + + def _build_where(self): + where =3D [] + cat =3D string.lower(self.args.cat) + if cat !=3D 'any': + where.append('CAT=3D$cat') + + pkg =3D string.lower(self.args.pkg) + if pkg !=3D 'any': + where.append('PKG=3D$pkg') + + ver =3D string.lower(self.args.ver) + if ver !=3D 'any': + where.append('VER=3D$ver') + + repo =3D string.lower(self.args.repo) + if repo !=3D 'any': + where.append('REPO=3D$repo') + return where + + def _build_having(self): + having =3D [] + if self.min_hosts !=3D -1: + having.append('HOSTS>=3D$min_hosts') + if self.max_hosts !=3D -1: + having.append('HOSTS<=3D$max_hosts') + return having diff --git a/server/templates/search.html b/server/templates/search.html new file mode 100644 index 0000000..c2ae39c --- /dev/null +++ b/server/templates/search.html @@ -0,0 +1,14 @@ +$def with (tuples) +$var title: Search + + + + + + + + + + $for t in tuples: + +
CategoryPackageVersionRepositoryHosts
$t['CAT']$t['PKG']$t['VER']$t['= REPO']$t['HOSTS']