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 1QWXf0-0006q5-2m for garchives@archives.gentoo.org; Tue, 14 Jun 2011 17:44:18 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 2D2881C17A; Tue, 14 Jun 2011 17:43:56 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id CD1211C17A for ; Tue, 14 Jun 2011 17:43:55 +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 1EFD11BC011 for ; Tue, 14 Jun 2011 17:43:55 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id 1491A80048 for ; Tue, 14 Jun 2011 17:43:54 +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: server/, server/templates/ X-VCS-Repository: proj/gentoostats X-VCS-Files: server/config.py server/helpers.py server/host.py server/index.py server/main.py server/post.py server/templates/host.html server/templates/index.html server/templates/stats.html X-VCS-Directories: server/ server/templates/ X-VCS-Committer: vikraman X-VCS-Committer-Name: Vikraman Choudhury X-VCS-Revision: f54a02be8f73be30e0607c8ca5c887a12f426c53 Date: Tue, 14 Jun 2011 17:43:54 +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: 8cad370f38da9fddc239d81b76e12811 commit: f54a02be8f73be30e0607c8ca5c887a12f426c53 Author: Vikraman Choudhury gmail com> AuthorDate: Tue Jun 14 17:43:08 2011 +0000 Commit: Vikraman Choudhury gmail com> CommitDate: Tue Jun 14 17:43:08 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/gentoostats.g= it;a=3Dcommit;h=3Df54a02be 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 =20 +db =3D web.database( + dbn=3D'mysql', + user=3D'gentoo', + pw=3D'gentoo', + db=3D'gentoostats' + ) + render =3D web.template.render('templates/', base=3D'layout') =20 +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 =20 +# check valid uuid + +def is_uuid(uuid): + regex =3D re.compile(r'^(\w{8})-(\w{4})-(\w{4})-(\w{4})-(\w{12})$') + return regex.search(uuid) + # convert uuid string to raw bytes =20 def uuidbin(string): @@ -31,59 +37,58 @@ def pkgsplit(pkgname): # lookup key and insert if not found =20 def get_kwkey(db, keyword): - db_keyword =3D db.select('keywords', vars=3D{'keyword':keyword}, where= =3D'keyword=3D$keyword') + db_keyword =3D db.select('KEYWORDS', vars=3D{'keyword':keyword}, where= =3D'KEYWORD=3D$keyword') if len(db_keyword): - kwkey =3D db_keyword[0].kwkey + kwkey =3D db_keyword[0]['KWKEY'] else: - kwkey =3D db.insert('keywords', keyword=3Dkeyword) + kwkey =3D db.insert('KEYWORDS', KEYWORD=3Dkeyword) return kwkey =20 def get_lkey(db, lang): - db_lang =3D db.select('lang', vars=3D{'lang':lang}, where=3D'lang=3D$l= ang') + db_lang =3D db.select('LANG', vars=3D{'lang':lang}, where=3D'LANG=3D$l= ang') if len(db_lang): - lkey =3D db_lang[0].lkey + lkey =3D db_lang[0]['LKEY'] else: - lkey =3D db.insert('lang', lang=3Dlang) + lkey =3D db.insert('LANG', LANG=3Dlang) return lkey =20 def get_fkey(db, feature): - db_feature =3D db.select('features', vars=3D{'feature':feature}, where= =3D'feature=3D$feature') + db_feature =3D db.select('FEATURES', vars=3D{'feature':feature}, where= =3D'FEATURE=3D$feature') if len(db_feature): - fkey =3D db_feature[0].fkey + fkey =3D db_feature[0]['FKEY'] else: - fkey =3D db.insert('features', feature=3Dfeature) + fkey =3D db.insert('FEATURES', FEATURE=3Dfeature) return fkey =20 def get_mkey(db, mirror): - db_mirror =3D db.select('gentoo_mirrors', vars=3D{'mirror':mirror}, wh= ere=3D'mirror=3D$mirror') + db_mirror =3D db.select('GENTOO_MIRRORS', vars=3D{'mirror':mirror}, wh= ere=3D'MIRROR=3D$mirror') if len(db_mirror): - mkey =3D db_mirror[0].mkey + mkey =3D db_mirror[0]['MKEY'] else: - mkey =3D db.insert('gentoo_mirrors', mirror=3Dmirror) + mkey =3D db.insert('GENTOO_MIRRORS', MIRROR=3Dmirror) return mkey =20 def get_ukey(db, useflag): - db_useflag =3D db.select('useflags', vars=3D{'useflag':useflag}, where= =3D'useflag=3D$useflag') + db_useflag =3D db.select('USEFLAGS', vars=3D{'useflag':useflag}, where= =3D'USEFLAG=3D$useflag') if len(db_useflag): - ukey =3D db_useflag[0].ukey + ukey =3D db_useflag[0]['UKEY'] else: - ukey =3D db.insert('useflags', useflag=3Duseflag) + ukey =3D db.insert('USEFLAGS', USEFLAG=3Duseflag) return ukey =20 def get_pkey(db, package): cpv =3D pkgsplit(package) - db_package =3D db.select('packages', vars=3Dcpv, where=3D'cat=3D$cat a= nd pkg=3D$pkg and ver=3D$ver') + db_package =3D db.select('PACKAGES', vars=3Dcpv, where=3D'CAT=3D$cat a= nd PKG=3D$pkg and VER=3D$ver') if len(db_package): - pkey =3D db_package[0].pkey + pkey =3D db_package[0]['PKEY'] else: - pkey =3D db.insert('packages', cat=3Dcpv['cat'], pkg=3Dcpv['pkg'], ver=3D= cpv['ver']) + pkey =3D db.insert('PACKAGES', CAT=3Dcpv['cat'], PKG=3Dcpv['pkg'], VER=3D= cpv['ver']) return pkey =20 def get_rkey(db, repo): - db_repo =3D db.select('repositories', vars=3D{'repo':repo}, where=3D'r= epo=3D$repo') + db_repo =3D db.select('REPOSITORIES', vars=3D{'repo':repo}, where=3D'R= EPO=3D$repo') if len(db_repo): - rkey =3D db_repo[0].rkey + rkey =3D db_repo[0]['RKEY'] else: - rkey =3D db.insert('repositories', repo=3Drepo) + rkey =3D db.insert('REPOSITORIES', REPO=3Drepo) 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 =3D helpers.uuidbin(str_uuid) + hosts =3D db.select('HOSTS', vars=3D{'uuid':uuid}, where=3D'UUID=3D$uui= d', what=3D'UUID') + if len(hosts) =3D=3D 0: + return config.notfound() + + get_data =3D dict() + get_data['UUID'] =3D str_uuid + + env =3D db.select('ENV', vars=3D{'uuid':uuid}, where=3D"UUID=3D$uuid") + e =3D env[0] + for var in ['PLATFORM','LASTSYNC','PROFILE','ARCH','CHOST','CFLAGS','CX= XFLAGS','FFLAGS','LDFLAGS','MAKEOPTS','SYNC']: + get_data[var] =3D e[var] +=09 + get_data['FEATURES'] =3D list() + features =3D db.query('SELECT FEATURE FROM HOST_FEATURES NATURAL JOIN F= EATURES WHERE UUID=3D$uuid', vars=3D{'uuid':uuid}) + for f in features: + get_data['FEATURES'].append(f['FEATURE']) + + get_data['ACCEPT_KEYWORDS'] =3D list() + keywords =3D db.query('SELECT KEYWORD FROM GLOBAL_KEYWORDS NATURAL JOIN= KEYWORDS WHERE UUID=3D$uuid', vars=3D{'uuid':uuid}) + for k in keywords: + get_data['ACCEPT_KEYWORDS'].append(k['KEYWORD']) +=09 + get_data['USE'] =3D list() + useflags =3D db.query('SELECT USEFLAG FROM GLOBAL_USEFLAGS NATURAL JOIN= USEFLAGS WHERE UUID=3D$uuid', vars=3D{'uuid':uuid}) + for u in useflags: + get_data['USE'].append(u['USEFLAG']) + + get_data['LANG'] =3D list() + lang =3D db.query('SELECT LANG FROM HOST_LANG NATURAL JOIN LANG WHERE U= UID=3D$uuid', vars=3D{'uuid':uuid}) + for l in lang: + get_data['LANG'].append(l['LANG']) + + get_data['GENTOO_MIRRORS'] =3D list() + mirrors =3D db.query('SELECT MIRROR FROM HOST_MIRRORS NATURAL JOIN GENT= OO_MIRRORS WHERE UUID=3D$uuid', vars=3D{'uuid':uuid}) + for m in mirrors: + get_data['GENTOO_MIRRORS'].append(m['MIRROR']) + + get_data['PACKAGES'] =3D dict() + packages =3D db.query('SELECT CAT, PKG, VER FROM INSTALLED_PACKAGES NAT= URAL JOIN PACKAGES WHERE UUID=3D$uuid ORDER BY CAT, PKG, VER', vars=3D{'u= uid':uuid}) + for p in packages: + cpv =3D p['CAT'] + '/' + p['PKG'] + '-' + p['VER'] + get_data['PACKAGES'][cpv] =3D dict() + + return render.host(get_data) + + def POST(self, str_uuid): + post_data =3D json.JSONDecoder().decode(web.data()) + + #TODO: Handle exceptions + if post_data['PROTOCOL'] !=3D 1: + return 'Unsupported protocol!' + + if post_data['AUTH']['UUID'] !=3D str_uuid: + return 'Invalid uuid!' + + uuid =3D helpers.uuidbin(str_uuid) + + # Insert in hosts + db_host =3D db.select('HOSTS', vars=3D{'uuid':uuid}, where=3D'UUID=3D$u= uid') + if len(db_host): + if post_data['AUTH']['PASSWD'] !=3D db_host[0]['PASSWD']: + return 'Wrong password!' + # This should delete all host entries from all tables + db.delete('HOSTS', vars=3D{'uuid':uuid}, where=3D'UUID=3D$uuid') + db.insert('HOSTS', UUID=3Duuid, PASSWD=3Dpost_data['AUTH']['PASSWD']) + + # Insert in env + db.insert('ENV', UUID=3Duuid, ARCH=3Dpost_data['ARCH'], CHOST=3Dpost_da= ta['CHOST'], CFLAGS=3Dpost_data['CFLAGS'], + CXXFLAGS=3Dpost_data['CXXFLAGS'], FFLAGS=3Dpost_data['FFLAGS'], LDFLAG= S=3Dpost_data['LDFLAGS'], + MAKEOPTS=3Dpost_data['MAKEOPTS'], SYNC=3Dpost_data['SYNC'], PLATFORM=3D= post_data['PLATFORM'], + PROFILE=3Dpost_data['PROFILE'], LASTSYNC=3Dpost_data['LASTSYNC']) + + # Insert in GLOBAL_KEYWORDS + for keyword in post_data['ACCEPT_KEYWORDS']: + kwkey =3D helpers.get_kwkey(db, keyword) + db.insert('GLOBAL_KEYWORDS', UUID=3Duuid, KWKEY=3Dkwkey) + + # Insert in HOST_LANG + for lang in post_data['LANG']: + lkey =3D helpers.get_lkey(db, lang) + db.insert('HOST_LANG', UUID=3Duuid, LKEY=3Dlkey) + + # Insert in HOST_FEATURES + for feature in post_data['FEATURES']: + fkey =3D helpers.get_fkey(db, feature) + db.insert('HOST_FEATURES', UUID=3Duuid, FKEY=3Dfkey) + + # Insert in HOST_MIRRORS + for mirror in post_data['GENTOO_MIRRORS']: + mkey =3D helpers.get_mkey(db, mirror) + db.insert('HOST_MIRRORS', UUID=3Duuid, MKEY=3Dmkey) + + # Insert in GLOBAL_USEFLAGS + for useflag in post_data['USE']: + ukey =3D helpers.get_ukey(db, useflag) + db.insert('GLOBAL_USEFLAGS', UUID=3Duuid, UKEY=3Dukey) + + # Handle PACKAGES + for package in post_data['PACKAGES'].keys(): + pkey =3D helpers.get_pkey(db, package) + post_data_pkg =3D post_data['PACKAGES'][package] + kwkey =3D helpers.get_kwkey(db, post_data_pkg['KEYWORD']) + rkey =3D helpers.get_rkey(db, post_data_pkg['REPO']) + + # Insert in INSTALLED_PACKAGES + ipkey =3D db.insert('INSTALLED_PACKAGES', UUID=3Duuid, PKEY=3Dpkey, B= UILD_TIME=3Dpost_data_pkg['BUILD_TIME'], + COUNTER=3Dpost_data_pkg['COUNTER'], KWKEY=3Dkwkey, RKEY=3Drkey, SI= ZE=3Dpost_data_pkg['SIZE']) + + # Insert in PLUS_USEFLAGS + for useflag in post_data_pkg['USE']['PLUS']: + ukey =3D helpers.get_ukey(db, useflag) + db.insert('PLUS_USEFLAGS', IPKEY=3Dipkey, UKEY=3Dukey) + + # Insert in MINUS_USEFLAGS + for useflag in post_data_pkg['USE']['MINUS']: + ukey =3D helpers.get_ukey(db, useflag) + db.insert('MINUS_USEFLAGS', IPKEY=3Dipkey, UKEY=3Dukey) + + # Insert in UNSET_USEFLAGS + for useflag in post_data_pkg['USE']['UNSET']: + ukey =3D helpers.get_ukey(db, useflag) + db.insert('UNSET_USEFLAGS', IPKEY=3Dipkey, UKEY=3Dukey) + + 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 =3D db.select('hosts', what=3D'count(uuid) as count') + count =3D 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 @@ =20 import web import config -import json from config import render -from post import handler +from index import Index +from host import Host =20 urls =3D ( - r'/', 'index', - r'/(.+)', 'stats' -) - -db =3D web.database( - dbn=3D'mysql', - user=3D'gentoo', - pw=3D'gentoo', - db=3D'gentoostats' - ) - -class index: - def GET(self): - hosts =3D db.select('hosts') - return render.index(hosts) - -class stats: - def GET(self, uuid): - if uuid =3D=3D 'favicon.ico': - return notfound() - hosts =3D db.select('hosts', vars=3D{'uuid':uuid}, where=3D"uuid=3D$= uuid") - env =3D db.select('env', vars=3D{'uuid':uuid}, where=3D"uuid=3D$uuid= ") - return render.stats(uuid, hosts, env) - - def POST(self, uuid): - post_data =3D 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' + ) =20 app =3D web.application(urls, globals()) =20 -app.notfound =3D notfound -app.internalerror =3D internalerror +app.notfound =3D config.notfound +app.internalerror =3D config.internalerror =20 if __name__ =3D=3D "__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'] !=3D 1: - return 'Unsupported protocol!' - - if data['AUTH']['UUID'] !=3D uuid_str: - return 'Invalid uuid!' - - uuid =3D uuidbin(uuid_str) - - # Insert in hosts - db_host =3D db.select('hosts', vars=3D{'uuid':uuid}, where=3D'uuid=3D$= uuid') - if len(db_host): - if data['AUTH']['PASSWD'] !=3D db_host[0].passwd: - return 'Wrong password!' - # This should delete all host entries from all tables - db.delete('hosts', vars=3D{'uuid':uuid}, where=3D'uuid=3D$uuid') - db.insert('hosts', uuid=3Duuid, passwd=3Ddata['AUTH']['PASSWD']) - - # Insert in env - db.insert('env', uuid=3Duuid, arch=3Ddata['ARCH'], chost=3Ddata['CHOST= '], cflags=3Ddata['CFLAGS'], - cxxflags=3Ddata['CXXFLAGS'], fflags=3Ddata['FFLAGS'], ldflags=3Ddata[= 'LDFLAGS'], - makeopts=3Ddata['MAKEOPTS'], sync=3Ddata['SYNC'], platform=3Ddata['PL= ATFORM'], - profile=3Ddata['PROFILE'], lastsync=3Ddata['LASTSYNC']) - - # Insert in global_keywords - for keyword in data['ACCEPT_KEYWORDS']: - kwkey =3D get_kwkey(db, keyword) - db.insert('global_keywords', uuid=3Duuid, kwkey=3Dkwkey) - - # Insert in host_lang - for lang in data['LANG']: - lkey =3D get_lkey(db, lang) - db.insert('host_lang', uuid=3Duuid, lkey=3Dlkey) - - # Insert in host_features - for feature in data['FEATURES']: - fkey =3D get_fkey(db, feature) - db.insert('host_features', uuid=3Duuid, fkey=3Dfkey) - - # Insert in host_mirrors - for mirror in data['GENTOO_MIRRORS']: - mkey =3D get_mkey(db, mirror) - db.insert('host_mirrors', uuid=3Duuid, mkey=3Dmkey) - - # Insert in global_useflags - for useflag in data['USE']: - ukey =3D get_ukey(db, useflag) - db.insert('global_useflags', uuid=3Duuid, ukey=3Dukey) - - # Handle packages - for package in data['PACKAGES'].keys(): - pkey =3D get_pkey(db, package) - data_pkg =3D data['PACKAGES'][package] - kwkey =3D get_kwkey(db, data_pkg['KEYWORD']) - rkey =3D get_rkey(db, data_pkg['REPO']) -=09 - # Insert in installed_packages - ipkey =3D db.insert('installed_packages', uuid=3Duuid, pkey=3Dpkey, bui= ld_time=3Ddata_pkg['BUILD_TIME'], - counter=3Ddata_pkg['COUNTER'], kwkey=3Dkwkey, rkey=3Drkey, size=3Ddata= _pkg['SIZE']) - - # Insert in plus_useflags - for useflag in data_pkg['USE']['PLUS']: - ukey =3D get_ukey(db, useflag) - db.insert('plus_useflags', ipkey=3Dipkey, ukey=3Dukey) -=09 - # Insert in minus_useflags - for useflag in data_pkg['USE']['MINUS']: - ukey =3D get_ukey(db, useflag) - db.insert('minus_useflags', ipkey=3Dipkey, ukey=3Dukey) - - # Insert in unset_useflags - for useflag in data_pkg['USE']['UNSET']: - ukey =3D get_ukey(db, useflag) - db.insert('unset_useflags', ipkey=3Dipkey, ukey=3Dukey) - - 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'] :

+
    +
  • Platform : $data['PLATFORM']
  • +
  • Profile : $data['PROFILE']
  • +
  • Timestamp of tree : $data['LASTSYNC']
  • +
  • ARCH : $data['ARCH']
  • +
  • CHOST : $data['CHOST']
  • +
  • CFLAGS : $data['CFLAGS']
  • +
  • CXXFLAGS : $data['CXXFLAGS']
  • +
  • FFLAGS : $data['FFLAGS']
  • +
  • LDLAGS : $data['LDFLAGS']
  • +
  • MAKEOPTS : $data['MAKEOPTS']
  • +
  • SYNC : $data['SYNC']
  • +
  • FEATURES : +
      +$for f in data['FEATURES']: +
    • $f
    • +
    +
  • +
  • ACCEPT_KEYWORDS : +
      +$for k in data['ACCEPT_KEYWORDS']: +
    • $k
    • +
    +
  • +
  • USE : +
      +$for u in data['USE']: +
    • $u
    • +
    +
  • +
  • LANG : +
      +$for l in data['LANG']: +
    • $l
    • +
    +
  • +
  • GENTOO_MIRRORS : +
      +$for m in data['GENTOO_MIRRORS']: +
    • $m
    • +
    +
  • +
  • Installed packages : +
      +$code: + packages =3D data['PACKAGES'].keys() + packages.sort() +$for p in packages: +
    • $p
    • +
    +
  • +
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 =20 Welcome to the gentoostats webapp
- -List of hosts:
- -$for host in hosts: -
  • $host.uuid
  • +
    +Number of hosts: $count
    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 :
    - $for e in env: -
  • $e.var =3D "$e.value"
  • -$else: - Host does not exist in records!