diff options
author | Vikraman Choudhury <vikraman.choudhury@gmail.com> | 2011-06-23 16:49:09 +0530 |
---|---|---|
committer | Vikraman Choudhury <vikraman.choudhury@gmail.com> | 2011-06-23 16:49:09 +0530 |
commit | 5f953a0c1c54257d5ba50c4c9a9502f38295afe2 (patch) | |
tree | f54120f79576df37e1a1975adb4281cc827e8df0 | |
parent | update ebuild (diff) | |
download | gentoostats-5f953a0c1c54257d5ba50c4c9a9502f38295afe2.tar.gz gentoostats-5f953a0c1c54257d5ba50c4c9a9502f38295afe2.tar.bz2 gentoostats-5f953a0c1c54257d5ba50c4c9a9502f38295afe2.zip |
allow masking payload fields
-rwxr-xr-x | client/gentoostats-send | 8 | ||||
-rw-r--r-- | client/gentoostats/payload.py | 83 | ||||
-rw-r--r-- | client/payload.cfg | 29 | ||||
-rw-r--r-- | server/helpers.py | 14 | ||||
-rw-r--r-- | server/host.py | 3 |
5 files changed, 98 insertions, 39 deletions
diff --git a/client/gentoostats-send b/client/gentoostats-send index 9a9cd39..b118e94 100755 --- a/client/gentoostats-send +++ b/client/gentoostats-send @@ -6,10 +6,10 @@ import sys import json import urllib, httplib -def getAuthInfo(): +def getAuthInfo(auth='/etc/gentoostats/auth.cfg'): config = ConfigParser.ConfigParser() - if len(config.read('/etc/gentoostats/auth.cfg')) == 0: - sys.stderr.write('Cannot read auth.cfg') + if len(config.read(auth)) == 0: + sys.stderr.write('Cannot read '+auth) sys.exit(1) try: @@ -18,7 +18,7 @@ def getAuthInfo(): auth_info = {'UUID' : uuid, 'PASSWD' : passwd} return auth_info except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): - sys.stderr.write('Malformed auth.cfg') + sys.stderr.write('Malformed auth config') sys.exit(1) def serialize(object, human=False): diff --git a/client/gentoostats/payload.py b/client/gentoostats/payload.py index 9553512..756496c 100644 --- a/client/gentoostats/payload.py +++ b/client/gentoostats/payload.py @@ -1,49 +1,64 @@ +import sys import pprint +import ConfigParser from gentoostats.environment import Environment from gentoostats.packages import Packages from gentoostats.metadata import Metadata class Payload(object): - def __init__(self): - self.payload = dict() - self.payload['PROTOCOL'] = 1 - self.update() + def __init__(self, configfile='/etc/gentoostats/payload.cfg'): + 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() + + 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() + + 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() - env = Environment() - self.payload['PLATFORM'] = env.getPlatform() - self.payload['LASTSYNC'] = env.getLastSync() - self.payload['PROFILE'] = env.getProfile() - - for var in ['ARCH','CHOST','CFLAGS','CXXFLAGS','FFLAGS','LDFLAGS','MAKEOPTS','SYNC']: - self.payload[var] = env.getVar(var) - - for var in ['ACCEPT_KEYWORDS','LANG','GENTOO_MIRRORS','FEATURES','USE']: - self.payload[var] = env.getVar(var).split() - - self.payload['PACKAGES'] = dict() - for cpv in Packages().getInstalledCPVs(): - m = Metadata(cpv) - p = dict() - p['REPO'] = m.getRepoName() - p['KEYWORD'] = m.getKeyword() - p['USE'] = dict() - p['USE']['PLUS'] = m.getPlusFlags() - p['USE']['MINUS'] = m.getMinusFlags() - p['USE']['UNSET'] = m.getUnsetFlags() - p['COUNTER'] = m.getCounter() - p['SIZE'] = m.getSize() - p['BUILD_TIME'] = 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 + return self.payload def dump(self,human=False): - if human: - pprint.pprint(self.payload) - else: - print self.payload + if human: + pprint.pprint(self.payload) + else: + print self.payload diff --git a/client/payload.cfg b/client/payload.cfg new file mode 100644 index 0000000..a90a7c8 --- /dev/null +++ b/client/payload.cfg @@ -0,0 +1,29 @@ + +[ENV] + +# PLATFORM = yes +# PROFILE = yes +# LASTSYNC = yes +# ARCH = yes +# CHOST = yes +# CFLAGS = yes +# CXXFLAGS = yes +# FFLAGS = yes +# LDFLAGS = yes +# MAKEOPTS = yes +# SYNC = yes +# ACCEPT_KEYWORDS = yes +# GENTOO_MIRRORS = yes +# FEATURES = yes +# USE = yes + +[PACKAGES] + +# REPO = yes +# KEYWORD = yes +# USE_PLUS = yes +# USE_MINUS = yes +# USE_UNSET = yes +# COUNTER = yes +# SIZE = yes +# BUILD_TIME = yes diff --git a/server/helpers.py b/server/helpers.py index ebd53a3..386d73c 100644 --- a/server/helpers.py +++ b/server/helpers.py @@ -37,6 +37,8 @@ def pkgsplit(pkgname): # 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'] @@ -45,6 +47,8 @@ def get_kwkey(db, 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'] @@ -53,6 +57,8 @@ def get_lkey(db, 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'] @@ -61,6 +67,8 @@ def get_fkey(db, 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'] @@ -69,6 +77,8 @@ def get_mkey(db, 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'] @@ -77,6 +87,8 @@ def get_ukey(db, 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): @@ -86,6 +98,8 @@ def get_pkey(db, package): 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'] diff --git a/server/host.py b/server/host.py index f737a6d..b0d9235 100644 --- a/server/host.py +++ b/server/host.py @@ -115,9 +115,10 @@ class Host(object): 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=int(post_data_pkg['BUILD_TIME']), + 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 |