From 4d9fec98d3806d2d286c04420e629b65c95476dd Mon Sep 17 00:00:00 2001 From: Leo Iannacone Date: Mon, 17 Mar 2014 15:08:06 +0100 Subject: [PATCH] Provide JSONLogger debomatic module along with this interface. Update README e config.js according with. --- README.md | 22 ++++++++---- debomatic-modules/JSONLogger.py | 63 +++++++++++++++++++++++++++++++++ debomatic-webui/lib/config.js | 2 +- 3 files changed, 79 insertions(+), 8 deletions(-) create mode 100644 debomatic-modules/JSONLogger.py diff --git a/README.md b/README.md index 2d3837c..b8044a8 100644 --- a/README.md +++ b/README.md @@ -5,22 +5,30 @@ debomatic-webui This interface is built up on [node](http://nodejs.org/) platform and uses intensely [socket.io](http://socket.io/) and [jquery](http://jquery.com/) technologies. Whenever you want to leave a suggestion or file a bug report, please open a [new issue](https://github.com/LeoIannacone/debomatic-webui/issues). -## Installation +## Requirements -Installation is very simple. +You need **JSONLogger** debomatic module (provided along with this interface) to get installed in debomatic. +You can copy `debomatic-modules/JSONLogger.py` or link to the modules directory. In the most cases: +``` +sudo cp debomatic-modules/JSONLogger.py /usr/share/debomatic/modules/ +``` +Restart debomatic service. -1. First of all, you need `npm` and `nodejs` installed on your system. On debian like systems type this in a command line: - ``` + +Install **npm** and **nodejs** on your system. On debian like systems type this in a command line: +``` sudo apt-get install npm nodejs ``` -2. Then move to `debomatic-webui/` directory and type: +## Installation + +Move to **debomatic-webui/** directory and type: ``` npm install ``` - That command downloads node depenences locally and creates the `user.config.js` file. +That command downloads node dependences locally and creates automatically user configuration file. -2. Take a look at `user.config.js`. Edit as you wish and then run service with: +Take a look at auto-generated **user.config.js**. Edit as you wish and then run service with: ``` nodejs index.js ``` diff --git a/debomatic-modules/JSONLogger.py b/debomatic-modules/JSONLogger.py new file mode 100644 index 0000000..4e8e62a --- /dev/null +++ b/debomatic-modules/JSONLogger.py @@ -0,0 +1,63 @@ +# Deb-o-Matic - JSON logger module +# +# Copyright (C) 2014 Leo Iannacone +# +# Authors: Leo Iannacone +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 3 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. +# +# Log information about building packages in a JSON format. + +import os +from json import dumps as toJSON + + +class DebomaticModule_JSONLogger: + + def __init__(self): + self.logfile = '/var/log/debomatic-json.log' + + def _set_logfile(self, args): + if args['opts'].has_section('jsonlogger'): + self.logfile = args['opts'].get('jsonlogger', 'jsonfile').strip() + + def _get_info(self, args): + keys = ['package', 'distribution', 'uploader'] + info = {} + for k in keys: + if args.has_key(k): + info[k] = args[k] + return info + + def pre_build(self, args): + self._set_logfile(args) + with open(self.logfile, 'a') as fd: + package = self._get_info(args) + package['status'] = 'building' + json = toJSON(package) + fd.write(json + '\n') + + def post_build(self, args): + self._set_logfile(args) + with open(self.logfile, 'a') as fd: + status = 'build-failed' + package = self._get_info(args) + resultdir = os.path.join(args['directory'], 'pool', args['package']) + for filename in os.listdir(resultdir): + if filename.endswith('.dsc'): + status = 'build-successed' + break + package['status'] = status + json = toJSON(package) + fd.write(json + '\n') diff --git a/debomatic-webui/lib/config.js b/debomatic-webui/lib/config.js index b48ab59..5892d9c 100644 --- a/debomatic-webui/lib/config.js +++ b/debomatic-webui/lib/config.js @@ -21,7 +21,7 @@ config.socket.log = false config.debomatic = {} config.debomatic.path = '/srv/debomatic-amd64' -config.debomatic.jsonfile = '/var/log/debomatic.json' +config.debomatic.jsonfile = '/var/log/debomatic-json.log' config.routes = {} config.routes.debomatic = '/debomatic'