public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Vikraman Choudhury" <vikraman.choudhury@gmail.com>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/gentoostats:master commit in: server/, server/sql/, server/templates/
Date: Wed, 11 May 2011 22:04:47 +0000 (UTC)	[thread overview]
Message-ID: <33a30c369c78d8b992f326e96bbc9d03784ace76.vikraman@gentoo> (raw)

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!



                 reply	other threads:[~2011-05-11 22:05 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=33a30c369c78d8b992f326e96bbc9d03784ace76.vikraman@gentoo \
    --to=vikraman.choudhury@gmail.com \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox