Commit 2281919d authored by Leo Iannacone's avatar Leo Iannacone

renamed variables and function names - update doc according with

parent d4429f40
...@@ -35,25 +35,26 @@ class DebomaticModule_JSONLogger: ...@@ -35,25 +35,26 @@ class DebomaticModule_JSONLogger:
def __init__(self): def __init__(self):
self.jsonfile = '/var/log/debomatic-json.log' self.jsonfile = '/var/log/debomatic-json.log'
def _set_jsonfile(self, args): def _set_json_logfile_name(self, args):
"""If debomatic config file has section [jsonlogger] try to get """If debomatic config file has section [jsonlogger] try to get
'jsonfile' option and override the default value.""" 'jsonfile' option and override the default value."""
if 'opts' in args and args['opts'].has_section('jsonlogger'): if 'opts' in args and args['opts'].has_section('jsonlogger'):
self.jsonfile = args['opts'].get('jsonlogger', 'jsonfile').strip() self.jsonfile = args['opts'].get('jsonlogger', 'jsonfile').strip()
def _append_info_to_logfile(self, args, info): def _write_json_logfile(self, args, status):
"""Write info to jsonfile converted in JSON format.""" """Write status to jsonfile in JSON format."""
self._set_jsonfile(args) self._set_json_logfile_name(args)
info['time'] = int(time()) status['time'] = int(time())
with open(self.jsonfile, 'a') as logfd: with open(self.jsonfile, 'a') as logfd:
json = toJSON(info) json = toJSON(status)
logfd.write(json + '\n') logfd.write(json + '\n')
def _get_package_json(self, args): def _get_package_json(self, args):
"""Get the path of package JSON file"""
return '%(directory)s/pool/%(package)s/%(package)s.json' % args return '%(directory)s/pool/%(package)s/%(package)s.json' % args
def _write_package_json(self, args, status): def _write_package_json(self, args, status):
"""Write package status into a JSON file.""" """Write package status to a JSON file."""
package_json = self._get_package_json(args) package_json = self._get_package_json(args)
if os.path.isfile(package_json): if os.path.isfile(package_json):
with open(package_json, 'r') as infofd: with open(package_json, 'r') as infofd:
...@@ -73,49 +74,49 @@ class DebomaticModule_JSONLogger: ...@@ -73,49 +74,49 @@ class DebomaticModule_JSONLogger:
json = toJSON(info, indent=4) json = toJSON(info, indent=4)
infofd.write(json + '\n') infofd.write(json + '\n')
def _get_distribution_info(self, args): def _get_distribution_status(self, args):
"""From args to distribution info.""" """From args to distribution status"""
info = {} status = {}
info['status'] = args['cmd'] status['status'] = args['cmd']
info['distribution'] = args['distribution'] status['distribution'] = args['distribution']
if 'success' in args: if 'success' in args:
info['success'] = args['success'] status['success'] = args['success']
return info return status
def _get_package_info(self, args): def _get_package_status(self, args):
"""From args to package info.""" """From args to package status"""
keys = ['package', 'distribution', 'uploader'] keys = ['package', 'distribution', 'uploader']
info = {} status = {}
for k in keys: for k in keys:
if k in args: if k in args:
info[k] = args[k] status[k] = args[k]
return info return status
def pre_chroot(self, args): def pre_chroot(self, args):
distribution = self._get_distribution_info(args) distribution = self._get_distribution_status(args)
self._append_info_to_logfile(args, distribution) self._write_json_logfile(args, distribution)
def post_chroot(self, args): def post_chroot(self, args):
distribution = self._get_distribution_info(args) distribution = self._get_distribution_status(args)
self._append_info_to_logfile(args, distribution) self._write_json_logfile(args, distribution)
def pre_build(self, args): def pre_build(self, args):
package = self._get_package_info(args) package = self._get_package_status(args)
package['status'] = 'build' package['status'] = 'build'
package_json = self._get_package_json(args) package_json = self._get_package_json(args)
if os.path.isfile(package_json): if os.path.isfile(package_json):
os.remove(package_json) os.remove(package_json)
self._write_package_json(args, package) self._write_package_json(args, package)
self._append_info_to_logfile(args, package) self._write_json_logfile(args, package)
def post_build(self, args): def post_build(self, args):
package = self._get_package_info(args) status = self._get_package_status(args)
package['status'] = 'build' status['status'] = 'build'
package['success'] = False status['success'] = False
resultdir = os.path.join(args['directory'], 'pool', args['package']) resultdir = os.path.join(args['directory'], 'pool', args['package'])
for filename in os.listdir(resultdir): for filename in os.listdir(resultdir):
if filename.endswith('.dsc'): if filename.endswith('.dsc'):
package['success'] = True status['success'] = True
break break
self._write_package_json(args, package) self._write_package_json(args, status)
self._append_info_to_logfile(args, package) self._write_json_logfile(args, status)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment