Commit 08e14f2f authored by Leo Iannacone's avatar Leo Iannacone

jslinted code

parent a6c6a245
var config = require('./config.js') 'use strict';
, fs = require('fs')
, Tail = require('./tail.js')
function __watch_status_check_same_obj (obj1, obj2) { var config = require('./config.js'),
if (obj1.status == obj2.status) { fs = require('fs'),
if (obj1.distribution == obj2.distribution) { utils = require('./utils.js'),
if (obj1.hasOwnProperty('package') && Tail = require('./tail.js');
obj2.hasOwnProperty('package'))
{ function __watch_status_check_same_obj(obj1, obj2) {
if (obj1.package == obj2.package) if (obj1.status == obj2.status) {
return true; if (obj1.distribution == obj2.distribution) {
return false if (obj1.hasOwnProperty('package') &&
} obj2.hasOwnProperty('package')) {
return true if (obj1.package == obj2.package)
return true;
return false;
}
return true;
}
} }
} return false;
return false
} }
// watcher on build_status // watcher on build_status
function __watch_status (socket, status) { function __watch_status(socket, status) {
var watcher = new Tail(config.debomatic.jsonfile) var watcher = new Tail(config.debomatic.jsonfile);
watcher.on('line', function(new_content) { watcher.on('line', function (new_content) {
var data = null var data = null;
try { try {
data = JSON.parse(new_content) data = JSON.parse(new_content);
} catch (err) { } catch (err) {
utils.errors_handler('Broadcaster:__watch_status:JSON.parse(new_content) - ', err, socket) utils.errors_handler('Broadcaster:__watch_status:JSON.parse(new_content) - ', err, socket);
return return;
}
// looking for same status already in statuses lists
if (data.hasOwnProperty('success')) {
for(i = 0; i < status.length; i++) {
if (__watch_status_check_same_obj(data, status[i])) {
status.splice(i, 1)
break;
} }
else // looking for same status already in statuses lists
continue; if (data.hasOwnProperty('success')) {
} for (var i = 0; i < status.length; i++) {
} if (__watch_status_check_same_obj(data, status[i])) {
else { status.splice(i, 1);
status.push(data) break;
} } else
socket.emit(config.events.broadcast.status_update, data) continue;
}) }
watcher.on('error', function(msg) { } else {
socket.emit(config.events.error, msg) status.push(data);
}) }
socket.emit(config.events.broadcast.status_update, data);
});
watcher.on('error', function (msg) {
socket.emit(config.events.error, msg);
});
} }
// watcher on new distributions // watcher on new distributions
function __watch_distributions (socket) { function __watch_distributions(socket) {
fs.watch(config.debomatic.path, { persistent: true }, function (event, fileName) { fs.watch(config.debomatic.path, {
// wait half a second to get pool subdir created persistent: true
setTimeout(function() { }, function (event, fileName) {
utils.send_distributions(socket) // wait half a second to get pool subdir created
}, 500) setTimeout(function () {
}) utils.send_distributions(socket);
}, 500);
});
} }
function Broadcaster (sockets, status) { function Broadcaster(sockets, status) {
var sockets = sockets
__watch_status(sockets, status) __watch_status(sockets, status);
__watch_distributions(sockets) __watch_distributions(sockets);
return { return {
} };
} }
module.exports = Broadcaster module.exports = Broadcaster;
This diff is collapsed.
'use strict';
/* /*
* Please DO NOT edit this file. * Please DO NOT edit this file.
* *
* Edit auto-generated "user.config.js" file instead. * Edit auto-generated 'user.config.js' file instead.
* *
*/ */
// #start config-auto-export // #start config-auto-export
var config = {} var config = {};
/* /*
* Configure host and port. * Configure host and port.
* Please for ports < 1000 use authbind. DO NOT RUN nodejs as root. * Please for ports < 1000 use authbind. DO NOT RUN nodejs as root.
* $ authbind nodejs index.js * $ authbind nodejs index.js
*/ */
config.host = 'localhost' config.host = 'localhost';
config.port = 3000 config.port = 3000;
config.socket = {} config.socket = {};
config.socket.log = false config.socket.log = false;
config.debomatic = {} config.debomatic = {};
config.debomatic.path = '/srv/debomatic-amd64' config.debomatic.path = '/srv/debomatic-amd64';
config.debomatic.jsonfile = '/var/log/debomatic-json.log' config.debomatic.jsonfile = '/var/log/debomatic-json.log';
config.routes = {} config.routes = {};
config.routes.debomatic = '/debomatic' config.routes.debomatic = '/debomatic';
config.routes.distribution = '/distribution' config.routes.distribution = '/distribution';
config.routes.preferences = '/preferences' config.routes.preferences = '/preferences';
config.web = {} config.web = {};
config.web.title = "Deb-o-Matic web.ui" config.web.title = 'Deb-o-Matic web.ui';
config.web.description = "This is a web interface for debomatic" config.web.description = 'This is a web interface for debomatic';
// debomatic configuration exportable for web // debomatic configuration exportable for web
config.web.debomatic = {} config.web.debomatic = {};
config.web.debomatic.admin = {} config.web.debomatic.admin = {};
config.web.debomatic.admin.name = "Your Name" config.web.debomatic.admin.name = 'Your Name';
config.web.debomatic.admin.email = "you AT debian DOT org" // please use this SPAMFREE form - it will be converted client side by javascript config.web.debomatic.admin.email = 'you AT debian DOT org'; // please use this SPAMFREE form - it will be converted client side by javascript
config.web.debomatic.architecture = 'amd64' config.web.debomatic.architecture = 'amd64';
config.web.debomatic.dput = {} config.web.debomatic.dput = {};
config.web.debomatic.dput.incoming = config.debomatic.path config.web.debomatic.dput.incoming = config.debomatic.path;
config.web.debomatic.dput.host = config.host config.web.debomatic.dput.host = config.host;
config.web.debomatic.dput.login = "debomatic" config.web.debomatic.dput.login = 'debomatic';
config.web.debomatic.dput.method = "scp" config.web.debomatic.dput.method = 'scp';
config.web.debomatic.dput.unsigned_uploads = false config.web.debomatic.dput.unsigned_uploads = false;
// default ui settings // default ui settings
config.web.preferences = {} config.web.preferences = {};
config.web.preferences.autoscroll = true config.web.preferences.autoscroll = true;
config.web.preferences.header = true config.web.preferences.header = true;
config.web.preferences.sidebar = true config.web.preferences.sidebar = true;
config.web.preferences.glossy_theme = true config.web.preferences.glossy_theme = true;
config.web.preferences.file_background = true config.web.preferences.file_background = true;
config.web.preferences.file_fontsize = 13 // valid values are [13..16] config.web.preferences.file_fontsize = 13; // valid values are [13..16]
config.web.preferences.debug = 0 // debug level - 0 means disabled config.web.preferences.debug = 0; // debug level - 0 means disabled
// #end config-auto-export // #end config-auto-export
// DO NOT TOUCH these ones // DO NOT TOUCH these ones
config.version = '0.2.2' config.version = '0.2.2';
// A simple function to quickly have // A simple function to quickly have
// get and set strings for client events // get and set strings for client events
function _event_get_set(event_name) { function _event_get_set(event_name) {
return { return {
set: event_name, set: event_name,
get: 'get_' + event_name get: 'get_' + event_name
} };
} }
config.events = {} config.events = {};
config.events.error = 'error' config.events.error = 'error';
config.events.broadcast = {} config.events.broadcast = {};
config.events.broadcast.distributions = 'distributions' config.events.broadcast.distributions = 'distributions';
config.events.broadcast.status_update = 'status_update' config.events.broadcast.status_update = 'status_update';
config.events.client = {} config.events.client = {};
config.events.client.distribution_packages = _event_get_set('distribution_packages') config.events.client.distribution_packages = _event_get_set('distribution_packages');
config.events.client.distribution_packages.status = 'package_status' config.events.client.distribution_packages.status = 'package_status';
config.events.client.package_files_list = _event_get_set('package_files_list') config.events.client.package_files_list = _event_get_set('package_files_list');
config.events.client.file = _event_get_set('file') config.events.client.file = _event_get_set('file');
config.events.client.file_newcontent = 'file_newcontent' config.events.client.file_newcontent = 'file_newcontent';
config.events.client.status = 'status' config.events.client.status = 'status';
// debomatic status according with JSONLogger.py module // debomatic status according with JSONLogger.py module
config.status = {} config.status = {};
config.status.build = 'build' config.status.build = 'build';
config.status.create = 'create' config.status.create = 'create';
config.status.update = 'update' config.status.update = 'update';
config.status.success = true config.status.success = true;
config.status.fail = false config.status.fail = false;
// read user configuration and merge it // read user configuration and merge it
/* /*
* update object1 with object2 values * update object1 with object2 values
*/ */
function _merge(object1, object2) { function _merge(object1, object2) {
var result = {} var result = {};
for (p in object1) { for (var p in object1) {
if (object2.hasOwnProperty(p)) { if (object2.hasOwnProperty(p)) {
if (typeof object1[p] === 'object' && typeof object2[p] === 'object') { if (typeof object1[p] === 'object' && typeof object2[p] === 'object') {
result[p] = _merge(object1[p], object2[p]) result[p] = _merge(object1[p], object2[p]);
} } else {
else { result[p] = object2[p];
result[p] = object2[p] }
} } else {
result[p] = object1[p];
}
} }
else { return result;
result[p] = object1[p]
}
}
return result
} }
try { try {
var Parser = require('./parser.js') var Parser = require('./parser.js');
var parser = new Parser() var parser = new Parser();
var user_config = parser.getUserConfig() var user_config = parser.getUserConfig();
if (user_config) { if (user_config) {
console.log("Reading user configutation ...") console.log('Reading user configutation ...');
config = _merge(config, require(user_config)) config = _merge(config, require(user_config));
} } else {
else { console.log('No user config specified. Using global settings.');
console.log("No user config specified. Using global settings.") }
}
} catch (err) { } catch (err) {
if (err.code == 'MODULE_NOT_FOUND') { if (err.code == 'MODULE_NOT_FOUND') {
console.log("File %s not found.", user_config) console.log('File %s not found.', user_config);
process.exit(1) process.exit(1);
} } else {
else { console.error('Error reading user configutation', err);
console.error("Error reading user configutation", err); process.exit(1);
process.exit(1) }
}
} finally { } finally {
// export some variable // export some variable
config.web.paths = config.routes config.web.paths = config.routes;
config.web.events = config.events config.web.events = config.events;
config.web.status = config.status config.web.status = config.status;
config.web.host = config.host config.web.host = config.host;
module.exports = config module.exports = config;
} }
function Parser() 'use strict';
{
var args = process.argv.slice(2); function Parser() {
var help = function() { var args = process.argv.slice(2);
console.log("\
var help = function () {
console.log('\
Usage: %s [-c config]\n\ Usage: %s [-c config]\n\
-h print this help \n\ -h print this help \n\
-c set user configuration file", -c set user configuration file',
process.argv[1].split('/').pop()); process.argv[1].split('/').pop());
process.exit(0);
}
this.getUserConfig = function() { process.exit(0);
var configFile = null; };
args.forEach(function (val, index) {
if (val == '-c') {
configFile = args[index+1]
return
}
})
if (configFile)
return process.cwd() + '/' + configFile;
else
return null
}
args.forEach(function (val, index) { this.getUserConfig = function () {
if (val == '-h') { var configFile = null;
help() args.forEach(function (val, index) {
} if (val == '-c') {
}) configFile = args[index + 1];
return;
}
});
if (configFile)
return process.cwd() + '/' + configFile;
else
return null;
};
args.forEach(function (val, index) {
if (val == '-h') {
help();
}
});
} }
module.exports = Parser module.exports = Parser
\ No newline at end of file
var fs =require('fs') 'use strict';
, Tail = require('tail').Tail
Tail.prototype.watchEvent = function(e) { var fs = require('fs'),
var _this = this; Tail = require('tail').Tail;
if (e === 'change') { Tail.prototype.watchEvent = function (e) {
return fs.stat(this.filename, function(err, stats) { var _this = this;
if (err) {
_this.emit('error', err); if (e === 'change') {
} return fs.stat(this.filename, function (err, stats) {
if (stats.size < _this.pos) { if (err) {
_this.pos = stats.size; _this.emit('error', err);
} }
if (stats.size > _this.pos) { if (stats.size < _this.pos) {
_this.queue.push({ _this.pos = stats.size;
start: _this.pos, }
end: stats.size if (stats.size > _this.pos) {
_this.queue.push({
start: _this.pos,
end: stats.size
});
_this.pos = stats.size;
if (_this.queue.length === 1) {
return _this.internalDispatcher.emit('next');
}
}
}); });
_this.pos = stats.size; } else if (e === 'rename') {
if (_this.queue.length === 1) { this.unwatch();
return _this.internalDispatcher.emit("next"); _this.emit('error', 'File ' + this.filename + ' deleted.');
} }
}
});
} else if (e === 'rename') {
this.unwatch();
_this.emit('error', "File " + this.filename + " deleted.");
}
}; };
Tail.prototype.close = function() { Tail.prototype.close = function () {
this.unwatch() this.unwatch();
} };
module.exports = Tail module.exports = Tail;
\ No newline at end of file
This diff is collapsed.
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