* [gentoo-commits] proj/gentoostats:master commit in: server/, server/templates/
@ 2011-05-06 14:42 Vikraman Choudhury
0 siblings, 0 replies; 10+ messages in thread
From: Vikraman Choudhury @ 2011-05-06 14:42 UTC (permalink / raw
To: gentoo-commits
commit: 085560c594307487d3af47da41d39e724d0339fc
Author: Vikraman Choudhury <vikraman.choudhury <AT> gmail <DOT> com>
AuthorDate: Fri May 6 14:41:47 2011 +0000
Commit: Vikraman Choudhury <vikraman.choudhury <AT> gmail <DOT> com>
CommitDate: Fri May 6 14:41:47 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoostats.git;a=commit;h=085560c5
first commit for server code
---
server/config.py | 4 ++++
server/main.py | 39 +++++++++++++++++++++++++++++++++++++++
server/templates/error_404.html | 6 ++++++
server/templates/error_500.html | 5 +++++
server/templates/index.html | 4 ++++
server/templates/layout.html | 12 ++++++++++++
6 files changed, 70 insertions(+), 0 deletions(-)
diff --git a/server/config.py b/server/config.py
new file mode 100644
index 0000000..5ef7087
--- /dev/null
+++ b/server/config.py
@@ -0,0 +1,4 @@
+import web
+
+render = web.template.render('templates/', base='layout')
+
diff --git a/server/main.py b/server/main.py
new file mode 100755
index 0000000..51ae445
--- /dev/null
+++ b/server/main.py
@@ -0,0 +1,39 @@
+#!/usr/bin/env python
+
+import web
+import config
+from config import render
+import json
+
+urls = (
+ r'/', 'index',
+ r'/(.+)', 'stats'
+)
+
+class index:
+ def GET(self):
+ return render.index()
+
+class stats:
+ def GET(self, uuid):
+ return '<html><body>GET success</body></html>'
+
+ def POST(self, uuid):
+ pdata = json.JSONDecoder().decode(web.data())
+ print pdata
+ return 'Post for ' + uuid + ' successful'
+
+def notfound():
+ return web.notfound(render.error_404())
+
+def internalerror():
+ return web.internalerror(render.error_500())
+
+app = web.application(urls, globals())
+
+app.notfound = notfound
+app.internalerror = internalerror
+
+if __name__ == "__main__":
+ app.run()
+
diff --git a/server/templates/error_404.html b/server/templates/error_404.html
new file mode 100644
index 0000000..d310a86
--- /dev/null
+++ b/server/templates/error_404.html
@@ -0,0 +1,6 @@
+$var title: Page not found
+
+<p>The requested page was not found.</p>
+
+<p><strong>Developer note:</strong> Because Google and Microsoft think its OK to violate web standards for their own benefit, you must ensure that your error pages are larger than 512 bytes if you wish them to be displayed instead of the "friendly" error pages the browsers show. Which is why this message is here. To make the page longer. Bah.</p>
+
diff --git a/server/templates/error_500.html b/server/templates/error_500.html
new file mode 100644
index 0000000..2314e76
--- /dev/null
+++ b/server/templates/error_500.html
@@ -0,0 +1,5 @@
+$var title: Internal error
+
+<p>Oops, it seems something is broke on the server. Please try again.</p>
+
+<p><strong>Developer note:</strong> Because Google and Microsoft think its OK to violate web standards for their own benefit, you must ensure that your error pages are larger than 512 bytes if you wish them to be displayed instead of the "friendly" error pages the browsers show. Which is why this message is here. To make the page longer. Bah.</p>
diff --git a/server/templates/index.html b/server/templates/index.html
new file mode 100644
index 0000000..11fafb6
--- /dev/null
+++ b/server/templates/index.html
@@ -0,0 +1,4 @@
+$var title: Gentoostats
+
+Welcome to the gentoostats webapp
+
diff --git a/server/templates/layout.html b/server/templates/layout.html
new file mode 100644
index 0000000..48140d6
--- /dev/null
+++ b/server/templates/layout.html
@@ -0,0 +1,12 @@
+$def with (content)
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<title>$content.title</title>
+</head>
+<body>
+$:content
+</body>
+</html>
+
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [gentoo-commits] proj/gentoostats:master commit in: server/, server/templates/
@ 2011-06-14 17:43 Vikraman Choudhury
0 siblings, 0 replies; 10+ messages in thread
From: Vikraman Choudhury @ 2011-06-14 17:43 UTC (permalink / raw
To: gentoo-commits
commit: f54a02be8f73be30e0607c8ca5c887a12f426c53
Author: Vikraman Choudhury <vikraman.choudhury <AT> gmail <DOT> com>
AuthorDate: Tue Jun 14 17:43:08 2011 +0000
Commit: Vikraman Choudhury <vikraman.choudhury <AT> gmail <DOT> com>
CommitDate: Tue Jun 14 17:43:08 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoostats.git;a=commit;h=f54a02be
updated server code, added host page
---
server/config.py | 14 ++++
server/helpers.py | 49 ++++++++-------
server/host.py | 138 +++++++++++++++++++++++++++++++++++++++++++
server/index.py | 8 +++
server/main.py | 44 ++------------
server/post.py | 81 -------------------------
server/templates/host.html | 56 +++++++++++++++++
server/templates/index.html | 9 +--
server/templates/stats.html | 9 ---
9 files changed, 253 insertions(+), 155 deletions(-)
diff --git a/server/config.py b/server/config.py
index 5ef7087..f4e74cd 100644
--- a/server/config.py
+++ b/server/config.py
@@ -1,4 +1,18 @@
+
import web
+db = web.database(
+ dbn='mysql',
+ user='gentoo',
+ pw='gentoo',
+ db='gentoostats'
+ )
+
render = web.template.render('templates/', base='layout')
+def notfound():
+ return web.notfound(render.error_404())
+
+def internalerror():
+ return web.internalerror(render.error_500())
+
diff --git a/server/helpers.py b/server/helpers.py
index ad70e31..ebd53a3 100644
--- a/server/helpers.py
+++ b/server/helpers.py
@@ -2,6 +2,12 @@
import uuid
import re
+# check valid uuid
+
+def is_uuid(uuid):
+ regex = re.compile(r'^(\w{8})-(\w{4})-(\w{4})-(\w{4})-(\w{12})$')
+ return regex.search(uuid)
+
# convert uuid string to raw bytes
def uuidbin(string):
@@ -31,59 +37,58 @@ def pkgsplit(pkgname):
# lookup key and insert if not found
def get_kwkey(db, keyword):
- db_keyword = db.select('keywords', vars={'keyword':keyword}, where='keyword=$keyword')
+ db_keyword = db.select('KEYWORDS', vars={'keyword':keyword}, where='KEYWORD=$keyword')
if len(db_keyword):
- kwkey = db_keyword[0].kwkey
+ kwkey = db_keyword[0]['KWKEY']
else:
- kwkey = db.insert('keywords', keyword=keyword)
+ kwkey = db.insert('KEYWORDS', KEYWORD=keyword)
return kwkey
def get_lkey(db, lang):
- db_lang = db.select('lang', vars={'lang':lang}, where='lang=$lang')
+ db_lang = db.select('LANG', vars={'lang':lang}, where='LANG=$lang')
if len(db_lang):
- lkey = db_lang[0].lkey
+ lkey = db_lang[0]['LKEY']
else:
- lkey = db.insert('lang', lang=lang)
+ lkey = db.insert('LANG', LANG=lang)
return lkey
def get_fkey(db, feature):
- db_feature = db.select('features', vars={'feature':feature}, where='feature=$feature')
+ db_feature = db.select('FEATURES', vars={'feature':feature}, where='FEATURE=$feature')
if len(db_feature):
- fkey = db_feature[0].fkey
+ fkey = db_feature[0]['FKEY']
else:
- fkey = db.insert('features', feature=feature)
+ fkey = db.insert('FEATURES', FEATURE=feature)
return fkey
def get_mkey(db, mirror):
- db_mirror = db.select('gentoo_mirrors', vars={'mirror':mirror}, where='mirror=$mirror')
+ db_mirror = db.select('GENTOO_MIRRORS', vars={'mirror':mirror}, where='MIRROR=$mirror')
if len(db_mirror):
- mkey = db_mirror[0].mkey
+ mkey = db_mirror[0]['MKEY']
else:
- mkey = db.insert('gentoo_mirrors', mirror=mirror)
+ mkey = db.insert('GENTOO_MIRRORS', MIRROR=mirror)
return mkey
def get_ukey(db, useflag):
- db_useflag = db.select('useflags', vars={'useflag':useflag}, where='useflag=$useflag')
+ db_useflag = db.select('USEFLAGS', vars={'useflag':useflag}, where='USEFLAG=$useflag')
if len(db_useflag):
- ukey = db_useflag[0].ukey
+ ukey = db_useflag[0]['UKEY']
else:
- ukey = db.insert('useflags', useflag=useflag)
+ ukey = db.insert('USEFLAGS', USEFLAG=useflag)
return ukey
def get_pkey(db, package):
cpv = pkgsplit(package)
- db_package = db.select('packages', vars=cpv, where='cat=$cat and pkg=$pkg and ver=$ver')
+ db_package = db.select('PACKAGES', vars=cpv, where='CAT=$cat and PKG=$pkg and VER=$ver')
if len(db_package):
- pkey = db_package[0].pkey
+ pkey = db_package[0]['PKEY']
else:
- pkey = db.insert('packages', cat=cpv['cat'], pkg=cpv['pkg'], ver=cpv['ver'])
+ pkey = db.insert('PACKAGES', CAT=cpv['cat'], PKG=cpv['pkg'], VER=cpv['ver'])
return pkey
def get_rkey(db, repo):
- db_repo = db.select('repositories', vars={'repo':repo}, where='repo=$repo')
+ db_repo = db.select('REPOSITORIES', vars={'repo':repo}, where='REPO=$repo')
if len(db_repo):
- rkey = db_repo[0].rkey
+ rkey = db_repo[0]['RKEY']
else:
- rkey = db.insert('repositories', repo=repo)
+ rkey = db.insert('REPOSITORIES', REPO=repo)
return rkey
-
diff --git a/server/host.py b/server/host.py
new file mode 100644
index 0000000..50df581
--- /dev/null
+++ b/server/host.py
@@ -0,0 +1,138 @@
+
+import web
+import json
+import helpers
+import config
+from config import render, db
+
+class Host(object):
+
+ def GET(self, str_uuid):
+ if not helpers.is_uuid(str_uuid):
+ return config.notfound()
+
+ uuid = helpers.uuidbin(str_uuid)
+ hosts = db.select('HOSTS', vars={'uuid':uuid}, where='UUID=$uuid', what='UUID')
+ if len(hosts) == 0:
+ return config.notfound()
+
+ get_data = dict()
+ get_data['UUID'] = str_uuid
+
+ env = db.select('ENV', vars={'uuid':uuid}, where="UUID=$uuid")
+ e = env[0]
+ for var in ['PLATFORM','LASTSYNC','PROFILE','ARCH','CHOST','CFLAGS','CXXFLAGS','FFLAGS','LDFLAGS','MAKEOPTS','SYNC']:
+ get_data[var] = e[var]
+
+ get_data['FEATURES'] = list()
+ features = db.query('SELECT FEATURE FROM HOST_FEATURES NATURAL JOIN FEATURES WHERE UUID=$uuid', vars={'uuid':uuid})
+ for f in features:
+ get_data['FEATURES'].append(f['FEATURE'])
+
+ get_data['ACCEPT_KEYWORDS'] = list()
+ keywords = db.query('SELECT KEYWORD FROM GLOBAL_KEYWORDS NATURAL JOIN KEYWORDS WHERE UUID=$uuid', vars={'uuid':uuid})
+ for k in keywords:
+ get_data['ACCEPT_KEYWORDS'].append(k['KEYWORD'])
+
+ get_data['USE'] = list()
+ useflags = db.query('SELECT USEFLAG FROM GLOBAL_USEFLAGS NATURAL JOIN USEFLAGS WHERE UUID=$uuid', vars={'uuid':uuid})
+ for u in useflags:
+ get_data['USE'].append(u['USEFLAG'])
+
+ get_data['LANG'] = list()
+ lang = db.query('SELECT LANG FROM HOST_LANG NATURAL JOIN LANG WHERE UUID=$uuid', vars={'uuid':uuid})
+ for l in lang:
+ get_data['LANG'].append(l['LANG'])
+
+ get_data['GENTOO_MIRRORS'] = list()
+ mirrors = db.query('SELECT MIRROR FROM HOST_MIRRORS NATURAL JOIN GENTOO_MIRRORS WHERE UUID=$uuid', vars={'uuid':uuid})
+ for m in mirrors:
+ get_data['GENTOO_MIRRORS'].append(m['MIRROR'])
+
+ get_data['PACKAGES'] = dict()
+ packages = db.query('SELECT CAT, PKG, VER FROM INSTALLED_PACKAGES NATURAL JOIN PACKAGES WHERE UUID=$uuid ORDER BY CAT, PKG, VER', vars={'uuid':uuid})
+ for p in packages:
+ cpv = p['CAT'] + '/' + p['PKG'] + '-' + p['VER']
+ get_data['PACKAGES'][cpv] = dict()
+
+ return render.host(get_data)
+
+ def POST(self, str_uuid):
+ post_data = json.JSONDecoder().decode(web.data())
+
+ #TODO: Handle exceptions
+ if post_data['PROTOCOL'] != 1:
+ return 'Unsupported protocol!'
+
+ if post_data['AUTH']['UUID'] != str_uuid:
+ return 'Invalid uuid!'
+
+ uuid = helpers.uuidbin(str_uuid)
+
+ # Insert in hosts
+ db_host = db.select('HOSTS', vars={'uuid':uuid}, where='UUID=$uuid')
+ if len(db_host):
+ if post_data['AUTH']['PASSWD'] != db_host[0]['PASSWD']:
+ return 'Wrong password!'
+ # This should delete all host entries from all tables
+ db.delete('HOSTS', vars={'uuid':uuid}, where='UUID=$uuid')
+ db.insert('HOSTS', UUID=uuid, PASSWD=post_data['AUTH']['PASSWD'])
+
+ # Insert in env
+ db.insert('ENV', UUID=uuid, ARCH=post_data['ARCH'], CHOST=post_data['CHOST'], CFLAGS=post_data['CFLAGS'],
+ CXXFLAGS=post_data['CXXFLAGS'], FFLAGS=post_data['FFLAGS'], LDFLAGS=post_data['LDFLAGS'],
+ MAKEOPTS=post_data['MAKEOPTS'], SYNC=post_data['SYNC'], PLATFORM=post_data['PLATFORM'],
+ PROFILE=post_data['PROFILE'], LASTSYNC=post_data['LASTSYNC'])
+
+ # Insert in GLOBAL_KEYWORDS
+ for keyword in post_data['ACCEPT_KEYWORDS']:
+ kwkey = helpers.get_kwkey(db, keyword)
+ db.insert('GLOBAL_KEYWORDS', UUID=uuid, KWKEY=kwkey)
+
+ # Insert in HOST_LANG
+ for lang in post_data['LANG']:
+ lkey = helpers.get_lkey(db, lang)
+ db.insert('HOST_LANG', UUID=uuid, LKEY=lkey)
+
+ # Insert in HOST_FEATURES
+ for feature in post_data['FEATURES']:
+ fkey = helpers.get_fkey(db, feature)
+ db.insert('HOST_FEATURES', UUID=uuid, FKEY=fkey)
+
+ # Insert in HOST_MIRRORS
+ for mirror in post_data['GENTOO_MIRRORS']:
+ mkey = helpers.get_mkey(db, mirror)
+ db.insert('HOST_MIRRORS', UUID=uuid, MKEY=mkey)
+
+ # Insert in GLOBAL_USEFLAGS
+ for useflag in post_data['USE']:
+ ukey = helpers.get_ukey(db, useflag)
+ db.insert('GLOBAL_USEFLAGS', UUID=uuid, UKEY=ukey)
+
+ # Handle PACKAGES
+ for package in post_data['PACKAGES'].keys():
+ pkey = helpers.get_pkey(db, package)
+ post_data_pkg = post_data['PACKAGES'][package]
+ kwkey = helpers.get_kwkey(db, post_data_pkg['KEYWORD'])
+ rkey = helpers.get_rkey(db, post_data_pkg['REPO'])
+
+ # Insert in INSTALLED_PACKAGES
+ ipkey = db.insert('INSTALLED_PACKAGES', UUID=uuid, PKEY=pkey, BUILD_TIME=post_data_pkg['BUILD_TIME'],
+ COUNTER=post_data_pkg['COUNTER'], KWKEY=kwkey, RKEY=rkey, SIZE=post_data_pkg['SIZE'])
+
+ # Insert in PLUS_USEFLAGS
+ for useflag in post_data_pkg['USE']['PLUS']:
+ ukey = helpers.get_ukey(db, useflag)
+ db.insert('PLUS_USEFLAGS', IPKEY=ipkey, UKEY=ukey)
+
+ # Insert in MINUS_USEFLAGS
+ for useflag in post_data_pkg['USE']['MINUS']:
+ ukey = helpers.get_ukey(db, useflag)
+ db.insert('MINUS_USEFLAGS', IPKEY=ipkey, UKEY=ukey)
+
+ # Insert in UNSET_USEFLAGS
+ for useflag in post_data_pkg['USE']['UNSET']:
+ ukey = helpers.get_ukey(db, useflag)
+ db.insert('UNSET_USEFLAGS', IPKEY=ipkey, UKEY=ukey)
+
+ return 'POST for ' + str_uuid + ' successful'
diff --git a/server/index.py b/server/index.py
new file mode 100644
index 0000000..038ae51
--- /dev/null
+++ b/server/index.py
@@ -0,0 +1,8 @@
+
+from config import render, db
+
+class Index(object):
+ def GET(self):
+ hosts = db.select('hosts', what='count(uuid) as count')
+ count = hosts[0].count
+ return render.index(count)
diff --git a/server/main.py b/server/main.py
index 08b8509..9eb74fa 100755
--- a/server/main.py
+++ b/server/main.py
@@ -2,49 +2,19 @@
import web
import config
-import json
from config import render
-from post import handler
+from index import Index
+from host import Host
urls = (
- r'/', 'index',
- r'/(.+)', 'stats'
-)
-
-db = web.database(
- dbn='mysql',
- user='gentoo',
- pw='gentoo',
- db='gentoostats'
- )
-
-class index:
- def GET(self):
- hosts = db.select('hosts')
- return render.index(hosts)
-
-class stats:
- def GET(self, uuid):
- if uuid == 'favicon.ico':
- return notfound()
- hosts = db.select('hosts', vars={'uuid':uuid}, where="uuid=$uuid")
- env = db.select('env', vars={'uuid':uuid}, where="uuid=$uuid")
- return render.stats(uuid, hosts, env)
-
- def POST(self, uuid):
- post_data = json.JSONDecoder().decode(web.data())
- return handler(uuid, post_data, db)
-
-def notfound():
- return web.notfound(render.error_404())
-
-def internalerror():
- return web.internalerror(render.error_500())
+ r'/', 'Index',
+ r'/host/(.+)', 'Host'
+ )
app = web.application(urls, globals())
-app.notfound = notfound
-app.internalerror = internalerror
+app.notfound = config.notfound
+app.internalerror = config.internalerror
if __name__ == "__main__":
app.run()
diff --git a/server/post.py b/server/post.py
deleted file mode 100644
index b9f4deb..0000000
--- a/server/post.py
+++ /dev/null
@@ -1,81 +0,0 @@
-#!/usr/bin/env python
-
-from helpers import *
-
-def handler(uuid_str, data, db):
- #TODO: Handle exceptions
- if data['PROTOCOL'] != 1:
- return 'Unsupported protocol!'
-
- if data['AUTH']['UUID'] != uuid_str:
- return 'Invalid uuid!'
-
- uuid = uuidbin(uuid_str)
-
- # Insert in hosts
- db_host = db.select('hosts', vars={'uuid':uuid}, where='uuid=$uuid')
- if len(db_host):
- if data['AUTH']['PASSWD'] != db_host[0].passwd:
- return 'Wrong password!'
- # This should delete all host entries from all tables
- db.delete('hosts', vars={'uuid':uuid}, where='uuid=$uuid')
- db.insert('hosts', uuid=uuid, passwd=data['AUTH']['PASSWD'])
-
- # Insert in env
- db.insert('env', uuid=uuid, arch=data['ARCH'], chost=data['CHOST'], cflags=data['CFLAGS'],
- cxxflags=data['CXXFLAGS'], fflags=data['FFLAGS'], ldflags=data['LDFLAGS'],
- makeopts=data['MAKEOPTS'], sync=data['SYNC'], platform=data['PLATFORM'],
- profile=data['PROFILE'], lastsync=data['LASTSYNC'])
-
- # Insert in global_keywords
- for keyword in data['ACCEPT_KEYWORDS']:
- kwkey = get_kwkey(db, keyword)
- db.insert('global_keywords', uuid=uuid, kwkey=kwkey)
-
- # Insert in host_lang
- for lang in data['LANG']:
- lkey = get_lkey(db, lang)
- db.insert('host_lang', uuid=uuid, lkey=lkey)
-
- # Insert in host_features
- for feature in data['FEATURES']:
- fkey = get_fkey(db, feature)
- db.insert('host_features', uuid=uuid, fkey=fkey)
-
- # Insert in host_mirrors
- for mirror in data['GENTOO_MIRRORS']:
- mkey = get_mkey(db, mirror)
- db.insert('host_mirrors', uuid=uuid, mkey=mkey)
-
- # Insert in global_useflags
- for useflag in data['USE']:
- ukey = get_ukey(db, useflag)
- db.insert('global_useflags', uuid=uuid, ukey=ukey)
-
- # Handle packages
- for package in data['PACKAGES'].keys():
- pkey = get_pkey(db, package)
- data_pkg = data['PACKAGES'][package]
- kwkey = get_kwkey(db, data_pkg['KEYWORD'])
- rkey = get_rkey(db, data_pkg['REPO'])
-
- # Insert in installed_packages
- ipkey = db.insert('installed_packages', uuid=uuid, pkey=pkey, build_time=data_pkg['BUILD_TIME'],
- counter=data_pkg['COUNTER'], kwkey=kwkey, rkey=rkey, size=data_pkg['SIZE'])
-
- # Insert in plus_useflags
- for useflag in data_pkg['USE']['PLUS']:
- ukey = get_ukey(db, useflag)
- db.insert('plus_useflags', ipkey=ipkey, ukey=ukey)
-
- # Insert in minus_useflags
- for useflag in data_pkg['USE']['MINUS']:
- ukey = get_ukey(db, useflag)
- db.insert('minus_useflags', ipkey=ipkey, ukey=ukey)
-
- # Insert in unset_useflags
- for useflag in data_pkg['USE']['UNSET']:
- ukey = get_ukey(db, useflag)
- db.insert('unset_useflags', ipkey=ipkey, ukey=ukey)
-
- return 'POST for ' + uuid_str + ' successful'
diff --git a/server/templates/host.html b/server/templates/host.html
new file mode 100644
index 0000000..04b1bff
--- /dev/null
+++ b/server/templates/host.html
@@ -0,0 +1,56 @@
+$def with (data)
+$var title: Host
+
+Stats for host $data['UUID'] : <br/> <br/>
+<ul>
+<li>Platform : $data['PLATFORM']</li>
+<li>Profile : $data['PROFILE']</li>
+<li>Timestamp of tree : $data['LASTSYNC']</li>
+<li>ARCH : $data['ARCH']</li>
+<li>CHOST : $data['CHOST']</li>
+<li>CFLAGS : $data['CFLAGS']</li>
+<li>CXXFLAGS : $data['CXXFLAGS']</li>
+<li>FFLAGS : $data['FFLAGS']</li>
+<li>LDLAGS : $data['LDFLAGS']</li>
+<li>MAKEOPTS : $data['MAKEOPTS']</li>
+<li>SYNC : $data['SYNC']</li>
+<li>FEATURES :
+<ul>
+$for f in data['FEATURES']:
+ <li>$f</li>
+</ul>
+</li>
+<li>ACCEPT_KEYWORDS :
+<ul>
+$for k in data['ACCEPT_KEYWORDS']:
+ <li>$k</li>
+</ul>
+</li>
+<li>USE :
+<ul>
+$for u in data['USE']:
+ <li>$u</li>
+</ul>
+</li>
+<li>LANG :
+<ul>
+$for l in data['LANG']:
+ <li>$l</li>
+</ul>
+</li>
+<li>GENTOO_MIRRORS :
+<ul>
+$for m in data['GENTOO_MIRRORS']:
+ <li>$m</li>
+</ul>
+</li>
+<li>Installed packages :
+<ul>
+$code:
+ packages = data['PACKAGES'].keys()
+ packages.sort()
+$for p in packages:
+ <li>$p</li>
+</ul>
+</li>
+</ul>
diff --git a/server/templates/index.html b/server/templates/index.html
index 76c16e5..86960c0 100644
--- a/server/templates/index.html
+++ b/server/templates/index.html
@@ -1,9 +1,6 @@
-$def with (hosts)
+$def with (count)
$var title: Gentoostats
Welcome to the gentoostats webapp <br/>
-
-List of hosts: <br/>
-
-$for host in hosts:
- <li><a href=$host.uuid>$host.uuid</li>
+<br/>
+Number of hosts: $count<br/>
diff --git a/server/templates/stats.html b/server/templates/stats.html
deleted file mode 100644
index 7081b02..0000000
--- a/server/templates/stats.html
+++ /dev/null
@@ -1,9 +0,0 @@
-$def with (uuid, hosts, env)
-$var title: Stats
-
-$if len(hosts):
- Stats for host $uuid : <br/>
- $for e in env:
- <li>$e.var = "$e.value"</li>
-$else:
- Host does not exist in records!
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [gentoo-commits] proj/gentoostats:master commit in: server/, server/templates/
@ 2011-07-03 18:04 Vikraman Choudhury
0 siblings, 0 replies; 10+ messages in thread
From: Vikraman Choudhury @ 2011-07-03 18:04 UTC (permalink / raw
To: gentoo-commits
commit: f5f0837b3bb3a7bdbf3adde70a6defcb3819c602
Author: Vikraman Choudhury <vikraman.choudhury <AT> gmail <DOT> com>
AuthorDate: Sun Jul 3 18:03:33 2011 +0000
Commit: Vikraman Choudhury <vikraman.choudhury <AT> gmail <DOT> com>
CommitDate: Sun Jul 3 18:03:33 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoostats.git;a=commit;h=f5f0837b
more stats pages
---
server/app.py | 16 ++++++++++++++++
server/arch.py | 10 ++++++++++
server/feature.py | 10 ++++++++++
server/kwd.py | 10 ++++++++++
server/lang.py | 10 ++++++++++
server/mirror.py | 10 ++++++++++
server/profile.py | 10 ++++++++++
server/repo.py | 10 ++++++++++
server/templates/arch.html | 11 +++++++++++
server/templates/feature.html | 11 +++++++++++
server/templates/keyword.html | 12 ++++++++++++
server/templates/lang.html | 11 +++++++++++
server/templates/mirror.html | 11 +++++++++++
server/templates/profile.html | 11 +++++++++++
server/templates/repo.html | 12 ++++++++++++
server/templates/use.html | 11 +++++++++++
server/use.py | 10 ++++++++++
17 files changed, 186 insertions(+), 0 deletions(-)
diff --git a/server/app.py b/server/app.py
index 89ade62..ba77639 100755
--- a/server/app.py
+++ b/server/app.py
@@ -4,10 +4,26 @@ import web
import config
from config import render
from index import Index
+from arch import Arch
+from profile import Profile
+from mirror import Mirror
+from feature import Feature
+from kwd import Keyword
+from use import Use
+from repo import Repo
+from lang import Lang
from host import Host
urls = (
r'/', 'Index',
+ r'/arch', 'Arch',
+ r'/profile', 'Profile',
+ r'/mirror', 'Mirror',
+ r'/feature', 'Feature',
+ r'/keyword', 'Keyword',
+ r'/use', 'Use',
+ r'/repo', 'Repo',
+ r'/lang', 'Lang',
r'/host/(.+)', 'Host'
)
diff --git a/server/arch.py b/server/arch.py
new file mode 100644
index 0000000..a389b8f
--- /dev/null
+++ b/server/arch.py
@@ -0,0 +1,10 @@
+
+from config import render, db
+
+class Arch(object):
+ def GET(self):
+ arch_count = db.select('ENV', what='ARCH, COUNT(UUID) AS HOSTS', group='ARCH')
+ arch_data = dict()
+ for t in arch_count:
+ arch_data[t['ARCH']] = {'HOSTS':t['HOSTS']}
+ return render.arch(arch_data)
diff --git a/server/feature.py b/server/feature.py
new file mode 100644
index 0000000..4b79da5
--- /dev/null
+++ b/server/feature.py
@@ -0,0 +1,10 @@
+
+from config import render, db
+
+class Feature(object):
+ def GET(self):
+ feature_count = db.query('SELECT FEATURE,COUNT(UUID) AS HOSTS FROM HOST_FEATURES NATURAL JOIN FEATURES GROUP BY FEATURE')
+ feature_data = dict()
+ for t in feature_count:
+ feature_data[t['FEATURE']] = {'HOSTS':t['HOSTS']}
+ return render.feature(feature_data)
diff --git a/server/kwd.py b/server/kwd.py
new file mode 100644
index 0000000..88fc799
--- /dev/null
+++ b/server/kwd.py
@@ -0,0 +1,10 @@
+
+from config import render, db
+
+class Keyword(object):
+ def GET(self):
+ keyword_count = db.query('SELECT KEYWORD, COUNT(DISTINCT IPKEY) AS PACKAGES, COUNT(DISTINCT UUID) AS HOSTS FROM GLOBAL_KEYWORDS NATURAL JOIN KEYWORDS NATURAL JOIN INSTALLED_PACKAGES GROUP BY KEYWORD')
+ keyword_data = dict()
+ for t in keyword_count:
+ keyword_data[t['KEYWORD']] = {'HOSTS':t['HOSTS'],'PACKAGES':t['PACKAGES']}
+ return render.keyword(keyword_data)
diff --git a/server/lang.py b/server/lang.py
new file mode 100644
index 0000000..3f4ebfb
--- /dev/null
+++ b/server/lang.py
@@ -0,0 +1,10 @@
+
+from config import render, db
+
+class Lang(object):
+ def GET(self):
+ lang_count = db.query('SELECT LANG,COUNT(UUID) AS HOSTS FROM HOST_LANG NATURAL JOIN LANG GROUP BY LANG')
+ lang_data = dict()
+ for t in lang_count:
+ lang_data[t['LANG']] = {'HOSTS':t['HOSTS']}
+ return render.lang(lang_data)
diff --git a/server/mirror.py b/server/mirror.py
new file mode 100644
index 0000000..7084831
--- /dev/null
+++ b/server/mirror.py
@@ -0,0 +1,10 @@
+
+from config import render, db
+
+class Mirror(object):
+ def GET(self):
+ mirror_count = db.query('SELECT MIRROR,COUNT(UUID) AS HOSTS FROM HOST_MIRRORS NATURAL JOIN GENTOO_MIRRORS GROUP BY MIRROR')
+ mirror_data = dict()
+ for t in mirror_count:
+ mirror_data[t['MIRROR']] = {'HOSTS':t['HOSTS']}
+ return render.mirror(mirror_data)
diff --git a/server/profile.py b/server/profile.py
new file mode 100644
index 0000000..211963c
--- /dev/null
+++ b/server/profile.py
@@ -0,0 +1,10 @@
+
+from config import render, db
+
+class Profile(object):
+ def GET(self):
+ profile_count = db.select('ENV', what='PROFILE, COUNT(UUID) AS HOSTS', group='PROFILE')
+ profile_data = dict()
+ for t in profile_count:
+ profile_data[t['PROFILE']] = {'HOSTS':t['HOSTS']}
+ return render.profile(profile_data)
diff --git a/server/repo.py b/server/repo.py
new file mode 100644
index 0000000..4348248
--- /dev/null
+++ b/server/repo.py
@@ -0,0 +1,10 @@
+
+from config import render, db
+
+class Repo(object):
+ def GET(self):
+ repo_count = db.query('select REPO,COUNT(DISTINCT IPKEY) AS PACKAGES,COUNT(DISTINCT UUID) AS HOSTS from INSTALLED_PACKAGES natural join REPOSITORIES group by REPO')
+ repo_data = dict()
+ for t in repo_count:
+ repo_data[t['REPO']] = {'HOSTS':t['HOSTS'], 'PACKAGES':t['PACKAGES']}
+ return render.repo(repo_data)
diff --git a/server/templates/arch.html b/server/templates/arch.html
new file mode 100644
index 0000000..535399c
--- /dev/null
+++ b/server/templates/arch.html
@@ -0,0 +1,11 @@
+$def with (arch_data)
+$var title: Arch
+
+<table border="1">
+ <tr>
+ <th>Arch</th>
+ <th>Hosts</th>
+ </tr>
+ $for arch in arch_data.keys():
+ <tr><td>$arch</td><td>$arch_data[arch]['HOSTS']</td></tr>
+</table>
diff --git a/server/templates/feature.html b/server/templates/feature.html
new file mode 100644
index 0000000..03c4bbd
--- /dev/null
+++ b/server/templates/feature.html
@@ -0,0 +1,11 @@
+$def with (feature_data)
+$var title: Feature
+
+<table border="1">
+ <tr>
+ <th>Feature</th>
+ <th>Hosts</th>
+ </tr>
+ $for feature in feature_data.keys():
+ <tr><td>$feature</td><td>$feature_data[feature]['HOSTS']</td></tr>
+</table>
diff --git a/server/templates/keyword.html b/server/templates/keyword.html
new file mode 100644
index 0000000..4855040
--- /dev/null
+++ b/server/templates/keyword.html
@@ -0,0 +1,12 @@
+$def with (keyword_data)
+$var title: Keyword
+
+<table border="1">
+ <tr>
+ <th>Keyword</th>
+ <th>Hosts</th>
+ <th>Packages</th>
+ </tr>
+ $for keyword in keyword_data.keys():
+ <tr><td>$keyword</td><td>$keyword_data[keyword]['HOSTS']</td><td>$keyword_data[keyword]['PACKAGES']</td></tr>
+</table>
diff --git a/server/templates/lang.html b/server/templates/lang.html
new file mode 100644
index 0000000..cfda84a
--- /dev/null
+++ b/server/templates/lang.html
@@ -0,0 +1,11 @@
+$def with (lang_data)
+$var title: Lang
+
+<table border="1">
+ <tr>
+ <th>Lang</th>
+ <th>Hosts</th>
+ </tr>
+ $for lang in lang_data.keys():
+ <tr><td>$lang</td><td>$lang_data[lang]['HOSTS']</td></tr>
+</table>
diff --git a/server/templates/mirror.html b/server/templates/mirror.html
new file mode 100644
index 0000000..a6189bc
--- /dev/null
+++ b/server/templates/mirror.html
@@ -0,0 +1,11 @@
+$def with (mirror_data)
+$var title: Mirror
+
+<table border="1">
+ <tr>
+ <th>Mirror</th>
+ <th>Hosts</th>
+ </tr>
+ $for mirror in mirror_data.keys():
+ <tr><td>$mirror</td><td>$mirror_data[mirror]['HOSTS']</td></tr>
+</table>
diff --git a/server/templates/profile.html b/server/templates/profile.html
new file mode 100644
index 0000000..702b03b
--- /dev/null
+++ b/server/templates/profile.html
@@ -0,0 +1,11 @@
+$def with (profile_data)
+$var title: Profile
+
+<table border="1">
+ <tr>
+ <th>Profile/th>
+ <th>Hosts</th>
+ </tr>
+ $for profile in profile_data.keys():
+ <tr><td>$profile</td><td>$profile_data[profile]['HOSTS']</td></tr>
+</table>
diff --git a/server/templates/repo.html b/server/templates/repo.html
new file mode 100644
index 0000000..63371bb
--- /dev/null
+++ b/server/templates/repo.html
@@ -0,0 +1,12 @@
+$def with (repo_data)
+$var title: Repository
+
+<table border="1">
+ <tr>
+ <th>Repository</th>
+ <th>Hosts</th>
+ <th>Packages</th>
+ </tr>
+ $for repo in repo_data.keys():
+ <tr><td>$repo</td><td>$repo_data[repo]['HOSTS']</td><td>$repo_data[repo]['PACKAGES']</td></tr>
+</table>
diff --git a/server/templates/use.html b/server/templates/use.html
new file mode 100644
index 0000000..209f8f8
--- /dev/null
+++ b/server/templates/use.html
@@ -0,0 +1,11 @@
+$def with (use_data)
+$var title: Use
+
+<table border="1">
+ <tr>
+ <th>Use</th>
+ <th>Hosts</th>
+ </tr>
+ $for use in use_data.keys():
+ <tr><td>$use</td><td>$use_data[use]['HOSTS']</td></tr>
+</table>
diff --git a/server/use.py b/server/use.py
new file mode 100644
index 0000000..dfdcfaf
--- /dev/null
+++ b/server/use.py
@@ -0,0 +1,10 @@
+
+from config import render, db
+
+class Use(object):
+ def GET(self):
+ use_count = db.query('SELECT USEFLAG,COUNT(UUID) AS HOSTS FROM GLOBAL_USEFLAGS NATURAL JOIN USEFLAGS GROUP BY USEFLAG')
+ use_data = dict()
+ for t in use_count:
+ use_data[t['USEFLAG']] = {'HOSTS':t['HOSTS']}
+ return render.use(use_data)
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [gentoo-commits] proj/gentoostats:master commit in: server/, server/templates/
@ 2011-07-07 16:02 Vikraman Choudhury
0 siblings, 0 replies; 10+ messages in thread
From: Vikraman Choudhury @ 2011-07-07 16:02 UTC (permalink / raw
To: gentoo-commits
commit: dbf074eb8ad273dcb0f6ac3e0f5af97a45ce0423
Author: Vikraman Choudhury <vikraman.choudhury <AT> gmail <DOT> com>
AuthorDate: Thu Jul 7 16:01:56 2011 +0000
Commit: Vikraman Choudhury <vikraman.choudhury <AT> gmail <DOT> com>
CommitDate: Thu Jul 7 16:01:56 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoostats.git;a=commit;h=dbf074eb
add package stats
---
server/app.py | 4 ++
server/helpers.py | 26 ++++++------
server/host.py | 32 ++++++++--------
server/package.py | 74 +++++++++++++++++++++++++++++++++++++
server/templates/package.html | 7 +++
server/templates/package_c.html | 6 +++
server/templates/package_cp.html | 5 ++
server/templates/package_cpv.html | 4 ++
8 files changed, 129 insertions(+), 29 deletions(-)
diff --git a/server/app.py b/server/app.py
index ba77639..94dffdd 100755
--- a/server/app.py
+++ b/server/app.py
@@ -12,6 +12,7 @@ from kwd import Keyword
from use import Use
from repo import Repo
from lang import Lang
+from package import Package
from host import Host
urls = (
@@ -24,6 +25,9 @@ urls = (
r'/use', 'Use',
r'/repo', 'Repo',
r'/lang', 'Lang',
+ r'/package/(.+)/(.+)', 'Package',
+ r'/package/(.+)', 'Package',
+ r'/package', 'Package',
r'/host/(.+)', 'Host'
)
diff --git a/server/helpers.py b/server/helpers.py
index 386d73c..10ac31f 100644
--- a/server/helpers.py
+++ b/server/helpers.py
@@ -1,6 +1,7 @@
import uuid
import re
+from portage.versions import catpkgsplit
# check valid uuid
@@ -15,22 +16,21 @@ def uuidbin(string):
u = uuid.UUID(string)
return u.bytes
-# split package name into cpv
-# based on pkgsplit code
-# in portage/versions.py
+# custom pkgsplit
def pkgsplit(pkgname):
- cpv={}
- pkgsplit = pkgname.split('/',1)
- cpv['cat'] = pkgsplit[0]
- pv_re =re.compile(r'(?x)^(?P<pn>[\w\+][\w\+-]*?(?P<pn_inval>-(cvs\.)?(\d+)((\.\d+)*)([a-z]?)((_(pre|p|beta|alpha|rc)\d*)*)(-r(\d+))?)?)-(?P<ver>(cvs\.)?(\d+)((\.\d+)*)([a-z]?)((_(pre|p|beta|alpha|rc)\d*)*))(-r(?P<rev>\d+))?$')
- m = pv_re.match(pkgsplit[1])
- cpv['pkg'] = m.group('pn')
- rev = m.group('rev')
- if rev is None:
- cpv['ver'] = m.group('ver')
+ cpv={'cat':'','pkg':'','ver':''}
+ cpvr = catpkgsplit(pkgname)
+ if cpvr is None:
+ pkgsplit = pkgname.split('/')
+ cpv['cat'] = pkgsplit[0]
+ cpv['pkg'] = pkgsplit[1]
else:
- cpv['ver'] = m.group('ver') + '-r' + rev
+ cpv['cat'] = cpvr[0]
+ cpv['pkg'] = cpvr[1]
+ cpv['ver'] = cpvr[2]
+ if cpvr[3] != 'r0':
+ cpv['ver'] = cpv['ver'] + '-' + cpvr[3]
return cpv
# get functions for index keys
diff --git a/server/host.py b/server/host.py
index b0d9235..c9a5d03 100644
--- a/server/host.py
+++ b/server/host.py
@@ -16,46 +16,46 @@ class Host(object):
if len(hosts) == 0:
return config.notfound()
- get_data = dict()
- get_data['UUID'] = str_uuid
+ host_data = dict()
+ host_data['UUID'] = str_uuid
env = db.select('ENV', vars={'uuid':uuid}, where="UUID=$uuid")
e = env[0]
for var in ['PLATFORM','LASTSYNC','PROFILE','ARCH','CHOST','CFLAGS','CXXFLAGS','FFLAGS','LDFLAGS','MAKEOPTS','SYNC']:
- get_data[var] = e[var]
+ host_data[var] = e[var]
- get_data['FEATURES'] = list()
+ host_data['FEATURES'] = list()
features = db.query('SELECT FEATURE FROM HOST_FEATURES NATURAL JOIN FEATURES WHERE UUID=$uuid', vars={'uuid':uuid})
for f in features:
- get_data['FEATURES'].append(f['FEATURE'])
+ host_data['FEATURES'].append(f['FEATURE'])
- get_data['ACCEPT_KEYWORDS'] = list()
+ host_data['ACCEPT_KEYWORDS'] = list()
keywords = db.query('SELECT KEYWORD FROM GLOBAL_KEYWORDS NATURAL JOIN KEYWORDS WHERE UUID=$uuid', vars={'uuid':uuid})
for k in keywords:
- get_data['ACCEPT_KEYWORDS'].append(k['KEYWORD'])
+ host_data['ACCEPT_KEYWORDS'].append(k['KEYWORD'])
- get_data['USE'] = list()
+ host_data['USE'] = list()
useflags = db.query('SELECT USEFLAG FROM GLOBAL_USEFLAGS NATURAL JOIN USEFLAGS WHERE UUID=$uuid', vars={'uuid':uuid})
for u in useflags:
- get_data['USE'].append(u['USEFLAG'])
+ host_data['USE'].append(u['USEFLAG'])
- get_data['LANG'] = list()
+ host_data['LANG'] = list()
lang = db.query('SELECT LANG FROM HOST_LANG NATURAL JOIN LANG WHERE UUID=$uuid', vars={'uuid':uuid})
for l in lang:
- get_data['LANG'].append(l['LANG'])
+ host_data['LANG'].append(l['LANG'])
- get_data['GENTOO_MIRRORS'] = list()
+ host_data['GENTOO_MIRRORS'] = list()
mirrors = db.query('SELECT MIRROR FROM HOST_MIRRORS NATURAL JOIN GENTOO_MIRRORS WHERE UUID=$uuid', vars={'uuid':uuid})
for m in mirrors:
- get_data['GENTOO_MIRRORS'].append(m['MIRROR'])
+ host_data['GENTOO_MIRRORS'].append(m['MIRROR'])
- get_data['PACKAGES'] = dict()
+ host_data['PACKAGES'] = dict()
packages = db.query('SELECT CAT, PKG, VER FROM INSTALLED_PACKAGES NATURAL JOIN PACKAGES WHERE UUID=$uuid ORDER BY CAT, PKG, VER', vars={'uuid':uuid})
for p in packages:
cpv = p['CAT'] + '/' + p['PKG'] + '-' + p['VER']
- get_data['PACKAGES'][cpv] = dict()
+ host_data['PACKAGES'][cpv] = dict()
- return render.host(get_data)
+ return render.host(host_data)
def POST(self, str_uuid):
post_data = json.JSONDecoder().decode(web.data())
diff --git a/server/package.py b/server/package.py
new file mode 100644
index 0000000..8f23daf
--- /dev/null
+++ b/server/package.py
@@ -0,0 +1,74 @@
+
+import helpers
+from config import render, db
+
+class Package(object):
+ def GET(self, *args):
+ l = len(args)
+ if l == 0:
+ return self.__GET()
+ elif l == 1:
+ return self.__GET_C(args[0])
+ elif l == 2:
+ cpv = helpers.pkgsplit(args[0] + '/' + args[1])
+ if cpv['ver'] == '':
+ return self.__GET_CP(cpv['cat'], cpv['pkg'])
+ else:
+ return self.__GET_CPV(cpv['cat'], cpv['pkg'], cpv['ver'])
+ else:
+ return config.internalerror()
+
+ def __GET(self):
+ pquery = db.query('SELECT COUNT(DISTINCT UUID) AS HOST_COUNT,\
+ COUNT(DISTINCT CAT) AS C_COUNT,\
+ COUNT(DISTINCT CAT,PKG) AS CP_COUNT,\
+ COUNT(DISTINCT CAT,PKG,VER) AS CPV_COUNT\
+ FROM INSTALLED_PACKAGES RIGHT OUTER JOIN PACKAGES\
+ ON INSTALLED_PACKAGES.PKEY = PACKAGES.PKEY')
+ t = pquery[0]
+ pdata = {
+ 'HOST_COUNT':t['HOST_COUNT'],
+ 'C_COUNT':t['C_COUNT'],
+ 'CP_COUNT':t['CP_COUNT'],
+ 'CPV_COUNT':t['CPV_COUNT']
+ }
+ return render.package(pdata)
+
+ def __GET_C(self, cat):
+ pquery = db.query('SELECT COUNT(DISTINCT UUID) AS HOST_COUNT,\
+ COUNT(DISTINCT CAT,PKG) AS CP_COUNT,\
+ COUNT(DISTINCT CAT,PKG,VER) AS CPV_COUNT\
+ FROM INSTALLED_PACKAGES RIGHT OUTER JOIN PACKAGES\
+ ON INSTALLED_PACKAGES.PKEY = PACKAGES.PKEY\
+ WHERE CAT=$cat', vars={'cat':cat})
+ t = pquery[0]
+ pdata = {
+ 'HOST_COUNT':t['HOST_COUNT'],
+ 'CP_COUNT':t['CP_COUNT'],
+ 'CPV_COUNT':t['CPV_COUNT']
+ }
+ return render.package_c(cat, pdata)
+
+ def __GET_CP(self, cat, pkg):
+ pquery = db.query('SELECT COUNT(DISTINCT UUID) AS HOST_COUNT,\
+ COUNT(DISTINCT CAT,PKG,VER) AS CPV_COUNT\
+ FROM INSTALLED_PACKAGES RIGHT OUTER JOIN PACKAGES\
+ ON INSTALLED_PACKAGES.PKEY = PACKAGES.PKEY\
+ WHERE CAT=$cat AND PKG=$pkg', vars={'cat':cat,'pkg':pkg})
+ t = pquery[0]
+ pdata = {
+ 'HOST_COUNT':t['HOST_COUNT'],
+ 'CPV_COUNT':t['CPV_COUNT']
+ }
+ return render.package_cp(cat, pkg, pdata)
+
+ def __GET_CPV(self, cat, pkg, ver):
+ pquery = db.query('SELECT COUNT(DISTINCT UUID) AS HOST_COUNT\
+ FROM INSTALLED_PACKAGES RIGHT OUTER JOIN PACKAGES\
+ ON INSTALLED_PACKAGES.PKEY = PACKAGES.PKEY\
+ WHERE CAT=$cat AND PKG=$pkg AND VER=$ver', vars={'cat':cat,'pkg':pkg,'ver':ver})
+ t = pquery[0]
+ pdata = {
+ 'HOST_COUNT':t['HOST_COUNT'],
+ }
+ return render.package_cpv(cat, pkg, ver, pdata)
diff --git a/server/templates/package.html b/server/templates/package.html
new file mode 100644
index 0000000..ca8ec96
--- /dev/null
+++ b/server/templates/package.html
@@ -0,0 +1,7 @@
+$def with (pdata)
+$var title: Package
+
+No. of hosts: $pdata['HOST_COUNT']</br>
+No. of categories: $pdata['C_COUNT']</br>
+No. of category-packages: $pdata['CP_COUNT']</br>
+No. of category-package-versions: $pdata['CPV_COUNT']</br>
diff --git a/server/templates/package_c.html b/server/templates/package_c.html
new file mode 100644
index 0000000..1d8e43a
--- /dev/null
+++ b/server/templates/package_c.html
@@ -0,0 +1,6 @@
+$def with (cat, pdata)
+$var title: $cat
+
+No. of hosts: $pdata['HOST_COUNT']</br>
+No. of category-packages: $pdata['CP_COUNT']</br>
+No. of category-package-versions: $pdata['CPV_COUNT']</br>
diff --git a/server/templates/package_cp.html b/server/templates/package_cp.html
new file mode 100644
index 0000000..1f24f8e
--- /dev/null
+++ b/server/templates/package_cp.html
@@ -0,0 +1,5 @@
+$def with (cat, pkg, pdata)
+$var title: $cat/$pkg
+
+No. of hosts: $pdata['HOST_COUNT']</br>
+No. of category-package-versions: $pdata['CPV_COUNT']</br>
diff --git a/server/templates/package_cpv.html b/server/templates/package_cpv.html
new file mode 100644
index 0000000..4abb62a
--- /dev/null
+++ b/server/templates/package_cpv.html
@@ -0,0 +1,4 @@
+$def with (cat, pkg, ver, pdata)
+$var title: $cat/$pkg-$ver
+
+No. of hosts: $pdata['HOST_COUNT']</br>
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [gentoo-commits] proj/gentoostats:master commit in: server/, server/templates/
@ 2011-07-07 19:40 Vikraman Choudhury
0 siblings, 0 replies; 10+ messages in thread
From: Vikraman Choudhury @ 2011-07-07 19:40 UTC (permalink / raw
To: gentoo-commits
commit: 78fb9b4a76433d166ef20091a598105075eb4265
Author: Vikraman Choudhury <vikraman.choudhury <AT> gmail <DOT> com>
AuthorDate: Thu Jul 7 19:37:12 2011 +0000
Commit: Vikraman Choudhury <vikraman.choudhury <AT> gmail <DOT> com>
CommitDate: Thu Jul 7 19:37:12 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoostats.git;a=commit;h=78fb9b4a
add top C,CP,CPV to /package pages
---
server/package.py | 131 ++++++++++++++++++++++++++++---------
server/templates/package.html | 9 +++
server/templates/package_c.html | 10 +++
server/templates/package_cp.html | 11 +++
4 files changed, 129 insertions(+), 32 deletions(-)
diff --git a/server/package.py b/server/package.py
index 8f23daf..4ac7aa2 100644
--- a/server/package.py
+++ b/server/package.py
@@ -1,74 +1,141 @@
+import web
import helpers
from config import render, db
class Package(object):
def GET(self, *args):
+ try:
+ top = int(web.input(top="5").top)
+ except ValueError:
+ top = 5
l = len(args)
if l == 0:
- return self.__GET()
+ return self.__GET(top)
elif l == 1:
- return self.__GET_C(args[0])
+ return self.__GET_C(top, args[0])
elif l == 2:
cpv = helpers.pkgsplit(args[0] + '/' + args[1])
if cpv['ver'] == '':
- return self.__GET_CP(cpv['cat'], cpv['pkg'])
+ return self.__GET_CP(top, cpv['cat'], cpv['pkg'])
else:
return self.__GET_CPV(cpv['cat'], cpv['pkg'], cpv['ver'])
else:
return config.internalerror()
- def __GET(self):
- pquery = db.query('SELECT COUNT(DISTINCT UUID) AS HOST_COUNT,\
+ def __GET(self, top):
+ p_query = db.query('SELECT COUNT(DISTINCT UUID) AS HOST_COUNT,\
COUNT(DISTINCT CAT) AS C_COUNT,\
COUNT(DISTINCT CAT,PKG) AS CP_COUNT,\
COUNT(DISTINCT CAT,PKG,VER) AS CPV_COUNT\
FROM INSTALLED_PACKAGES RIGHT OUTER JOIN PACKAGES\
ON INSTALLED_PACKAGES.PKEY = PACKAGES.PKEY')
- t = pquery[0]
- pdata = {
- 'HOST_COUNT':t['HOST_COUNT'],
- 'C_COUNT':t['C_COUNT'],
- 'CP_COUNT':t['CP_COUNT'],
- 'CPV_COUNT':t['CPV_COUNT']
+ p_tuple = p_query[0]
+ p_data = {
+ 'HOST_COUNT':p_tuple['HOST_COUNT'],
+ 'C_COUNT':p_tuple['C_COUNT'],
+ 'CP_COUNT':p_tuple['CP_COUNT'],
+ 'CPV_COUNT':p_tuple['CPV_COUNT'],
+ 'TOP_C':self.__top(top)
}
- return render.package(pdata)
+ return render.package(p_data)
- def __GET_C(self, cat):
- pquery = db.query('SELECT COUNT(DISTINCT UUID) AS HOST_COUNT,\
+ def __GET_C(self, top, cat):
+ p_query = db.query('SELECT COUNT(DISTINCT UUID) AS HOST_COUNT,\
COUNT(DISTINCT CAT,PKG) AS CP_COUNT,\
COUNT(DISTINCT CAT,PKG,VER) AS CPV_COUNT\
FROM INSTALLED_PACKAGES RIGHT OUTER JOIN PACKAGES\
ON INSTALLED_PACKAGES.PKEY = PACKAGES.PKEY\
WHERE CAT=$cat', vars={'cat':cat})
- t = pquery[0]
- pdata = {
- 'HOST_COUNT':t['HOST_COUNT'],
- 'CP_COUNT':t['CP_COUNT'],
- 'CPV_COUNT':t['CPV_COUNT']
+ p_tuple = p_query[0]
+ p_data = {
+ 'HOST_COUNT':p_tuple['HOST_COUNT'],
+ 'CP_COUNT':p_tuple['CP_COUNT'],
+ 'CPV_COUNT':p_tuple['CPV_COUNT'],
+ 'TOP_CP':self.__top(top, cat)
}
- return render.package_c(cat, pdata)
+ return render.package_c(cat, p_data)
- def __GET_CP(self, cat, pkg):
- pquery = db.query('SELECT COUNT(DISTINCT UUID) AS HOST_COUNT,\
+ def __GET_CP(self, top, cat, pkg):
+ p_query = db.query('SELECT COUNT(DISTINCT UUID) AS HOST_COUNT,\
COUNT(DISTINCT CAT,PKG,VER) AS CPV_COUNT\
FROM INSTALLED_PACKAGES RIGHT OUTER JOIN PACKAGES\
ON INSTALLED_PACKAGES.PKEY = PACKAGES.PKEY\
WHERE CAT=$cat AND PKG=$pkg', vars={'cat':cat,'pkg':pkg})
- t = pquery[0]
- pdata = {
- 'HOST_COUNT':t['HOST_COUNT'],
- 'CPV_COUNT':t['CPV_COUNT']
+ p_tuple = p_query[0]
+ p_data = {
+ 'HOST_COUNT':p_tuple['HOST_COUNT'],
+ 'CPV_COUNT':p_tuple['CPV_COUNT'],
+ 'TOP_CPV':self.__top(top, cat, pkg)
}
- return render.package_cp(cat, pkg, pdata)
+ return render.package_cp(cat, pkg, p_data)
def __GET_CPV(self, cat, pkg, ver):
- pquery = db.query('SELECT COUNT(DISTINCT UUID) AS HOST_COUNT\
+ p_query = db.query('SELECT COUNT(DISTINCT UUID) AS HOST_COUNT\
FROM INSTALLED_PACKAGES RIGHT OUTER JOIN PACKAGES\
ON INSTALLED_PACKAGES.PKEY = PACKAGES.PKEY\
WHERE CAT=$cat AND PKG=$pkg AND VER=$ver', vars={'cat':cat,'pkg':pkg,'ver':ver})
- t = pquery[0]
- pdata = {
- 'HOST_COUNT':t['HOST_COUNT'],
+ p_tuple = p_query[0]
+ p_data = {
+ 'HOST_COUNT':p_tuple['HOST_COUNT'],
}
- return render.package_cpv(cat, pkg, ver, pdata)
+ return render.package_cpv(cat, pkg, ver, p_data)
+
+ def __top(self, count, *args):
+ t_list = list()
+ if len(args) == 0:
+ tc_query = db.query('SELECT CAT,COUNT(DISTINCT UUID) AS HOST_COUNT\
+ FROM INSTALLED_PACKAGES RIGHT OUTER JOIN PACKAGES\
+ ON INSTALLED_PACKAGES.PKEY = PACKAGES.PKEY\
+ GROUP BY CAT\
+ ORDER BY HOST_COUNT DESC,CAT')
+ for idx in range(0,count):
+ try:
+ tc_tuple = tc_query[idx]
+ t_list.append({
+ 'CAT':tc_tuple['CAT'],
+ 'HOST_COUNT':tc_tuple['HOST_COUNT']
+ })
+ except IndexError:
+ break
+
+ elif len(args) == 1:
+ tcp_query = db.query('SELECT CAT,PKG,COUNT(DISTINCT UUID) AS HOST_COUNT\
+ FROM INSTALLED_PACKAGES RIGHT OUTER JOIN PACKAGES\
+ ON INSTALLED_PACKAGES.PKEY = PACKAGES.PKEY\
+ WHERE CAT=$cat\
+ GROUP BY CAT,PKG\
+ ORDER BY HOST_COUNT DESC,CAT,PKG',
+ vars={'cat':args[0]})
+ for idx in range(0,count):
+ try:
+ tcp_tuple = tcp_query[idx]
+ t_list.append({
+ 'CAT':tcp_tuple['CAT'],
+ 'PKG':tcp_tuple['PKG'],
+ 'HOST_COUNT':tcp_tuple['HOST_COUNT']
+ })
+ except IndexError:
+ break
+
+ elif len(args) == 2:
+ tcpv_query = db.query('SELECT CAT,PKG,VER,COUNT(DISTINCT UUID) AS HOST_COUNT\
+ FROM INSTALLED_PACKAGES RIGHT OUTER JOIN PACKAGES\
+ ON INSTALLED_PACKAGES.PKEY = PACKAGES.PKEY\
+ WHERE CAT=$cat AND PKG=$pkg\
+ GROUP BY CAT,PKG,VER\
+ ORDER BY HOST_COUNT DESC,CAT,PKG,VER',
+ vars={'cat':args[0],'pkg':args[1]})
+ for idx in range(0,count):
+ try:
+ tcpv_tuple = tcpv_query[idx]
+ t_list.append({
+ 'CAT':tcpv_tuple['CAT'],
+ 'PKG':tcpv_tuple['PKG'],
+ 'VER':tcpv_tuple['VER'],
+ 'HOST_COUNT':tcpv_tuple['HOST_COUNT']
+ })
+ except IndexError:
+ break
+
+ return t_list
diff --git a/server/templates/package.html b/server/templates/package.html
index ca8ec96..f1a4e5c 100644
--- a/server/templates/package.html
+++ b/server/templates/package.html
@@ -5,3 +5,12 @@ No. of hosts: $pdata['HOST_COUNT']</br>
No. of categories: $pdata['C_COUNT']</br>
No. of category-packages: $pdata['CP_COUNT']</br>
No. of category-package-versions: $pdata['CPV_COUNT']</br>
+Top Categories:</br>
+<table border="1">
+ <tr>
+ <th>Category</th>
+ <th>Hosts</th>
+ </tr>
+ $for p in pdata['TOP_C']:
+ <tr><td>$p['CAT']</td><td>$p['HOST_COUNT']</td></tr>
+</table>
diff --git a/server/templates/package_c.html b/server/templates/package_c.html
index 1d8e43a..8247173 100644
--- a/server/templates/package_c.html
+++ b/server/templates/package_c.html
@@ -4,3 +4,13 @@ $var title: $cat
No. of hosts: $pdata['HOST_COUNT']</br>
No. of category-packages: $pdata['CP_COUNT']</br>
No. of category-package-versions: $pdata['CPV_COUNT']</br>
+Top CPs:</br>
+<table border="1">
+ <tr>
+ <th>Category</th>
+ <th>Package</th>
+ <th>Hosts</th>
+ </tr>
+ $for p in pdata['TOP_CP']:
+ <tr><td>$p['CAT']</td><td>$p['PKG']</td><td>$p['HOST_COUNT']</td></tr>
+</table>
diff --git a/server/templates/package_cp.html b/server/templates/package_cp.html
index 1f24f8e..30fdb25 100644
--- a/server/templates/package_cp.html
+++ b/server/templates/package_cp.html
@@ -3,3 +3,14 @@ $var title: $cat/$pkg
No. of hosts: $pdata['HOST_COUNT']</br>
No. of category-package-versions: $pdata['CPV_COUNT']</br>
+Top CPVs:</br>
+<table border="1">
+ <tr>
+ <th>Category</th>
+ <th>Package</th>
+ <th>Version</th>
+ <th>Hosts</th>
+ </tr>
+ $for p in pdata['TOP_CPV']:
+ <tr><td>$p['CAT']</td><td>$p['PKG']</td><td>$p['VER']</td><td>$p['HOST_COUNT']</td></tr>
+</table>
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [gentoo-commits] proj/gentoostats:master commit in: server/, server/templates/
@ 2011-07-09 17:09 Vikraman Choudhury
0 siblings, 0 replies; 10+ messages in thread
From: Vikraman Choudhury @ 2011-07-09 17:09 UTC (permalink / raw
To: gentoo-commits
commit: 304488f520ecbcea352283a9b5c0c3c41ddf05b5
Author: Vikraman Choudhury <vikraman.choudhury <AT> gmail <DOT> com>
AuthorDate: Sat Jul 9 17:09:25 2011 +0000
Commit: Vikraman Choudhury <vikraman.choudhury <AT> gmail <DOT> com>
CommitDate: Sat Jul 9 17:09:25 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoostats.git;a=commit;h=304488f5
per useflag stats
---
server/app.py | 3 +-
server/templates/use.html | 11 +-------
server/templates/use_useflag.html | 8 ++++++
server/use.py | 48 ++++++++++++++++++++++++++++++++----
4 files changed, 54 insertions(+), 16 deletions(-)
diff --git a/server/app.py b/server/app.py
index 94dffdd..fa5d6a4 100755
--- a/server/app.py
+++ b/server/app.py
@@ -22,12 +22,13 @@ urls = (
r'/mirror', 'Mirror',
r'/feature', 'Feature',
r'/keyword', 'Keyword',
- r'/use', 'Use',
r'/repo', 'Repo',
r'/lang', 'Lang',
r'/package/(.+)/(.+)', 'Package',
r'/package/(.+)', 'Package',
r'/package', 'Package',
+ r'/use/(.+)', 'Use',
+ r'/use', 'Use',
r'/host/(.+)', 'Host'
)
diff --git a/server/templates/use.html b/server/templates/use.html
index 209f8f8..bd2a3f7 100644
--- a/server/templates/use.html
+++ b/server/templates/use.html
@@ -1,11 +1,4 @@
$def with (use_data)
-$var title: Use
+$var title: Useflags
-<table border="1">
- <tr>
- <th>Use</th>
- <th>Hosts</th>
- </tr>
- $for use in use_data.keys():
- <tr><td>$use</td><td>$use_data[use]['HOSTS']</td></tr>
-</table>
+No. of useflags: $use_data['USE_COUNT']
diff --git a/server/templates/use_useflag.html b/server/templates/use_useflag.html
new file mode 100644
index 0000000..4d27b4a
--- /dev/null
+++ b/server/templates/use_useflag.html
@@ -0,0 +1,8 @@
+$def with (useflag, use_data)
+$var title: Useflags
+
+Useflag: $useflag</br>
+Globally enabled: $use_data['GLOBAL_COUNT'] hosts</br>
+Enabled: $use_data['PLUS_COUNT'] packages</br>
+Disabled: $use_data['MINUS_COUNT'] packages</br>
+Unset: $use_data['UNSET_COUNT'] packages</br>
diff --git a/server/use.py b/server/use.py
index dfdcfaf..5b7a54d 100644
--- a/server/use.py
+++ b/server/use.py
@@ -2,9 +2,45 @@
from config import render, db
class Use(object):
- def GET(self):
- use_count = db.query('SELECT USEFLAG,COUNT(UUID) AS HOSTS FROM GLOBAL_USEFLAGS NATURAL JOIN USEFLAGS GROUP BY USEFLAG')
- use_data = dict()
- for t in use_count:
- use_data[t['USEFLAG']] = {'HOSTS':t['HOSTS']}
- return render.use(use_data)
+ def GET(self, *args):
+ l = len(args)
+ if l == 0:
+ use_query = db.query('SELECT COUNT(DISTINCT UKEY) AS USE_COUNT FROM USEFLAGS')
+ use_tuple = use_query[0]
+ use_data = {'USE_COUNT':use_tuple['USE_COUNT']}
+ return render.use(use_data)
+
+ elif l == 1:
+ global_use_query = db.query('SELECT COUNT(DISTINCT UUID) AS GLOBAL_COUNT\
+ FROM GLOBAL_USEFLAGS RIGHT OUTER JOIN USEFLAGS\
+ ON GLOBAL_USEFLAGS.UKEY = USEFLAGS.UKEY\
+ WHERE USEFLAG=$useflag', vars={'useflag':args[0]})
+ plus_use_query = db.query('SELECT COUNT(DISTINCT IPKEY) AS PLUS_COUNT\
+ FROM PLUS_USEFLAGS RIGHT OUTER JOIN USEFLAGS\
+ ON PLUS_USEFLAGS.UKEY = USEFLAGS.UKEY\
+ WHERE USEFLAG=$useflag', vars={'useflag':args[0]})
+ minus_use_query = db.query('SELECT COUNT(DISTINCT IPKEY) AS MINUS_COUNT\
+ FROM MINUS_USEFLAGS RIGHT OUTER JOIN USEFLAGS\
+ ON MINUS_USEFLAGS.UKEY = USEFLAGS.UKEY\
+ WHERE USEFLAG=$useflag', vars={'useflag':args[0]})
+ unset_use_query = db.query('SELECT COUNT(DISTINCT IPKEY) AS UNSET_COUNT\
+ FROM UNSET_USEFLAGS RIGHT OUTER JOIN USEFLAGS\
+ ON UNSET_USEFLAGS.UKEY = USEFLAGS.UKEY\
+ WHERE USEFLAG=$useflag', vars={'useflag':args[0]})
+
+ global_use_tuple = global_use_query[0]
+ plus_use_tuple = plus_use_query[0]
+ minus_use_tuple = minus_use_query[0]
+ unset_use_tuple = unset_use_query[0]
+
+ use_data = {
+ 'GLOBAL_COUNT':global_use_tuple['GLOBAL_COUNT'],
+ 'PLUS_COUNT':plus_use_tuple['PLUS_COUNT'],
+ 'MINUS_COUNT':minus_use_tuple['MINUS_COUNT'],
+ 'UNSET_COUNT':unset_use_tuple['UNSET_COUNT']
+ }
+
+ return render.use_useflag(args[0], use_data)
+
+ else:
+ return config.internalerror()
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [gentoo-commits] proj/gentoostats:master commit in: server/, server/templates/
@ 2011-07-17 21:51 Vikraman Choudhury
0 siblings, 0 replies; 10+ messages in thread
From: Vikraman Choudhury @ 2011-07-17 21:51 UTC (permalink / raw
To: gentoo-commits
commit: 2dda88db0716efa9a42ab703a70a49533c2852b9
Author: Vikraman Choudhury <vikraman.choudhury <AT> gmail <DOT> com>
AuthorDate: Sun Jul 17 21:50:38 2011 +0000
Commit: Vikraman Choudhury <vikraman.choudhury <AT> gmail <DOT> com>
CommitDate: Sun Jul 17 21:50:38 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoostats.git;a=commit;h=2dda88db
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
urls = (
r'', 'Index',
@@ -30,7 +31,8 @@ urls = (
r'/package', 'Package',
r'/use/(.+)', 'Use',
r'/use', 'Use',
- r'/host/(.+)', 'Host'
+ r'/host/(.+)', 'Host',
+ r'/search', 'Search'
)
app = web.application(urls, globals(), autoreload=True)
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 = ['CAT', 'PKG', 'VER', 'REPO', 'COUNT(DISTINCT UUID) AS HOSTS']
+order_by = ['HOSTS DESC','CAT', 'PKG', 'VER', 'REPO']
+group_by = ['CAT', 'PKG', 'VER', 'REPO']
+which = ['PACKAGES','INSTALLED_PACKAGES','REPOSITORIES']
+
+class Search(object):
+
+ def GET(self):
+ self.args = web.input(cat='any', pkg='any', ver='any', repo='any')
+
+ try:
+ self.min_hosts = int(web.input(min_hosts=-1).min_hosts)
+ except ValueError:
+ self.min_hosts = -1
+
+ try:
+ self.max_hosts = int(web.input(max_hosts=-1).max_hosts)
+ except ValueError:
+ self.max_hosts = -1
+
+ where = self._build_where()
+ having = self._build_having()
+ query = self._build_query(where, having)
+ search_tuples = db.query(query, vars={
+ '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 = ' '
+ query = ''
+ query += 'SELECT' + sep + ','.join(what) + sep
+ query += 'FROM' + sep + (sep + 'NATURAL LEFT OUTER JOIN' + sep).join(which) + sep
+ if len(where) != 0:
+ query += 'WHERE' + sep
+ query += (sep + 'AND' + sep).join(where)
+ query += sep
+ query += 'GROUP BY' + sep + ','.join(group_by) + sep
+ if len(having) != 0:
+ query += 'HAVING' + sep
+ query += (sep + 'AND' + sep).join(having)
+ query += sep
+ query += 'ORDER BY' + sep + ','.join(order_by) + sep
+ return query.strip()
+
+ def _build_where(self):
+ where = []
+ cat = string.lower(self.args.cat)
+ if cat != 'any':
+ where.append('CAT=$cat')
+
+ pkg = string.lower(self.args.pkg)
+ if pkg != 'any':
+ where.append('PKG=$pkg')
+
+ ver = string.lower(self.args.ver)
+ if ver != 'any':
+ where.append('VER=$ver')
+
+ repo = string.lower(self.args.repo)
+ if repo != 'any':
+ where.append('REPO=$repo')
+ return where
+
+ def _build_having(self):
+ having = []
+ if self.min_hosts != -1:
+ having.append('HOSTS>=$min_hosts')
+ if self.max_hosts != -1:
+ having.append('HOSTS<=$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
+
+<table border="1">
+ <tr>
+ <th>Category</th>
+ <th>Package</th>
+ <th>Version</th>
+ <th>Repository</th>
+ <th>Hosts</th>
+ </tr>
+ $for t in tuples:
+ <tr><td>$t['CAT']</td><td>$t['PKG']</td><td>$t['VER']</td><td>$t['REPO']</td><td>$t['HOSTS']</td></tr>
+</table>
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [gentoo-commits] proj/gentoostats:master commit in: server/, server/templates/
@ 2011-08-03 21:52 Vikraman Choudhury
0 siblings, 0 replies; 10+ messages in thread
From: Vikraman Choudhury @ 2011-08-03 21:52 UTC (permalink / raw
To: gentoo-commits
commit: ff90e73798944f2d3a616729f8ab159d48366247
Author: Vikraman Choudhury <vikraman.choudhury <AT> gmail <DOT> com>
AuthorDate: Wed Aug 3 21:51:32 2011 +0000
Commit: Vikraman Choudhury <vikraman.choudhury <AT> gmail <DOT> com>
CommitDate: Wed Aug 3 21:51:32 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoostats.git;a=commit;h=ff90e737
add input form for host uuid
---
server/app.py | 1 +
server/host.py | 23 +++++++++++++++++++++--
server/templates/host_input.html | 7 +++++++
3 files changed, 29 insertions(+), 2 deletions(-)
diff --git a/server/app.py b/server/app.py
index fcef84f..0cd4b9b 100755
--- a/server/app.py
+++ b/server/app.py
@@ -32,6 +32,7 @@ urls = (
r'/use/(.+)', 'Use',
r'/use', 'Use',
r'/host/(.+)', 'Host',
+ r'/host', 'Host',
r'/search', 'Search'
)
diff --git a/server/host.py b/server/host.py
index fab706c..7fd8132 100644
--- a/server/host.py
+++ b/server/host.py
@@ -3,11 +3,22 @@ import web
import json
import helpers
import config
+from web import form
from config import render, db
+host_form = form.Form(
+ form.Textbox('uuid', description = 'UUID'),
+ form.Button('submit', description = 'Submit')
+ )
+
class Host(object):
- def GET(self, str_uuid):
+ def GET(self, *args):
+ if len(args) == 0:
+ form = host_form()
+ return render.host_input(form)
+
+ str_uuid = args[0]
if not helpers.is_uuid(str_uuid):
return config.notfound()
@@ -60,7 +71,15 @@ class Host(object):
else:
return render.host(host_data)
- def POST(self, str_uuid):
+ def POST(self, *args):
+ if len(args) == 0:
+ form = host_form()
+ if not form.validates():
+ return render.host_input(form)
+ else:
+ raise web.seeother('/host/' + form['uuid'].value)
+
+ str_uuid = args[0]
post_data = json.JSONDecoder().decode(web.data())
#TODO: Handle exceptions
diff --git a/server/templates/host_input.html b/server/templates/host_input.html
new file mode 100644
index 0000000..ae0e2ec
--- /dev/null
+++ b/server/templates/host_input.html
@@ -0,0 +1,7 @@
+$def with (form)
+$var title: Host
+
+<h2>Input host uuid</h2>
+<form method="POST">
+ $:form.render()
+</form>
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [gentoo-commits] proj/gentoostats:master commit in: server/, server/templates/
@ 2011-08-03 23:45 Vikraman Choudhury
0 siblings, 0 replies; 10+ messages in thread
From: Vikraman Choudhury @ 2011-08-03 23:45 UTC (permalink / raw
To: gentoo-commits
commit: 6a6a09d88f50282b910ef82c47bb4bb21cd48556
Author: Vikraman Choudhury <vikraman.choudhury <AT> gmail <DOT> com>
AuthorDate: Wed Aug 3 23:45:24 2011 +0000
Commit: Vikraman Choudhury <vikraman.choudhury <AT> gmail <DOT> com>
CommitDate: Wed Aug 3 23:45:24 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoostats.git;a=commit;h=6a6a09d8
updates to index page, trying out relative urls
---
server/index.py | 16 +++++++++++++++-
server/templates/index.html | 26 +++++++++++++-------------
2 files changed, 28 insertions(+), 14 deletions(-)
diff --git a/server/index.py b/server/index.py
index e6a63f5..2204bd3 100644
--- a/server/index.py
+++ b/server/index.py
@@ -1,8 +1,22 @@
+from web import form
from config import render, db
+search_form = form.Form(
+ form.Textbox('cat', value = 'any', description = 'Category'),
+ form.Textbox('pkg', value = 'any', description = 'Package'),
+ form.Textbox('ver', value = 'any', description = 'Version'),
+ form.Textbox('repo', value = 'any', description = 'Repository'),
+ form.Textbox('min_hosts', value = 'any', description = 'Minimum hosts'),
+ form.Textbox('max_hosts', value = 'any', description = 'Maximum hosts'),
+ form.Button('Search', type = 'submit')
+ )
+
class Index(object):
def GET(self):
hosts = db.select('HOSTS', what='COUNT(UUID) as COUNT')
count = hosts[0]['COUNT']
- return render.index(count)
+
+ form = search_form()
+
+ return render.index(count, form)
diff --git a/server/templates/index.html b/server/templates/index.html
index e601b26..24f7ea7 100644
--- a/server/templates/index.html
+++ b/server/templates/index.html
@@ -1,4 +1,4 @@
-$def with (count)
+$def with (count, form)
$var title: Gentoostats
Welcome to the gentoostats webapp <br/>
@@ -7,18 +7,18 @@ Number of hosts: $count<br/>
<h2>Statistics</h2>
<ul>
- <li>Arch statistics: <a href="/gentoostats/arch">/arch</a></li>
- <li>Portage feature statistics: <a href="/gentoostats/feature">/feature</a></li>
- <li>Keyword statistics: <a href="/gentoostats/keyword">/keyword</a></li>
- <li>Language statistics: <a href="/gentoostats/lang">/lang</a></li>
- <li>Mirror statistics: <a href="/gentoostats/mirror">/mirror</a></li>
- <li>Package statistics: <a href="/gentoostats/package">/package</a></li>
- <li>Profile statistics: <a href="/gentoostats/profile">/profile</a></li>
- <li>Repository statistics: <a href="/gentoostats/repo">/repo</a></li>
- <li>Useflag statistics: <a href="/gentoostats/use">/use</a></li>
+ <li>Arch statistics: <a href="arch">/arch</a></li>
+ <li>Portage feature statistics: <a href="feature">/feature</a></li>
+ <li>Keyword statistics: <a href="keyword">/keyword</a></li>
+ <li>Language statistics: <a href="lang">/lang</a></li>
+ <li>Mirror statistics: <a href="mirror">/mirror</a></li>
+ <li>Package statistics: <a href="package">/package</a></li>
+ <li>Profile statistics: <a href="profile">/profile</a></li>
+ <li>Repository statistics: <a href="repo">/repo</a></li>
+ <li>Useflag statistics: <a href="use">/use</a></li>
</ul>
<h2>Package search</h2>
-<ul>
- <li><a href="/gentoostats/search">/search</a></li>
-</ul>
+<form method="GET" action="/gentoostats/search">
+ $:form.render()
+</form>
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [gentoo-commits] proj/gentoostats:master commit in: server/, server/templates/
@ 2011-08-11 20:41 Vikraman Choudhury
0 siblings, 0 replies; 10+ messages in thread
From: Vikraman Choudhury @ 2011-08-11 20:41 UTC (permalink / raw
To: gentoo-commits
commit: c6a27937f63a7629aeb235fb5ef8bef5c66aee78
Author: Vikraman Choudhury <vikraman.choudhury <AT> gmail <DOT> com>
AuthorDate: Thu Aug 11 20:40:36 2011 +0000
Commit: Vikraman Choudhury <vikraman.choudhury <AT> gmail <DOT> com>
CommitDate: Thu Aug 11 20:40:36 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoostats.git;a=commit;h=c6a27937
add barcharts for /arch and /keyword
---
server/arch.py | 7 ++++++-
server/helpers.py | 25 +++++++++++++++++++++++++
server/kwd.py | 7 ++++++-
server/templates/arch.html | 4 +++-
server/templates/keyword.html | 4 +++-
5 files changed, 43 insertions(+), 4 deletions(-)
diff --git a/server/arch.py b/server/arch.py
index 20dde69..814c7c4 100644
--- a/server/arch.py
+++ b/server/arch.py
@@ -11,4 +11,9 @@ class Arch(object):
if helpers.is_json_request():
return helpers.serialize(arch_data)
else:
- return render.arch(arch_data)
+ x_ticklabels = arch_data.keys()
+ y_values = [ arch_data[a]['HOSTS'] for a in x_ticklabels ]
+ arch_plot = helpers.barchart(title = 'Hosts per arch', x_label = 'Arch',
+ y_label = 'Number of Hosts', x_ticklabels = x_ticklabels,
+ y_values = y_values)
+ return render.arch(arch_data, arch_plot)
diff --git a/server/helpers.py b/server/helpers.py
index a5977be..5b81cb3 100644
--- a/server/helpers.py
+++ b/server/helpers.py
@@ -3,8 +3,16 @@ import web
import json
import uuid
import re
+import StringIO
+import base64
from portage.versions import catpkgsplit
+# matplotlib requires a writable home directory
+import os
+os.environ['HOME'] = '/tmp'
+from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
+from matplotlib.figure import Figure
+
# check valid uuid
def is_uuid(uuid):
@@ -118,3 +126,20 @@ def serialize(object, human=True):
else:
indent = None
return json.JSONEncoder(indent=indent).encode(object)
+
+def barchart(title, x_label, x_ticklabels, y_label, y_values):
+ fig = Figure()
+ canvas = FigureCanvas(fig)
+ ind = range(len(y_values))
+
+ ax = fig.add_subplot(1, 1, 1)
+ ax.set_title(title)
+ ax.set_xlabel(x_label)
+ ax.set_ylabel(y_label)
+ ax.set_xticks(ind)
+ ax.set_xticklabels(x_ticklabels)
+ ax.bar(ind, y_values, align='center')
+
+ ret = StringIO.StringIO()
+ canvas.print_figure(ret)
+ return base64.b64encode(ret.getvalue())
diff --git a/server/kwd.py b/server/kwd.py
index b8c50cd..779ac61 100644
--- a/server/kwd.py
+++ b/server/kwd.py
@@ -11,4 +11,9 @@ class Keyword(object):
if helpers.is_json_request():
return helpers.serialize(keyword_data)
else:
- return render.keyword(keyword_data)
+ x_ticklabels = keyword_data.keys()
+ y_values = [ keyword_data[k]['PACKAGES'] for k in x_ticklabels ]
+ keyword_plot = helpers.barchart(title = 'Installed packages per keyword',
+ x_label = 'Keyword', y_label = 'Number of Packages',
+ x_ticklabels = x_ticklabels, y_values = y_values)
+ return render.keyword(keyword_data, keyword_plot)
diff --git a/server/templates/arch.html b/server/templates/arch.html
index 04ddcf6..8decac5 100644
--- a/server/templates/arch.html
+++ b/server/templates/arch.html
@@ -1,4 +1,4 @@
-$def with (arch_data)
+$def with (arch_data, arch_plot)
$var title: Arch
<table border="1">
@@ -9,3 +9,5 @@ $var title: Arch
$for arch in arch_data.keys():
<tr><td>$arch</td><td>$arch_data[arch]['HOSTS']</td></tr>
</table>
+
+<img src="data:image/png;base64,$arch_plot"/>
diff --git a/server/templates/keyword.html b/server/templates/keyword.html
index 2dee5ea..608693f 100644
--- a/server/templates/keyword.html
+++ b/server/templates/keyword.html
@@ -1,4 +1,4 @@
-$def with (keyword_data)
+$def with (keyword_data, keyword_plot)
$var title: Keyword
<table border="1">
@@ -10,3 +10,5 @@ $var title: Keyword
$for keyword in keyword_data.keys():
<tr><td>$keyword</td><td>$keyword_data[keyword]['HOSTS']</td><td>$keyword_data[keyword]['PACKAGES']</td></tr>
</table>
+
+<img src="data:image/png;base64,$keyword_plot" />
^ permalink raw reply related [flat|nested] 10+ messages in thread
end of thread, other threads:[~2011-08-11 20:41 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-03 18:04 [gentoo-commits] proj/gentoostats:master commit in: server/, server/templates/ Vikraman Choudhury
-- strict thread matches above, loose matches on Subject: below --
2011-08-11 20:41 Vikraman Choudhury
2011-08-03 23:45 Vikraman Choudhury
2011-08-03 21:52 Vikraman Choudhury
2011-07-17 21:51 Vikraman Choudhury
2011-07-09 17:09 Vikraman Choudhury
2011-07-07 19:40 Vikraman Choudhury
2011-07-07 16:02 Vikraman Choudhury
2011-06-14 17:43 Vikraman Choudhury
2011-05-06 14:42 Vikraman Choudhury
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox