public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/gentoostats:master commit in: /, server/
@ 2011-05-12 10:48 Vikraman Choudhury
  0 siblings, 0 replies; 3+ messages in thread
From: Vikraman Choudhury @ 2011-05-12 10:48 UTC (permalink / raw
  To: gentoo-commits

commit:     144bfa8b04c4fc750fac206357d88c722a63653d
Author:     Vikraman Choudhury <vikraman.choudhury <AT> gmail <DOT> com>
AuthorDate: Thu May 12 10:47:56 2011 +0000
Commit:     Vikraman Choudhury <vikraman.choudhury <AT> gmail <DOT> com>
CommitDate: Thu May 12 10:47:56 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoostats.git;a=commit;h=144bfa8b

fixes after code review

---
 TODO           |    8 +++++---
 server/main.py |    4 ++--
 server/post.py |    1 +
 3 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/TODO b/TODO
index 3bbc2ce..0821f7b 100644
--- a/TODO
+++ b/TODO
@@ -1,3 +1,5 @@
-TODO: Return public uuid and md5sum of password
-TODO: Handle exceptions
-TODO: Remove gentoolkit dependency
+./server/post.py:  #TODO: Improve this
+./server/post.py:  #TODO: Handle exceptions
+./client/bin/client:  #TODO: Return public uuid and md5sum of password
+./client/bin/client:  #TODO: Handle exceptions
+./client/useflags.py:#TODO: Remove gentoolkit dependency

diff --git a/server/main.py b/server/main.py
index dbfd3ad..7796aba 100755
--- a/server/main.py
+++ b/server/main.py
@@ -27,8 +27,8 @@ class stats:
   def GET(self, uuid):
     if uuid == 'favicon.ico':
       return notfound()
-    hosts = db.select('hosts', vars=locals(), where="uuid=$uuid")
-    env = db.select('env', vars=locals(), where="uuid=$uuid")
+    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):

diff --git a/server/post.py b/server/post.py
index b9eb46c..0aa1d98 100644
--- a/server/post.py
+++ b/server/post.py
@@ -20,6 +20,7 @@ def pkgsplit(pkgname):
   return cpv
 
 def handler(uuid, data, db):
+  #TODO: Handle exceptions
   if data['PROTOCOL'] != 1:
     return 'Unsupported protocol!'
 



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [gentoo-commits] proj/gentoostats:master commit in: /, server/
@ 2011-06-07 23:58 Vikraman Choudhury
  0 siblings, 0 replies; 3+ messages in thread
From: Vikraman Choudhury @ 2011-06-07 23:58 UTC (permalink / raw
  To: gentoo-commits

commit:     f175ca30a0c692f5c28f8baa7cc397fac853f766
Author:     Vikraman Choudhury <vikraman.choudhury <AT> gmail <DOT> com>
AuthorDate: Tue Jun  7 22:04:06 2011 +0000
Commit:     Vikraman Choudhury <vikraman.choudhury <AT> gmail <DOT> com>
CommitDate: Tue Jun  7 22:04:06 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoostats.git;a=commit;h=f175ca30

update post handler

---
 .gitignore        |    1 +
 server/helpers.py |   81 +++++++++++++++++++++++++++++++++++++++
 server/post.py    |  110 ++++++++++++++++++++++++++++++----------------------
 3 files changed, 145 insertions(+), 47 deletions(-)

diff --git a/.gitignore b/.gitignore
index 551cb32..a253c69 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
 *.*~
 *.pyc
+*.swp

diff --git a/server/helpers.py b/server/helpers.py
new file mode 100644
index 0000000..571ffa6
--- /dev/null
+++ b/server/helpers.py
@@ -0,0 +1,81 @@
+
+import re
+
+# split package name into cpv
+# based on pkgsplit code 
+# in portage/versions.py
+
+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('pkg')
+  rev = m.group('rev')
+  if rev is None:
+ 	cpv['ver'] = m.group('ver')
+  else:
+	cpv['ver'] = m.group('ver') + '-r' + rev
+  return cpv
+
+# get functions for index keys
+# lookup key and insert if not found
+
+def get_kwkey(db, keyword):
+  db_keyword = db.select('keywords', vars={'keyword':keyword}, where='keyword=$keyword')
+  if len(db_keyword):
+	kwkey = db_keyword[0].kwkey
+  else:
+	kwkey = db.insert('keywords', keyword=keyword)
+  return kwkey
+
+def get_lkey(db, lang):
+  db_lang = db.select('lang', vars={'lang':lang}, where='lang=$lang')
+  if len(db_lang):
+	lkey = db_lang[0].lkey
+  else:
+	lkey = db.insert('lang', lang=lang)
+  return lkey
+
+def get_fkey(db, feature):
+  db_feature = db.select('features', vars={'feature':feature}, where='feature=$feature')
+  if len(db_feature):
+	fkey = db_feature[0].fkey
+  else:
+	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')
+  if len(db_mirror):
+	mkey = db_mirror[0].mkey
+  else:
+	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')
+  if len(db_useflag):
+	ukey = db_useflag[0].ukey
+  else:
+	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')
+  if len(db_package):
+	pkey = db_package[0].pkey
+  else:
+	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')
+  if len(db_repo):
+	rkey = db_repo[0].rkey
+  else:
+	rkey = db.insert('repositories', repo=repo)
+  return rkey
+

diff --git a/server/post.py b/server/post.py
index 0aa1d98..1ca491d 100644
--- a/server/post.py
+++ b/server/post.py
@@ -1,23 +1,6 @@
 #!/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
+from helpers import *
 
 def handler(uuid, data, db):
   #TODO: Handle exceptions
@@ -27,35 +10,68 @@ def handler(uuid, data, db):
   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])
+  # 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'])
 
-  if exists:
-    db.delete('useflags', vars={'uuid':uuid}, where='uuid=$uuid')
-
-  pkg = data['PACKAGES']
-  for cpv in pkg.keys():
-    t = pkgsplit(cpv)
-    s = db.select('packages', vars={'cat':t['cat'], 'pkg':t['pn'], 'ver':t['ver']},
-	where='cat=$cat and pkg=$pkg and ver=$ver')
-    if len(s) == 0:
-      pkey = db.insert('packages', cat=t['cat'], pkg=t['pn'], ver=t['ver'])
-    else:
-      pkey = s[0].pkey
-    for use in pkg[cpv]:
-      db.insert('useflags', uuid=uuid, useflag=use, pkey=str(pkey))
+  # Insert in env
+  for var in ['ARCH','CHOST','CFLAGS','CXXFLAGS','FFLAGS','LDFLAGS','MAKEOPTS','SYNC','PLATFORM','PROFILE','LASTSYNC']:
+    db.insert('env', uuid=uuid, var=var, value=data[var])
   
+  # 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 + ' successful'



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [gentoo-commits] proj/gentoostats:master commit in: /, server/
@ 2011-07-11 14:14 Vikraman Choudhury
  0 siblings, 0 replies; 3+ messages in thread
From: Vikraman Choudhury @ 2011-07-11 14:14 UTC (permalink / raw
  To: gentoo-commits

commit:     b67120122f77805800208a5e48f7cf39782dcd2f
Author:     Vikraman Choudhury <vikraman.choudhury <AT> gmail <DOT> com>
AuthorDate: Mon Jul 11 14:14:32 2011 +0000
Commit:     Vikraman Choudhury <vikraman.choudhury <AT> gmail <DOT> com>
CommitDate: Mon Jul 11 14:14:32 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoostats.git;a=commit;h=b6712012

make db configurable

---
 .gitignore            |    1 +
 server/app.py         |    2 +-
 server/config.py      |   11 +++++++----
 server/db.cfg.example |    6 ++++++
 server/dbconfig.py    |   24 ++++++++++++++++++++++++
 5 files changed, 39 insertions(+), 5 deletions(-)

diff --git a/.gitignore b/.gitignore
index a253c69..7ac969b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
 *.*~
 *.pyc
 *.swp
+server/db.cfg

diff --git a/server/app.py b/server/app.py
index 3d31d73..e957cde 100755
--- a/server/app.py
+++ b/server/app.py
@@ -33,7 +33,7 @@ urls = (
         r'/host/(.+)', 'Host'
         )
 
-app = web.application(urls, globals())
+app = web.application(urls, globals(), autoreload=True)
 
 app.notfound = config.notfound
 app.internalerror = config.internalerror

diff --git a/server/config.py b/server/config.py
index a7b0f26..98326ae 100644
--- a/server/config.py
+++ b/server/config.py
@@ -2,15 +2,18 @@
 import os
 import sys
 import web
+from dbconfig import DBConfig
 
+rootdir = os.path.abspath(os.path.dirname(__file__)) + '/'
+
+dbconfig = DBConfig(rootdir + 'db.cfg').get_config()
 db = web.database(
         dbn='mysql',
-        user='gentoostats',
-        pw='poicyurp3ZaddajGhaf',
-        db='gentoostats'
+        db=dbconfig['DB'],
+        user=dbconfig['USER'],
+        pw=dbconfig['PASS']
         )
 
-rootdir = os.path.abspath(os.path.dirname(__file__)) + '/'
 render = web.template.render(rootdir + 'templates/', base='layout')
 
 def notfound():

diff --git a/server/db.cfg.example b/server/db.cfg.example
new file mode 100644
index 0000000..1857e2f
--- /dev/null
+++ b/server/db.cfg.example
@@ -0,0 +1,6 @@
+
+[MYSQL]
+
+DB = gentoostats
+USER = gentoo
+PASS = gentoo

diff --git a/server/dbconfig.py b/server/dbconfig.py
new file mode 100644
index 0000000..e5eb42c
--- /dev/null
+++ b/server/dbconfig.py
@@ -0,0 +1,24 @@
+
+import sys
+import ConfigParser
+
+class DBConfig(object):
+
+    def __init__(self, configfile):
+        self.config = ConfigParser.ConfigParser()
+        if len(self.config.read(configfile)) == 0:
+            sys.stderr.write('Cannot read ' + configfile)
+            sys.exit(1)
+
+    def get_config(self):
+        ret = dict()
+        try:
+            ret['DB'] = self.config.get('MYSQL', 'DB')
+            ret['USER'] = self.config.get('MYSQL', 'USER')
+            ret['PASS'] = self.config.get('MYSQL', 'PASS')
+
+        except ConfigParser.NoSectionError, ConfigParser.NoOptionError:
+            sys.stderr.write('Invalid db config')
+            sys.exit(1)
+
+        return ret



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-07-11 14:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-12 10:48 [gentoo-commits] proj/gentoostats:master commit in: /, server/ Vikraman Choudhury
  -- strict thread matches above, loose matches on Subject: below --
2011-06-07 23:58 Vikraman Choudhury
2011-07-11 14:14 Vikraman Choudhury

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox