diff options
author | Vikraman Choudhury <vikraman.choudhury@gmail.com> | 2011-07-11 02:58:35 +0530 |
---|---|---|
committer | Vikraman Choudhury <vikraman.choudhury@gmail.com> | 2011-07-11 02:58:35 +0530 |
commit | 1cb6b9cc00ad839c47453ba3b554df1fb8508508 (patch) | |
tree | 2b963f322ea3d66fa7c2071c3cfe14621c1ff10a | |
parent | per useflag stats (diff) | |
download | gentoostats-1cb6b9cc00ad839c47453ba3b554df1fb8508508.tar.gz gentoostats-1cb6b9cc00ad839c47453ba3b554df1fb8508508.tar.bz2 gentoostats-1cb6b9cc00ad839c47453ba3b554df1fb8508508.zip |
fix tabs
37 files changed, 782 insertions, 788 deletions
@@ -1,5 +1,2 @@ -./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 +./server/host.py: #TODO: Handle exceptions +./server/helpers.py: #TODO: string is not a valid uuid diff --git a/client/gentoostats-send b/client/gentoostats-send index 73d53a2..f2b7246 100755 --- a/client/gentoostats-send +++ b/client/gentoostats-send @@ -8,59 +8,59 @@ import urllib, httplib from gentoostats.payload import Payload def getAuthInfo(auth): - config = ConfigParser.ConfigParser() - if len(config.read(auth)) == 0: - sys.stderr.write('Cannot read ' + auth) - sys.exit(1) + config = ConfigParser.ConfigParser() + if len(config.read(auth)) == 0: + sys.stderr.write('Cannot read ' + auth) + sys.exit(1) - try: - uuid = config.get('AUTH', 'UUID') - passwd = config.get('AUTH', 'PASSWD') - auth_info = {'UUID' : uuid, 'PASSWD' : passwd} - return auth_info - except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): - sys.stderr.write('Malformed auth config') - sys.exit(1) + try: + uuid = config.get('AUTH', 'UUID') + passwd = config.get('AUTH', 'PASSWD') + auth_info = {'UUID' : uuid, 'PASSWD' : passwd} + return auth_info + except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): + sys.stderr.write('Malformed auth config') + sys.exit(1) def serialize(object, human=False): - if human: - indent = 2 - sort_keys = True - else: - indent = None - sort_keys = False - return json.JSONEncoder(indent=indent, sort_keys=sort_keys).encode(object) + if human: + indent = 2 + sort_keys = True + else: + indent = None + sort_keys = False + return json.JSONEncoder(indent=indent, sort_keys=sort_keys).encode(object) def main(): - parser = argparse.ArgumentParser(description='Gentoostats client') - parser.add_argument('-s', '--server', default='soc.dev.gentoo.org') - parser.add_argument('-p', '--port', type = int, default=443) - parser.add_argument('-u', '--url', default='/gentoostats') - parser.add_argument('-a', '--auth', default='/etc/gentoostats/auth.cfg') - parser.add_argument('-c', '--config', default='/etc/gentoostats/payload.cfg') - args = vars(parser.parse_args()) + parser = argparse.ArgumentParser(description='Gentoostats client') + parser.add_argument('-s', '--server', default='soc.dev.gentoo.org') + parser.add_argument('-p', '--port', type = int, default=443) + parser.add_argument('-u', '--url', default='/gentoostats') + parser.add_argument('-a', '--auth', default='/etc/gentoostats/auth.cfg') + parser.add_argument('-c', '--config', default='/etc/gentoostats/payload.cfg') + args = vars(parser.parse_args()) - pl = Payload(configfile=args['config']) - pl.dump(human=True) + pl = Payload(configfile=args['config']) + pl.dump(human=True) - post_data = pl.get() - post_data['AUTH'] = getAuthInfo(auth=args['auth']) + post_data = pl.get() + post_data['AUTH'] = getAuthInfo(auth=args['auth']) - post_url = args['url'].strip('/') - if not len(post_url) == 0: - post_url = '/' + post_url - post_url = post_url + '/host/' + post_data['AUTH']['UUID'] + post_url = args['url'].strip('/') + if not len(post_url) == 0: + post_url = '/' + post_url + post_url = post_url + '/host/' + post_data['AUTH']['UUID'] - post_body = serialize(post_data,human=True) - post_headers = {'Content-type':'application/json'} + post_body = serialize(post_data,human=True) + post_headers = {'Content-type':'application/json'} - conn = httplib.HTTPSConnection(args['server'] + ':' + str(args['port'])) - conn.request('POST', url=post_url, headers=post_headers, body=post_body) + conn = httplib.HTTPSConnection(args['server'] + ':' + str(args['port'])) + conn.request('POST', url=post_url, headers=post_headers, body=post_body) - #TODO: Handle exceptions - response = conn.getresponse() - print response.status, response.reason - print 'Server response: ' + response.read() + #TODO: Handle exceptions + response = conn.getresponse() + print response.status, response.reason + print 'Server response: ' + response.read() if __name__ == "__main__": - main() + main() diff --git a/client/gentoostats/environment.py b/client/gentoostats/environment.py index f03a76c..2e92ca3 100644 --- a/client/gentoostats/environment.py +++ b/client/gentoostats/environment.py @@ -7,46 +7,46 @@ from _emerge.actions import relative_profile_path class Environment(object): - def __init__(self): - self.portdir = portage.settings['PORTDIR'] - - def getVar(self, myvar): - return portage.settings[myvar] - - def getPlatform(self): - return platform.platform(aliased=1) - - def getLastSync(self): - lastsync = None - try: - lastsync = portage.grabfile(os.path.join(self.portdir, 'metadata', 'timestamp.chk')) - except portage.exception.PortageException: - pass - if lastsync is None: - return 'Unknown' - return lastsync[0] - - def getProfile(self): - profilever = None - profile = portage.settings.profile_path - if profile: - profilever = relative_profile_path(self.portdir, profile) - if profilever is None: - try: - for parent in portage.grabfile(os.path.join(profile, 'parent')): - profilever = relative_profile_path(self.portdir,os.path.join(profile, parent)) - if profilever is not None: - break - except portage.exception.PortageException: - pass - - if profilever is None: - try: - profilever = '!' + os.readlink(profile) - except (OSError): - pass - - if profilever is None: - profilever = 'Unknown' - - return profilever + def __init__(self): + self.portdir = portage.settings['PORTDIR'] + + def getVar(self, myvar): + return portage.settings[myvar] + + def getPlatform(self): + return platform.platform(aliased=1) + + def getLastSync(self): + lastsync = None + try: + lastsync = portage.grabfile(os.path.join(self.portdir, 'metadata', 'timestamp.chk')) + except portage.exception.PortageException: + pass + if lastsync is None: + return 'Unknown' + return lastsync[0] + + def getProfile(self): + profilever = None + profile = portage.settings.profile_path + if profile: + profilever = relative_profile_path(self.portdir, profile) + if profilever is None: + try: + for parent in portage.grabfile(os.path.join(profile, 'parent')): + profilever = relative_profile_path(self.portdir,os.path.join(profile, parent)) + if profilever is not None: + break + except portage.exception.PortageException: + pass + + if profilever is None: + try: + profilever = '!' + os.readlink(profile) + except (OSError): + pass + + if profilever is None: + profilever = 'Unknown' + + return profilever diff --git a/client/gentoostats/metadata.py b/client/gentoostats/metadata.py index 224fbfd..fb36a12 100644 --- a/client/gentoostats/metadata.py +++ b/client/gentoostats/metadata.py @@ -6,40 +6,40 @@ from gentoolkit.enalyze.lib import KeywordAnalyser class Metadata(object): - def __init__(self, cpv): - self.repo, self.counter, self.build_time, self.size = VARDB.aux_get(cpv,['repository','COUNTER','BUILD_TIME','SIZE']) + def __init__(self, cpv): + self.repo, self.counter, self.build_time, self.size = VARDB.aux_get(cpv,['repository','COUNTER','BUILD_TIME','SIZE']) - system_use = portage.settings['USE'].split() - fa = FlagAnalyzer(system=system_use) - self.flags = fa.analyse_cpv(cpv) + system_use = portage.settings['USE'].split() + fa = FlagAnalyzer(system=system_use) + self.flags = fa.analyse_cpv(cpv) - arch = portage.settings['ARCH'] - accept_keywords = portage.settings['ACCEPT_KEYWORDS'].split() - ka = KeywordAnalyser(arch=arch,accept_keywords=accept_keywords) - self.keyword = ka.get_inst_keyword_cpv(cpv) + arch = portage.settings['ARCH'] + accept_keywords = portage.settings['ACCEPT_KEYWORDS'].split() + ka = KeywordAnalyser(arch=arch,accept_keywords=accept_keywords) + self.keyword = ka.get_inst_keyword_cpv(cpv) - def getPlusFlags(self): - return list(self.flags[0]) + def getPlusFlags(self): + return list(self.flags[0]) - def getMinusFlags(self): - return list(self.flags[1]) + def getMinusFlags(self): + return list(self.flags[1]) - def getUnsetFlags(self): - return list(self.flags[2]) + def getUnsetFlags(self): + return list(self.flags[2]) - def getKeyword(self): - return self.keyword + def getKeyword(self): + return self.keyword - def getRepoName(self): - if self.repo: - return self.repo - return 'Unknown' + def getRepoName(self): + if self.repo: + return self.repo + return 'Unknown' - def getCounter(self): - return self.counter + def getCounter(self): + return self.counter - def getBuildTime(self): - return self.build_time + def getBuildTime(self): + return self.build_time - def getSize(self): - return self.size + def getSize(self): + return self.size diff --git a/client/gentoostats/packages.py b/client/gentoostats/packages.py index 2c9f48d..2d8d677 100644 --- a/client/gentoostats/packages.py +++ b/client/gentoostats/packages.py @@ -5,14 +5,14 @@ from gentoostats.dbapi import VARDB class Packages(object): - def getInstalledCPs(self, sort=False): - installed_cps = VARDB.cp_all() - if sort: - return sorted(installed_cps) - return installed_cps + def getInstalledCPs(self, sort=False): + installed_cps = VARDB.cp_all() + if sort: + return sorted(installed_cps) + return installed_cps - def getInstalledCPVs(self,sort=False): - installed_cpvs = VARDB.cpv_all() - if sort: - return installed_cpvs - return installed_cpvs + def getInstalledCPVs(self,sort=False): + installed_cpvs = VARDB.cpv_all() + if sort: + return installed_cpvs + return installed_cpvs diff --git a/client/gentoostats/payload.py b/client/gentoostats/payload.py index 22f736e..40532c5 100644 --- a/client/gentoostats/payload.py +++ b/client/gentoostats/payload.py @@ -8,57 +8,57 @@ from gentoostats.metadata import Metadata class Payload(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 __init__(self, configfile): + self.config = ConfigParser.ConfigParser() + if len(self.config.read(configfile)) == 0: + sys.stderr.write('Cannot read ' + configfile) + sys.exit(1) - self.payload = dict() - self.payload['PROTOCOL'] = 1 - self.update() + self.payload = dict() + self.payload['PROTOCOL'] = 1 + self.update() - def __masked(self, section, item): - try: - return not self.config.getboolean(section, item) - except ConfigParser.NoOptionError: - return False - except (ConfigParser.NoSectionError, ValueError): - sys.stderr.write('Malformed payload config') - sys.exit(1) + def __masked(self, section, item): + try: + return not self.config.getboolean(section, item) + except ConfigParser.NoOptionError: + return False + except (ConfigParser.NoSectionError, ValueError): + sys.stderr.write('Malformed payload config') + sys.exit(1) - def update(self): - env = Environment() - self.payload['PLATFORM'] = 'Unknown' if self.__masked('ENV','PLATFORM') else env.getPlatform() - self.payload['LASTSYNC'] = 'Unknown' if self.__masked('ENV','LASTSYNC') else env.getLastSync() - self.payload['PROFILE'] = 'Unknown' if self.__masked('ENV','PROFILE') else env.getProfile() + def update(self): + env = Environment() + self.payload['PLATFORM'] = 'Unknown' if self.__masked('ENV','PLATFORM') else env.getPlatform() + self.payload['LASTSYNC'] = 'Unknown' if self.__masked('ENV','LASTSYNC') else env.getLastSync() + self.payload['PROFILE'] = 'Unknown' if self.__masked('ENV','PROFILE') else env.getProfile() - for var in ['ARCH','CHOST','CFLAGS','CXXFLAGS','FFLAGS','LDFLAGS','MAKEOPTS','SYNC']: - self.payload[var] = None if self.__masked('ENV',var) else env.getVar(var) + for var in ['ARCH','CHOST','CFLAGS','CXXFLAGS','FFLAGS','LDFLAGS','MAKEOPTS','SYNC']: + self.payload[var] = None if self.__masked('ENV',var) else env.getVar(var) - for var in ['ACCEPT_KEYWORDS','LANG','GENTOO_MIRRORS','FEATURES','USE']: - self.payload[var] = [] if self.__masked('ENV',var) else env.getVar(var).split() + for var in ['ACCEPT_KEYWORDS','LANG','GENTOO_MIRRORS','FEATURES','USE']: + self.payload[var] = [] if self.__masked('ENV',var) else env.getVar(var).split() - self.payload['PACKAGES'] = dict() - for cpv in Packages().getInstalledCPVs(): - m = Metadata(cpv) - p = dict() - p['REPO'] = None if self.__masked('PACKAGES','REPO') else m.getRepoName() - p['KEYWORD'] = None if self.__masked('PACKAGES','KEYWORD') else m.getKeyword() - p['USE'] = dict() - p['USE']['PLUS'] = [] if self.__masked('PACKAGES','USE_PLUS') else m.getPlusFlags() - p['USE']['MINUS'] = [] if self.__masked('PACKAGES','USE_MINUS') else m.getMinusFlags() - p['USE']['UNSET'] = [] if self.__masked('PACKAGES','USE_UNSET') else m.getUnsetFlags() - p['COUNTER'] = None if self.__masked('PACKAGES','COUNTER') else m.getCounter() - p['SIZE'] = None if self.__masked('PACKAGES','SIZE') else m.getSize() - p['BUILD_TIME'] = None if self.__masked('PACKAGES','BUILD_TIME') else m.getBuildTime() - self.payload['PACKAGES'][cpv] = p + self.payload['PACKAGES'] = dict() + for cpv in Packages().getInstalledCPVs(): + m = Metadata(cpv) + p = dict() + p['REPO'] = None if self.__masked('PACKAGES','REPO') else m.getRepoName() + p['KEYWORD'] = None if self.__masked('PACKAGES','KEYWORD') else m.getKeyword() + p['USE'] = dict() + p['USE']['PLUS'] = [] if self.__masked('PACKAGES','USE_PLUS') else m.getPlusFlags() + p['USE']['MINUS'] = [] if self.__masked('PACKAGES','USE_MINUS') else m.getMinusFlags() + p['USE']['UNSET'] = [] if self.__masked('PACKAGES','USE_UNSET') else m.getUnsetFlags() + p['COUNTER'] = None if self.__masked('PACKAGES','COUNTER') else m.getCounter() + p['SIZE'] = None if self.__masked('PACKAGES','SIZE') else m.getSize() + p['BUILD_TIME'] = None if self.__masked('PACKAGES','BUILD_TIME') else m.getBuildTime() + self.payload['PACKAGES'][cpv] = p - def get(self): - return self.payload + def get(self): + return self.payload - def dump(self,human=False): - if human: - pprint.pprint(self.payload) - else: - print self.payload + def dump(self,human=False): + if human: + pprint.pprint(self.payload) + else: + print self.payload diff --git a/client/setup.py b/client/setup.py index 133274c..c018ccc 100644 --- a/client/setup.py +++ b/client/setup.py @@ -2,13 +2,13 @@ from setuptools import setup setup( - name = "gentoostats", - version = "9999", - author = "Vikraman Choudhury", - author_email = "vikraman.choudhury@gmail.com", - description = "Package statistics client", - license = "GPLv3", - url = "http://soc.dev.gentoo/org/gentoostats", - packages = ['gentoostats'], - scripts = ['gentoostats-send'] - ) + name = "gentoostats", + version = "9999", + author = "Vikraman Choudhury", + author_email = "vikraman.choudhury@gmail.com", + description = "Package statistics client", + license = "GPLv3", + url = "http://soc.dev.gentoo/org/gentoostats", + packages = ['gentoostats'], + scripts = ['gentoostats-send'] + ) diff --git a/server/app.py b/server/app.py index fa5d6a4..f2948e8 100755 --- a/server/app.py +++ b/server/app.py @@ -16,21 +16,21 @@ from package import Package from host import Host urls = ( - r'/', 'Index', - r'/arch', 'Arch', - r'/profile', 'Profile', - r'/mirror', 'Mirror', - r'/feature', 'Feature', - r'/keyword', 'Keyword', - r'/repo', 'Repo', - r'/lang', 'Lang', - r'/package/(.+)/(.+)', 'Package', - r'/package/(.+)', 'Package', - r'/package', 'Package', - r'/use/(.+)', 'Use', - r'/use', 'Use', - r'/host/(.+)', 'Host' - ) + r'/', 'Index', + r'/arch', 'Arch', + r'/profile', 'Profile', + r'/mirror', 'Mirror', + r'/feature', 'Feature', + r'/keyword', 'Keyword', + r'/repo', 'Repo', + r'/lang', 'Lang', + r'/package/(.+)/(.+)', 'Package', + r'/package/(.+)', 'Package', + r'/package', 'Package', + r'/use/(.+)', 'Use', + r'/use', 'Use', + r'/host/(.+)', 'Host' + ) app = web.application(urls, globals()) @@ -38,4 +38,4 @@ app.notfound = config.notfound app.internalerror = config.internalerror if __name__ == "__main__": - app.run() + app.run() diff --git a/server/arch.py b/server/arch.py index a389b8f..8b9ef99 100644 --- a/server/arch.py +++ b/server/arch.py @@ -2,9 +2,9 @@ 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) + 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/config.py b/server/config.py index ae73fc4..6cb9ec3 100644 --- a/server/config.py +++ b/server/config.py @@ -4,18 +4,17 @@ import sys import web db = web.database( - dbn='mysql', - user='gentoo', - pw='gentoo', - db='gentoostats' - ) + dbn='mysql', + user='gentoo', + pw='gentoo', + db='gentoostats' + ) rootdir = os.path.abspath(os.path.dirname(__file__)) + '/' render = web.template.render(rootdir + 'templates/', base='layout') def notfound(): - return web.notfound(render.error_404()) + return web.notfound(render.error_404()) def internalerror(): - return web.internalerror(render.error_500()) - + return web.internalerror(render.error_500()) diff --git a/server/feature.py b/server/feature.py index 4b79da5..d7674f7 100644 --- a/server/feature.py +++ b/server/feature.py @@ -2,9 +2,9 @@ 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) + 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/helpers.py b/server/helpers.py index 10ac31f..28d15a2 100644 --- a/server/helpers.py +++ b/server/helpers.py @@ -6,103 +6,103 @@ from portage.versions import catpkgsplit # 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) + 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): - #TODO: string is not a valid uuid - u = uuid.UUID(string) - return u.bytes + #TODO: string is not a valid uuid + u = uuid.UUID(string) + return u.bytes # custom pkgsplit def pkgsplit(pkgname): - cpv={'cat':'','pkg':'','ver':''} - cpvr = catpkgsplit(pkgname) - if cpvr is None: - pkgsplit = pkgname.split('/') - cpv['cat'] = pkgsplit[0] - cpv['pkg'] = pkgsplit[1] - else: - cpv['cat'] = cpvr[0] - cpv['pkg'] = cpvr[1] - cpv['ver'] = cpvr[2] - if cpvr[3] != 'r0': - cpv['ver'] = cpv['ver'] + '-' + cpvr[3] - return cpv + cpv={'cat':'','pkg':'','ver':''} + cpvr = catpkgsplit(pkgname) + if cpvr is None: + pkgsplit = pkgname.split('/') + cpv['cat'] = pkgsplit[0] + cpv['pkg'] = pkgsplit[1] + else: + 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 # lookup key and insert if not found def get_kwkey(db, keyword): - if keyword is None: - return None - 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 + if keyword is None: + return None + 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): - if lang is None: - return None - 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 + if lang is None: + return None + 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): - if feature is None: - return None - 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 + if feature is None: + return None + 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): - if mirror is None: - return None - 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 + if mirror is None: + return None + 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): - if useflag is None: - return None - 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 + if useflag is None: + return None + 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): - if package is None: - return None - 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 + if package is None: + return None + 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): - if repo is None: - return None - 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 + if repo is None: + return None + 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/host.py b/server/host.py index c9a5d03..03bc2ba 100644 --- a/server/host.py +++ b/server/host.py @@ -7,133 +7,133 @@ 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() - - 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']: - host_data[var] = e[var] - - 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: - host_data['FEATURES'].append(f['FEATURE']) - - 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: - host_data['ACCEPT_KEYWORDS'].append(k['KEYWORD']) - - 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: - host_data['USE'].append(u['USEFLAG']) - - 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: - host_data['LANG'].append(l['LANG']) - - 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: - host_data['GENTOO_MIRRORS'].append(m['MIRROR']) - - 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'] - host_data['PACKAGES'][cpv] = dict() - - return render.host(host_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']) - build_time = int(post_data_pkg['BUILD_TIME']) if post_data_pkg['BUILD_TIME'] else None - - # Insert in INSTALLED_PACKAGES - ipkey = db.insert('INSTALLED_PACKAGES', UUID=uuid, PKEY=pkey, BUILD_TIME=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' + 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() + + 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']: + host_data[var] = e[var] + + 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: + host_data['FEATURES'].append(f['FEATURE']) + + 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: + host_data['ACCEPT_KEYWORDS'].append(k['KEYWORD']) + + 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: + host_data['USE'].append(u['USEFLAG']) + + 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: + host_data['LANG'].append(l['LANG']) + + 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: + host_data['GENTOO_MIRRORS'].append(m['MIRROR']) + + 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'] + host_data['PACKAGES'][cpv] = dict() + + return render.host(host_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']) + build_time = int(post_data_pkg['BUILD_TIME']) if post_data_pkg['BUILD_TIME'] else None + + # Insert in INSTALLED_PACKAGES + ipkey = db.insert('INSTALLED_PACKAGES', UUID=uuid, PKEY=pkey, BUILD_TIME=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 index e5866a2..e6a63f5 100644 --- a/server/index.py +++ b/server/index.py @@ -2,7 +2,7 @@ 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) + def GET(self): + hosts = db.select('HOSTS', what='COUNT(UUID) as COUNT') + count = hosts[0]['COUNT'] + return render.index(count) diff --git a/server/kwd.py b/server/kwd.py index 88fc799..c5f3403 100644 --- a/server/kwd.py +++ b/server/kwd.py @@ -2,9 +2,9 @@ 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) + 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 index 3f4ebfb..e8c2d90 100644 --- a/server/lang.py +++ b/server/lang.py @@ -2,9 +2,9 @@ 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) + 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 index 7084831..c8b44c2 100644 --- a/server/mirror.py +++ b/server/mirror.py @@ -2,9 +2,9 @@ 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) + 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/package.py b/server/package.py index 4ac7aa2..58e3066 100644 --- a/server/package.py +++ b/server/package.py @@ -4,138 +4,138 @@ 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(top) - elif l == 1: - return self.__GET_C(top, args[0]) - elif l == 2: - cpv = helpers.pkgsplit(args[0] + '/' + args[1]) - if cpv['ver'] == '': - 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, *args): + try: + top = int(web.input(top="5").top) + except ValueError: + top = 5 + l = len(args) + if l == 0: + return self.__GET(top) + elif l == 1: + return self.__GET_C(top, args[0]) + elif l == 2: + cpv = helpers.pkgsplit(args[0] + '/' + args[1]) + if cpv['ver'] == '': + 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, 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') - 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(p_data) + 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') + 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(p_data) - 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}) - 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, p_data) + 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}) + 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, p_data) - 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}) - 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, p_data) + 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}) + 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, p_data) - def __GET_CPV(self, cat, pkg, ver): - 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}) - p_tuple = p_query[0] - p_data = { - 'HOST_COUNT':p_tuple['HOST_COUNT'], - } - return render.package_cpv(cat, pkg, ver, p_data) + def __GET_CPV(self, cat, pkg, ver): + 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}) + p_tuple = p_query[0] + p_data = { + 'HOST_COUNT':p_tuple['HOST_COUNT'], + } + 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 + 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) == 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 + 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 + return t_list diff --git a/server/profile.py b/server/profile.py index 211963c..c0a0fc5 100644 --- a/server/profile.py +++ b/server/profile.py @@ -2,9 +2,9 @@ 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) + 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 index 4348248..5db221a 100644 --- a/server/repo.py +++ b/server/repo.py @@ -2,9 +2,9 @@ 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) + 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/runtests.py b/server/runtests.py index 8c0cbb0..51d0208 100755 --- a/server/runtests.py +++ b/server/runtests.py @@ -8,6 +8,6 @@ from tests.test_host import TestHost testCases = [TestIndex, TestHost] if __name__ == '__main__': - suites = [ unittest.TestLoader().loadTestsFromTestCase(testCase) for testCase in testCases] - for suite in suites: - unittest.TextTestRunner(verbosity=2).run(suite) + suites = [ unittest.TestLoader().loadTestsFromTestCase(testCase) for testCase in testCases] + for suite in suites: + unittest.TextTestRunner(verbosity=2).run(suite) diff --git a/server/templates/arch.html b/server/templates/arch.html index 535399c..04ddcf6 100644 --- a/server/templates/arch.html +++ b/server/templates/arch.html @@ -2,10 +2,10 @@ $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> + <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/error_404.html b/server/templates/error_404.html index d310a86..1d701eb 100644 --- a/server/templates/error_404.html +++ b/server/templates/error_404.html @@ -3,4 +3,3 @@ $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/feature.html b/server/templates/feature.html index 03c4bbd..e4529ae 100644 --- a/server/templates/feature.html +++ b/server/templates/feature.html @@ -2,10 +2,10 @@ $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> + <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/host.html b/server/templates/host.html index 04b1bff..b252bff 100644 --- a/server/templates/host.html +++ b/server/templates/host.html @@ -17,40 +17,40 @@ Stats for host $data['UUID'] : <br/> <br/> <li>FEATURES : <ul> $for f in data['FEATURES']: - <li>$f</li> + <li>$f</li> </ul> </li> <li>ACCEPT_KEYWORDS : <ul> $for k in data['ACCEPT_KEYWORDS']: - <li>$k</li> + <li>$k</li> </ul> </li> <li>USE : <ul> $for u in data['USE']: - <li>$u</li> + <li>$u</li> </ul> </li> <li>LANG : <ul> $for l in data['LANG']: - <li>$l</li> + <li>$l</li> </ul> </li> <li>GENTOO_MIRRORS : <ul> $for m in data['GENTOO_MIRRORS']: - <li>$m</li> + <li>$m</li> </ul> </li> <li>Installed packages : <ul> $code: - packages = data['PACKAGES'].keys() - packages.sort() + packages = data['PACKAGES'].keys() + packages.sort() $for p in packages: - <li>$p</li> + <li>$p</li> </ul> </li> </ul> diff --git a/server/templates/keyword.html b/server/templates/keyword.html index 4855040..2dee5ea 100644 --- a/server/templates/keyword.html +++ b/server/templates/keyword.html @@ -2,11 +2,11 @@ $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> + <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 index cfda84a..bd4b2ba 100644 --- a/server/templates/lang.html +++ b/server/templates/lang.html @@ -2,10 +2,10 @@ $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> + <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/layout.html b/server/templates/layout.html index 48140d6..b144b29 100644 --- a/server/templates/layout.html +++ b/server/templates/layout.html @@ -9,4 +9,3 @@ $def with (content) $:content </body> </html> - diff --git a/server/templates/mirror.html b/server/templates/mirror.html index a6189bc..311f8fa 100644 --- a/server/templates/mirror.html +++ b/server/templates/mirror.html @@ -2,10 +2,10 @@ $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> + <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/package.html b/server/templates/package.html index f1a4e5c..6b1f7da 100644 --- a/server/templates/package.html +++ b/server/templates/package.html @@ -7,10 +7,10 @@ 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> + <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 8247173..4971ca7 100644 --- a/server/templates/package_c.html +++ b/server/templates/package_c.html @@ -6,11 +6,11 @@ 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> + <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 30fdb25..ac39835 100644 --- a/server/templates/package_cp.html +++ b/server/templates/package_cp.html @@ -5,12 +5,12 @@ 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> + <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> diff --git a/server/templates/profile.html b/server/templates/profile.html index 702b03b..b6feb4d 100644 --- a/server/templates/profile.html +++ b/server/templates/profile.html @@ -2,10 +2,10 @@ $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> + <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 index 63371bb..98d94f6 100644 --- a/server/templates/repo.html +++ b/server/templates/repo.html @@ -2,11 +2,11 @@ $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> + <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/tests/test_host.py b/server/tests/test_host.py index 68a6732..a5e723b 100644 --- a/server/tests/test_host.py +++ b/server/tests/test_host.py @@ -6,76 +6,76 @@ from app import app class TestHost(unittest.TestCase): - def setUp(self): - self.b = app.browser() + def setUp(self): + self.b = app.browser() - def test_basic(self): - self.b.open('/host') - self.assertEqual(self.b.path, '/host') - self.assertEqual(self.b.status, 404) - - def test_get(self): - uri = '/host/' + str(uuid.uuid4()) - self.b.open(uri) - self.assertEqual(self.b.path, uri) + def test_basic(self): + self.b.open('/host') + self.assertEqual(self.b.path, '/host') + self.assertEqual(self.b.status, 404) - # This has a probability of failing of - # 1 - exp(-((n+1)**2)/2**123) - # where n is the no. of uuids already in the db - self.assertEqual(self.b.status, 404) + def test_get(self): + uri = '/host/' + str(uuid.uuid4()) + self.b.open(uri) + self.assertEqual(self.b.path, uri) - def test_post_empty(self): - str_uuid = str(uuid.uuid4()) - uri = '/host/' + str_uuid - # post with empty string - self.b.open(uri, '') - self.assertEqual(self.b.path, uri) - self.assertEqual(self.b.status, 500) - # post with empty json string - data = json.JSONEncoder().encode('') - self.b.open(uri, data) - self.assertEqual(self.b.path, uri) - self.assertEqual(self.b.status, 500) - # post with empty payload - payload = { - 'AUTH':{'UUID':str_uuid,'PASSWD':'test'}, - 'PROTOCOL':1 - } - data = json.JSONEncoder().encode(payload) - self.b.open(uri, data) - self.assertEqual(self.b.path, uri) - self.assertEqual(self.b.status, 500) - - def test_post_bad(self): - str_uuid = str(uuid.uuid4()) - uri = '/host/' + str_uuid - # different uuid in payload - payload = { - 'AUTH':{'UUID':str(uuid.uuid4()),'PASSWD':'test'}, - 'PROTOCOL':1 - } - data = json.JSONEncoder().encode(payload) - self.b.open(uri,data) - self.assertEqual(self.b.path, uri) - self.assertEqual(self.b.status, 200) - self.assertTrue('Invalid uuid' in self.b.data) + # This has a probability of failing of + # 1 - exp(-((n+1)**2)/2**123) + # where n is the no. of uuids already in the db + self.assertEqual(self.b.status, 404) - def test_post_get(self): - str_uuid = str(uuid.uuid4()) - uri = '/host/' + str_uuid - payload = { - 'AUTH':{'UUID':str_uuid,'PASSWD':'test'}, - 'PROTOCOL':1 - } - for var in ['PLATFORM','PROFILE','LASTSYNC']: - payload[var] = 'Unknown' - for var in ['ARCH','CHOST','CFLAGS','CXXFLAGS','FFLAGS','LDFLAGS','MAKEOPTS','SYNC']: - payload[var] = None - for var in ['ACCEPT_KEYWORDS','LANG','GENTOO_MIRRORS','FEATURES','USE']: - payload[var] = [] - payload['PACKAGES'] = {} - data = json.JSONEncoder().encode(payload) - self.b.open(uri,data) - self.assertEqual(self.b.path, uri) - self.assertEqual(self.b.status, 200) - self.assertTrue('POST for ' + str_uuid + ' successful' in self.b.data) + def test_post_empty(self): + str_uuid = str(uuid.uuid4()) + uri = '/host/' + str_uuid + # post with empty string + self.b.open(uri, '') + self.assertEqual(self.b.path, uri) + self.assertEqual(self.b.status, 500) + # post with empty json string + data = json.JSONEncoder().encode('') + self.b.open(uri, data) + self.assertEqual(self.b.path, uri) + self.assertEqual(self.b.status, 500) + # post with empty payload + payload = { + 'AUTH':{'UUID':str_uuid,'PASSWD':'test'}, + 'PROTOCOL':1 + } + data = json.JSONEncoder().encode(payload) + self.b.open(uri, data) + self.assertEqual(self.b.path, uri) + self.assertEqual(self.b.status, 500) + + def test_post_bad(self): + str_uuid = str(uuid.uuid4()) + uri = '/host/' + str_uuid + # different uuid in payload + payload = { + 'AUTH':{'UUID':str(uuid.uuid4()),'PASSWD':'test'}, + 'PROTOCOL':1 + } + data = json.JSONEncoder().encode(payload) + self.b.open(uri,data) + self.assertEqual(self.b.path, uri) + self.assertEqual(self.b.status, 200) + self.assertTrue('Invalid uuid' in self.b.data) + + def test_post_get(self): + str_uuid = str(uuid.uuid4()) + uri = '/host/' + str_uuid + payload = { + 'AUTH':{'UUID':str_uuid,'PASSWD':'test'}, + 'PROTOCOL':1 + } + for var in ['PLATFORM','PROFILE','LASTSYNC']: + payload[var] = 'Unknown' + for var in ['ARCH','CHOST','CFLAGS','CXXFLAGS','FFLAGS','LDFLAGS','MAKEOPTS','SYNC']: + payload[var] = None + for var in ['ACCEPT_KEYWORDS','LANG','GENTOO_MIRRORS','FEATURES','USE']: + payload[var] = [] + payload['PACKAGES'] = {} + data = json.JSONEncoder().encode(payload) + self.b.open(uri,data) + self.assertEqual(self.b.path, uri) + self.assertEqual(self.b.status, 200) + self.assertTrue('POST for ' + str_uuid + ' successful' in self.b.data) diff --git a/server/tests/test_index.py b/server/tests/test_index.py index 45de92b..2796c1d 100644 --- a/server/tests/test_index.py +++ b/server/tests/test_index.py @@ -4,23 +4,23 @@ from app import app class TestIndex(unittest.TestCase): - def setUp(self): - self.b = app.browser() - self.b.open('/') + def setUp(self): + self.b = app.browser() + self.b.open('/') - def test_basic(self): - self.assertEqual(self.b.path, '/') - self.assertEqual(self.b.status, 200) + def test_basic(self): + self.assertEqual(self.b.path, '/') + self.assertEqual(self.b.status, 200) - def test_content(self): - self.assertTrue('Welcome to the gentoostats webapp' in self.b.data) + def test_content(self): + self.assertTrue('Welcome to the gentoostats webapp' in self.b.data) - def test_hosts(self): - self.assertTrue('Number of hosts' in self.b.data) - lines = self.b.data.split('\n') - for line in lines: - if line.startswith('Number of hosts'): - words = line.split() - count = int(words[-1].strip('</br>')) - self.assertGreaterEqual(count,0) - break + def test_hosts(self): + self.assertTrue('Number of hosts' in self.b.data) + lines = self.b.data.split('\n') + for line in lines: + if line.startswith('Number of hosts'): + words = line.split() + count = int(words[-1].strip('</br>')) + self.assertGreaterEqual(count,0) + break diff --git a/server/use.py b/server/use.py index 5b7a54d..13068ec 100644 --- a/server/use.py +++ b/server/use.py @@ -2,45 +2,45 @@ from config import render, db class Use(object): - 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) + 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] + 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]}) - 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'] - } + 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] - return render.use_useflag(args[0], use_data) + 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'] + } - else: - return config.internalerror() + return render.use_useflag(args[0], use_data) + + else: + return config.internalerror() |