Commit e8dff50b authored by Leo Iannacone's avatar Leo Iannacone

Merge remote-tracking branch 'github/master' into portable

parents 8b46ae53 886c11aa
...@@ -35,7 +35,7 @@ from collections import defaultdict ...@@ -35,7 +35,7 @@ from collections import defaultdict
# as first and as last one for pre_* and post_* hooks # as first and as last one for pre_* and post_* hooks
class DebomaticModule_00_JSONLogger: class DebomaticModule_00_JSONLogger:
def __init__(self): def __init__(self):
self.logger = JSONLogger.Instance() self.logger = DebomaticModule_JSONLogger()
def pre_chroot(self, args): def pre_chroot(self, args):
self.logger.pre_chroot(args) self.logger.pre_chroot(args)
...@@ -46,7 +46,7 @@ class DebomaticModule_00_JSONLogger: ...@@ -46,7 +46,7 @@ class DebomaticModule_00_JSONLogger:
class DebomaticModule_ZZ_JSONLogger: class DebomaticModule_ZZ_JSONLogger:
def __init__(self): def __init__(self):
self.logger = JSONLogger.Instance() self.logger = DebomaticModule_JSONLogger()
def post_chroot(self, args): def post_chroot(self, args):
self.logger.post_chroot(args) self.logger.post_chroot(args)
...@@ -55,25 +55,8 @@ class DebomaticModule_ZZ_JSONLogger: ...@@ -55,25 +55,8 @@ class DebomaticModule_ZZ_JSONLogger:
self.logger.post_build(args) self.logger.post_build(args)
# Singleton decorator
class Singleton:
def __init__(self, decorated):
self._decorated = decorated
def Instance(self):
try:
return self._instance
except AttributeError:
self._instance = self._decorated()
return self._instance
def __call__(self):
raise TypeError('Singletons must be accessed through `Instance()`.')
# The real JSONLogger Class # The real JSONLogger Class
@Singleton class DebomaticModule_JSONLogger:
class JSONLogger:
def __init__(self): def __init__(self):
self.jsonfile = '/var/log/debomatic-json.log' self.jsonfile = '/var/log/debomatic-json.log'
...@@ -81,10 +64,33 @@ class JSONLogger: ...@@ -81,10 +64,33 @@ class JSONLogger:
def _set_json_logfile_name(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') and \
args['opts'].has_option('jsonlogger', 'jsonfile'):
self.jsonfile = args['opts'].get('jsonlogger', 'jsonfile').strip() self.jsonfile = args['opts'].get('jsonlogger', 'jsonfile').strip()
def _write_json_logfile(self, args, status): def _get_package_json_filename(self, args):
"""Get the path of package JSON file"""
return '%(directory)s/pool/%(package)s/%(package)s.json' % args
def _get_distribution_status(self, args):
"""From args to distribution status"""
status = {}
status['status'] = args['cmd']
status['distribution'] = args['distribution']
if 'success' in args:
status['success'] = args['success']
return status
def _get_package_status(self, args):
"""From args to package status"""
status = {}
for k in ['package', 'distribution', 'uploader']:
if k in args:
status[k] = args[k]
return status
def _append_json_logfile(self, args, status):
"""Write status to jsonfile in JSON format.""" """Write status to jsonfile in JSON format."""
self._set_json_logfile_name(args) self._set_json_logfile_name(args)
status['time'] = int(time()) status['time'] = int(time())
...@@ -92,13 +98,9 @@ class JSONLogger: ...@@ -92,13 +98,9 @@ class JSONLogger:
json = toJSON(status) json = toJSON(status)
logfd.write(json + '\n') 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): def _write_package_json(self, args, status):
"""Write package status to a JSON file.""" """Write package status to a JSON file."""
package_json = self._get_package_json(args) package_json = self._get_package_json_filename(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:
try: try:
...@@ -117,40 +119,22 @@ class JSONLogger: ...@@ -117,40 +119,22 @@ class JSONLogger:
json = toJSON(info, indent=4) json = toJSON(info, indent=4)
infofd.write(json + '\n') infofd.write(json + '\n')
def _get_distribution_status(self, args):
"""From args to distribution status"""
status = {}
status['status'] = args['cmd']
status['distribution'] = args['distribution']
if 'success' in args:
status['success'] = args['success']
return status
def _get_package_status(self, args):
"""From args to package status"""
keys = ['package', 'distribution', 'uploader']
status = {}
for k in keys:
if k in args:
status[k] = args[k]
return status
def pre_chroot(self, args): def pre_chroot(self, args):
distribution = self._get_distribution_status(args) distribution = self._get_distribution_status(args)
self._write_json_logfile(args, distribution) self._append_json_logfile(args, distribution)
def post_chroot(self, args): def post_chroot(self, args):
distribution = self._get_distribution_status(args) distribution = self._get_distribution_status(args)
self._write_json_logfile(args, distribution) self._append_json_logfile(args, distribution)
def pre_build(self, args): def pre_build(self, args):
package = self._get_package_status(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_filename(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._write_json_logfile(args, package) self._append_json_logfile(args, package)
def post_build(self, args): def post_build(self, args):
status = self._get_package_status(args) status = self._get_package_status(args)
...@@ -167,7 +151,7 @@ class JSONLogger: ...@@ -167,7 +151,7 @@ class JSONLogger:
if tag: if tag:
status['tags'][filename] = tag status['tags'][filename] = tag
self._write_package_json(args, status) self._write_package_json(args, status)
self._write_json_logfile(args, status) self._append_json_logfile(args, status)
# Parser for log files # Parser for log files
...@@ -227,9 +211,5 @@ class LogParser(): ...@@ -227,9 +211,5 @@ class LogParser():
def _from_tags_to_result(self, tags): def _from_tags_to_result(self, tags):
keys = sorted(list(tags.keys())) keys = sorted(list(tags.keys()))
result = [] result = ["%s%s" % (k, tags[k]) for k in keys]
for k in keys: return ' '.join(result) if result else None
result.append("%s%s" % (k, tags[k]))
if len(result) > 0:
return ' '.join(result)
return None
...@@ -137,6 +137,7 @@ function Client(socket) { ...@@ -137,6 +137,7 @@ function Client(socket) {
return; return;
var distribution_path = path.join(config.debomatic.path, data.distribution.name, 'pool'); var distribution_path = path.join(config.debomatic.path, data.distribution.name, 'pool');
utils.generic_handler_watcher(_e.distribution_packages, socket, data, distribution_path, __send_distribution_packages); utils.generic_handler_watcher(_e.distribution_packages, socket, data, distribution_path, __send_distribution_packages);
data = null;
}); });
socket.on(_e.package_files_list, function (data) { socket.on(_e.package_files_list, function (data) {
...@@ -144,18 +145,21 @@ function Client(socket) { ...@@ -144,18 +145,21 @@ function Client(socket) {
return; return;
var package_path = utils.get_package_path(data); var package_path = utils.get_package_path(data);
utils.generic_handler_watcher(_e.package_files_list, socket, data, package_path, __send_package_files_list); utils.generic_handler_watcher(_e.package_files_list, socket, data, package_path, __send_package_files_list);
data = null;
}); });
socket.on(_e.file, function (data) { socket.on(_e.file, function (data) {
if (!utils.check_data_file(data)) if (!utils.check_data_file(data))
return; return;
__handler_get_file(socket, data); __handler_get_file(socket, data);
data = null;
}); });
socket.on(_e.package_info, function (data) { socket.on(_e.package_info, function (data) {
if (!utils.check_data_package(data)) if (!utils.check_data_package(data))
return; return;
__send_package_info(socket, data); __send_package_info(socket, data);
data = null;
}); });
...@@ -167,7 +171,9 @@ function Client(socket) { ...@@ -167,7 +171,9 @@ function Client(socket) {
for (var key in socket_watchers) { for (var key in socket_watchers) {
try { try {
socket_watchers[key].close(); socket_watchers[key].close();
} catch (error_watch) {} } catch (error_watch) {
utils.errors_handler('client:disconnect', error_watch);
}
} }
}); });
}; };
......
...@@ -725,12 +725,14 @@ function Page_Distrubion(socket) { ...@@ -725,12 +725,14 @@ function Page_Distrubion(socket) {
socket.on(_e.distribution_packages, function (socket_data) { socket.on(_e.distribution_packages, function (socket_data) {
debug_socket('received', _e.distribution_packages, socket_data); debug_socket('received', _e.distribution_packages, socket_data);
packages.set(socket_data); packages.set(socket_data);
socket_data = null;
}); });
socket.on(_e.distribution_packages_status, function (socket_data) { socket.on(_e.distribution_packages_status, function (socket_data) {
debug_socket('received', _e.distribution_packages_status, socket_data); debug_socket('received', _e.distribution_packages_status, socket_data);
packages.set_status(socket_data); packages.set_status(socket_data);
sticky.set_status(socket_data); sticky.set_status(socket_data);
socket_data = null;
}); });
socket.on(config.events.broadcast.status_update, function (socket_data) { socket.on(config.events.broadcast.status_update, function (socket_data) {
...@@ -739,26 +741,31 @@ function Page_Distrubion(socket) { ...@@ -739,26 +741,31 @@ function Page_Distrubion(socket) {
if (socket_data.distribution == view.distribution.name && socket_data.package == view.package.orig_name) { if (socket_data.distribution == view.distribution.name && socket_data.package == view.package.orig_name) {
package_info.get(); package_info.get();
} }
socket_data = null;
}); });
socket.on(_e.package_files_list, function (socket_data) { socket.on(_e.package_files_list, function (socket_data) {
debug_socket('received', _e.package_files_list, socket_data); debug_socket('received', _e.package_files_list, socket_data);
files.set(socket_data); files.set(socket_data);
socket_data = null;
}); });
socket.on(_e.file, function (socket_data) { socket.on(_e.file, function (socket_data) {
debug_socket('received', _e.file, socket_data); debug_socket('received', _e.file, socket_data);
file.set(socket_data); file.set(socket_data);
socket_data = null;
}); });
socket.on(_e.file_newcontent, function (socket_data) { socket.on(_e.file_newcontent, function (socket_data) {
debug_socket('received', _e.file_newcontent, socket_data); debug_socket('received', _e.file_newcontent, socket_data);
new_lines.push(socket_data.file.new_content); new_lines.push(socket_data.file.new_content);
socket_data = null;
}); });
socket.on(_e.package_info, function (socket_data) { socket.on(_e.package_info, function (socket_data) {
debug_socket('received', _e.package_info, socket_data); debug_socket('received', _e.package_info, socket_data);
package_info.set(socket_data); package_info.set(socket_data);
socket_data = null;
}); });
$(window).on('hashchange', function () { $(window).on('hashchange', function () {
...@@ -775,6 +782,8 @@ function Page_Distrubion(socket) { ...@@ -775,6 +782,8 @@ function Page_Distrubion(socket) {
update.page(old_view); update.page(old_view);
page.go.up(); page.go.up();
debug(1, 'changing view', 'old:', old_view, 'new:', view); debug(1, 'changing view', 'old:', old_view, 'new:', view);
old_view = null;
new_view = null;
}); });
......
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