* [gentoo-commits] proj/gentoostats:master commit in: server/, server/sql/, server/templates/
@ 2011-05-11 22:04 Vikraman Choudhury
0 siblings, 0 replies; only message in thread
From: Vikraman Choudhury @ 2011-05-11 22:04 UTC (permalink / raw
To: gentoo-commits
commit: 33a30c369c78d8b992f326e96bbc9d03784ace76
Author: Vikraman Choudhury <vikraman.choudhury <AT> gmail <DOT> com>
AuthorDate: Wed May 11 22:03:44 2011 +0000
Commit: Vikraman Choudhury <vikraman.choudhury <AT> gmail <DOT> com>
CommitDate: Wed May 11 22:03:44 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoostats.git;a=commit;h=33a30c36
server working, can POST data successfully :)
---
server/main.py | 22 ++++++++++++----
server/post.py | 57 +++++++++++++++++++++++++++++++++++++++++++
server/sql/init.sql | 18 +++++++------
server/templates/index.html | 7 ++++-
server/templates/stats.html | 9 +++++++
5 files changed, 98 insertions(+), 15 deletions(-)
diff --git a/server/main.py b/server/main.py
index 51ae445..92e24ce 100755
--- a/server/main.py
+++ b/server/main.py
@@ -2,26 +2,36 @@
import web
import config
-from config import render
import json
+from config import render
+from post import handler
urls = (
r'/', 'index',
r'/(.+)', 'stats'
)
+db = web.database(
+ dbn='mysql',
+ user='vh4x0r',
+ pw='vh4x0r',
+ db='gentoostats'
+ )
+
class index:
def GET(self):
- return render.index()
+ hosts = db.select('hosts')
+ return render.index(hosts)
class stats:
def GET(self, uuid):
- return '<html><body>GET success</body></html>'
+ hosts = db.select('hosts', vars=locals(), where="uuid=$uuid")
+ env = db.select('env', vars=locals(), where="uuid=$uuid")
+ return render.stats(uuid, hosts, env)
def POST(self, uuid):
- pdata = json.JSONDecoder().decode(web.data())
- print pdata
- return 'Post for ' + uuid + ' successful'
+ post_data = json.JSONDecoder().decode(web.data())
+ return handler(uuid, post_data, db)
def notfound():
return web.notfound(render.error_404())
diff --git a/server/post.py b/server/post.py
new file mode 100644
index 0000000..4cd0712
--- /dev/null
+++ b/server/post.py
@@ -0,0 +1,57 @@
+#!/usr/bin/env python
+
+import re
+
+def pkgsplit(pkgname):
+ #TODO: Improve this
+ 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['pn'] = m.group('pn')
+ rev = m.group('rev')
+ if rev is None:
+ cpv['ver'] = m.group('ver')
+ else:
+ cpv['ver'] = m.group('ver') + '-r' + rev
+
+ return cpv
+
+def handler(uuid, data, db):
+ if data['PROTOCOL'] != 1:
+ return 'Unsupported protocol!'
+
+ if data['AUTH']['UUID'] != uuid:
+ return 'Invalid uuid!'
+
+ host = db.select('hosts', vars={'uuid':uuid}, where='uuid=$uuid')
+ if len(host):
+ if data['AUTH']['PASSWD'] == host[0].passwd:
+ exists = True
+ else:
+ return 'Wrong password!'
+ else:
+ db.insert('hosts', uuid=uuid, passwd=data['AUTH']['PASSWD'])
+ exists = False
+
+ if exists:
+ db.delete('env', vars={'uuid':uuid}, where='uuid=$uuid')
+
+ for var in ['CFLAGS', 'CXXFLAGS', 'LDFLAGS', 'CHOST', 'FEATURES']:
+ db.insert('env', uuid=uuid, var=var, value=data[var])
+
+ if exists:
+ db.delete('useflags', vars={'uuid':uuid}, where='uuid=$uuid')
+
+ pkg = data['PACKAGES']
+ for cpv in pkg.keys():
+ t = pkgsplit(cpv)
+ db.insert('packages', cat=t['cat'], pkg=t['pn'], ver=t['ver'])
+ pkey = db.select('packages', vars={'cat':t['cat'], 'pkg':t['pn'], 'ver':t['ver']},
+ where='cat=$cat and pkg=$pkg and ver=$ver', what='pkey')[0].pkey
+ for use in pkg[cpv]:
+ db.insert('useflags', uuid=uuid, useflag=use, pkey=str(pkey))
+
+ return 'POST for ' + uuid + ' successful'
diff --git a/server/sql/init.sql b/server/sql/init.sql
index 4fa490a..68d309f 100644
--- a/server/sql/init.sql
+++ b/server/sql/init.sql
@@ -11,22 +11,24 @@ create table hosts (
drop table if exists env;
create table env (
uuid varchar (40) references hosts.uuid,
- var varchar (15) not null,
- value varchar (100),
+ var varchar (20) not null,
+ value varchar (512),
primary key (uuid, var)
);
drop table if exists packages;
create table packages (
- cat varchar (20) not null,
- pkg varchar (20) not null,
- ver varchar (20) not null,
- pkey serial primary key
+ cat varchar (40) not null,
+ pkg varchar (40) not null,
+ ver varchar (40) not null,
+ pkey serial,
+ primary key (cat, pkg, ver, pkey)
);
drop table if exists useflags;
create table useflags (
uuid varchar (40) references host.uuid,
- useflag varchar (20) not null,
- pkey serial references packages.pkey
+ useflag varchar (40) not null,
+ pkey bigint unsigned references packages.pkey,
+ primary key (uuid, useflag, pkey)
);
diff --git a/server/templates/index.html b/server/templates/index.html
index 11fafb6..76c16e5 100644
--- a/server/templates/index.html
+++ b/server/templates/index.html
@@ -1,4 +1,9 @@
+$def with (hosts)
$var title: Gentoostats
-Welcome to the gentoostats webapp
+Welcome to the gentoostats webapp <br/>
+List of hosts: <br/>
+
+$for host in hosts:
+ <li><a href=$host.uuid>$host.uuid</li>
diff --git a/server/templates/stats.html b/server/templates/stats.html
new file mode 100644
index 0000000..7081b02
--- /dev/null
+++ b/server/templates/stats.html
@@ -0,0 +1,9 @@
+$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] only message in thread
only message in thread, other threads:[~2011-05-11 22:05 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-11 22:04 [gentoo-commits] proj/gentoostats:master commit in: server/, server/sql/, server/templates/ Vikraman Choudhury
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox