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:
def __init__(self):
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
'jsonfile' option and override the default value."""
if 'opts' in args and args['opts'].has_section('jsonlogger'):
self.jsonfile = args['opts'].get('jsonlogger', 'jsonfile').strip()
def _append_info_to_logfile(self, args, info):
"""Write info to jsonfile converted in JSON format."""
self._set_jsonfile(args)
info['time'] = int(time())
def _write_json_logfile(self, args, status):
"""Write status to jsonfile in JSON format."""
self._set_json_logfile_name(args)
status['time'] = int(time())
with open(self.jsonfile, 'a') as logfd:
json = toJSON(info)
json = toJSON(status)
logfd.write(json + '\n')
def _get_package_json(self, args):
"""Get the path of package JSON file"""
return '%(directory)s/pool/%(package)s/%(package)s.json' % args
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)
if os.path.isfile(package_json):
with open(package_json, 'r') as infofd:
......@@ -73,49 +74,49 @@ class DebomaticModule_JSONLogger:
json = toJSON(info, indent=4)
infofd.write(json + '\n')
def _get_distribution_info(self, args):
"""From args to distribution info."""
info = {}
info['status'] = args['cmd']
info['distribution'] = args['distribution']
def _get_distribution_status(self, args):
"""From args to distribution status"""
status = {}
status['status'] = args['cmd']
status['distribution'] = args['distribution']
if 'success' in args:
info['success'] = args['success']
return info
status['success'] = args['success']
return status
def _get_package_info(self, args):
"""From args to package info."""
def _get_package_status(self, args):
"""From args to package status"""
keys = ['package', 'distribution', 'uploader']
info = {}
status = {}
for k in keys:
if k in args:
info[k] = args[k]
return info
status[k] = args[k]
return status
def pre_chroot(self, args):
distribution = self._get_distribution_info(args)
self._append_info_to_logfile(args, distribution)
distribution = self._get_distribution_status(args)
self._write_json_logfile(args, distribution)
def post_chroot(self, args):
distribution = self._get_distribution_info(args)
self._append_info_to_logfile(args, distribution)
distribution = self._get_distribution_status(args)
self._write_json_logfile(args, distribution)
def pre_build(self, args):
package = self._get_package_info(args)
package = self._get_package_status(args)
package['status'] = 'build'
package_json = self._get_package_json(args)
if os.path.isfile(package_json):
os.remove(package_json)
self._write_package_json(args, package)
self._append_info_to_logfile(args, package)
self._write_json_logfile(args, package)
def post_build(self, args):
package = self._get_package_info(args)
package['status'] = 'build'
package['success'] = False
status = self._get_package_status(args)
status['status'] = 'build'
status['success'] = False
resultdir = os.path.join(args['directory'], 'pool', args['package'])
for filename in os.listdir(resultdir):
if filename.endswith('.dsc'):
package['success'] = True
status['success'] = True
break
self._write_package_json(args, package)
self._append_info_to_logfile(args, package)
self._write_package_json(args, status)
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