Commit 9f520661 authored by Leo Iannacone's avatar Leo Iannacone

use 2 blank space instead of 4

parent e46c0e75
...@@ -41,75 +41,74 @@ var io = require('socket.io').listen(app); ...@@ -41,75 +41,74 @@ var io = require('socket.io').listen(app);
app.get('/', routes.index); app.get('/', routes.index);
function watch_path_onsocket(event_name, socket, data, watch_path, updater) { function watch_path_onsocket(event_name, socket, data, watch_path, updater) {
name = "watcher-" + event_name name = "watcher-" + event_name
socket.get(name, function (err, watcher) { socket.get(name, function (err, watcher) {
if (watcher) { if (watcher) {
try { try {
watcher.unwatch() watcher.unwatch()
} catch (errorWatchingDirectory) { } catch (errorWatchingDirectory) {
watcher.close() watcher.close()
} }
}
try {
fs.stat(watch_path, function(err, stats) {
if (err)
return
if (stats.isDirectory()) {
watcher = fs.watch(watch_path, {persistent: true}, function (event, fileName) {
if(event == 'rename')
updater(socket, data)
})
} }
try { else {
fs.stat(watch_path, function(err, stats) { watcher = new Tail(watch_path)
if (err) watcher.on('line', function(new_content) {
return data.file.new_content = new_content + '\n'
if (stats.isDirectory()) { updater(socket, data)
watcher = fs.watch(watch_path, {persistent: true}, function (event, fileName) { })
if(event == 'rename') }
updater(socket, data) socket.set(name, watcher)
}) })
} } catch (err_watch) {}
else { })
watcher = new Tail(watch_path)
watcher.on('line', function(new_content) {
data.file.new_content = new_content + '\n'
updater(socket, data)
})
}
socket.set(name, watcher)
})
} catch (err_watch) {}
})
} }
io.sockets.on('connection', function(socket) { io.sockets.on('connection', function(socket) {
send.distributions(socket); send.distributions(socket);
// send distribution packages // send distribution packages
socket.on('get_distribution_packages', function (data) { socket.on('get_distribution_packages', function (data) {
if (! utils.check_data_distribution(data)) if (! utils.check_data_distribution(data))
return return
distribution_path = path.join(config.debomatic_path, data.distribution.name, 'pool') distribution_path = path.join(config.debomatic_path, data.distribution.name, 'pool')
watch_path_onsocket('get_distribution_packages', socket, data, distribution_path, send.distribution_packages) watch_path_onsocket('get_distribution_packages', socket, data, distribution_path, send.distribution_packages)
send.distribution_packages(socket, data); send.distribution_packages(socket, data);
}) })
socket.on('get_package_file_list', function(data) {
if (! utils.check_data_package(data))
return
package_path = utils.get_package_path(data)
watch_path_onsocket('get_package_file_list', socket, data, package_path, send.package_file_list)
send.package_file_list(socket, data)
socket.on('get_package_file_list', function(data) { })
if (! utils.check_data_package(data))
return socket.on('get_file', function (data){
package_path = utils.get_package_path(data) if (! utils.check_data_file(data))
watch_path_onsocket('get_package_file_list', socket, data, package_path, send.package_file_list) return
send.package_file_list(socket, data) file_path = utils.get_file_path(data)
watch_path_onsocket('get_file', socket, data, file_path, send.file_newcontent)
}) send.file(socket, data)
})
socket.on('get_file', function (data){
if (! utils.check_data_file(data))
return
file_path = utils.get_file_path(data)
watch_path_onsocket('get_file', socket, data, file_path, send.file_newcontent)
send.file(socket, data)
})
}); });
io.sockets.on('disconnect', function(socket){ io.sockets.on('disconnect', function(socket){
}); });
fs.watch(config.debomatic_path, { persistent: true }, function (event, fileName) { fs.watch(config.debomatic_path, { persistent: true }, function (event, fileName) {
send.distributions(io.sockets); send.distributions(io.sockets);
}); });
var server = app.listen(config.port, function(){ var server = app.listen(config.port, function(){
......
...@@ -4,114 +4,114 @@ var fs = require('fs') ...@@ -4,114 +4,114 @@ var fs = require('fs')
, utils = require('./utils.js') , utils = require('./utils.js')
function __get_files_list(dir, onlyDirectories, callback) { function __get_files_list(dir, onlyDirectories, callback) {
fs.readdir(dir, function(err, files){ fs.readdir(dir, function(err, files){
result = []; result = [];
if (err) { if (err) {
console.error(err); console.error(err);
return; return;
}
files.forEach( function(f) {
complete_path = path.join(dir, f);
if (onlyDirectories) {
if (fs.statSync(complete_path).isDirectory()) {
result.push(f);
}
}
else {
if (fs.statSync(complete_path).isFile()) {
result.push(f);
} }
files.forEach( function(f) { }
complete_path = path.join(dir, f);
if (onlyDirectories) {
if (fs.statSync(complete_path).isDirectory()) {
result.push(f);
}
}
else {
if (fs.statSync(complete_path).isFile()) {
result.push(f);
}
}
});
callback(result);
}); });
callback(result);
});
} }
function __get_files_list_from_package(data, callback) { function __get_files_list_from_package(data, callback) {
package_path = utils.get_package_path(data) package_path = utils.get_package_path(data)
__get_files_list(package_path, false, function(files) { __get_files_list(package_path, false, function(files) {
data.package.files = [] data.package.files = []
data.package.debs = [] data.package.debs = []
data.package.archives = [] data.package.archives = []
files.forEach(function (f) { files.forEach(function (f) {
file = {} file = {}
file.path = path.join(package_path, f).replace(config.debomatic_path, config.debomatic_webpath) file.path = path.join(package_path, f).replace(config.debomatic_path, config.debomatic_webpath)
file.orig_name = f file.orig_name = f
file.name = f.split('_')[0] file.name = f.split('_')[0]
file.label = f.replace(file.name + '_', '') file.label = f.replace(file.name + '_', '')
file.extension = f.split('.').pop(); file.extension = f.split('.').pop();
if (file.extension == "deb" || file.extension == "ddeb") if (file.extension == "deb" || file.extension == "ddeb")
data.package.debs.push(file); data.package.debs.push(file);
else if (f.indexOf('.tar') >= 0 || file.extension == "changes" || file.extension == "dsc") { else if (f.indexOf('.tar') >= 0 || file.extension == "changes" || file.extension == "dsc") {
data.package.archives.push(file) data.package.archives.push(file)
} }
else { else {
file.name = file.extension file.name = file.extension
data.package.files.push(file) data.package.files.push(file)
} }
});
callback(data);
}); });
callback(data);
});
} }
function __send_package_files_list (socket, data) { function __send_package_files_list (socket, data) {
__get_files_list_from_package(data, function(new_data){ __get_files_list_from_package(data, function(new_data){
socket.emit('package_file_list', new_data) socket.emit('package_file_list', new_data)
}); });
} }
function __send_distribution_packages (socket, data) { function __send_distribution_packages (socket, data) {
distro_path = utils.get_distribution_pool_path(data) distro_path = utils.get_distribution_pool_path(data)
__get_files_list(distro_path, true, function (packages) { __get_files_list(distro_path, true, function (packages) {
data.distribution.packages = [] data.distribution.packages = []
packages.forEach( function (p) { packages.forEach( function (p) {
pack = {} pack = {}
info = p.split('_') info = p.split('_')
pack.name = info[0] pack.name = info[0]
pack.version = info[1] pack.version = info[1]
if( data.package && if( data.package &&
pack.name == data.package.name && pack.name == data.package.name &&
pack.version == data.package.version ) { pack.version == data.package.version ) {
pack.selected = true; pack.selected = true;
} }
data.distribution.packages.push(pack) data.distribution.packages.push(pack)
});
socket.emit("distribution_packages", data)
}); });
socket.emit("distribution_packages", data)
});
} }
function __send_file (socket, data) { function __send_file (socket, data) {
file_path = utils.get_file_path(data) file_path = utils.get_file_path(data)
fs.readFile(file_path, 'utf8', function (err, content) { fs.readFile(file_path, 'utf8', function (err, content) {
if (err) return; if (err) return;
data.file.content = content data.file.content = content
socket.emit('file', data) socket.emit('file', data)
}); });
} }
debomatic_sender = { debomatic_sender = {
distributions: function(socket) { distributions: function(socket) {
__get_files_list(config.debomatic_path, true, function(distros){ __get_files_list(config.debomatic_path, true, function(distros){
socket.emit('distributions', distros); socket.emit('distributions', distros);
}); });
}, },
package_file_list: function(socket, data) { package_file_list: function(socket, data) {
__send_package_files_list(socket, data) __send_package_files_list(socket, data)
}, },
distribution_packages: function(socket, data) { distribution_packages: function(socket, data) {
__send_distribution_packages(socket, data) __send_distribution_packages(socket, data)
}, },
file: function(socket, data) { file: function(socket, data) {
__send_file(socket, data) __send_file(socket, data)
}, },
file_newcontent: function(socket, data) { file_newcontent: function(socket, data) {
socket.emit('file_newcontent', data); socket.emit('file_newcontent', data);
} }
} }
module.exports = debomatic_sender module.exports = debomatic_sender
...@@ -2,48 +2,48 @@ var path = require('path') ...@@ -2,48 +2,48 @@ var path = require('path')
, config = require('./config.js') , config = require('./config.js')
function __check_data_distribution(data) { function __check_data_distribution(data) {
return data && data.distribution && data.distribution.name return data && data.distribution && data.distribution.name
} }
function __check_data_package(data) { function __check_data_package(data) {
return __check_data_distribution(data) && data.package && data.package.name && data.package.version return __check_data_distribution(data) && data.package && data.package.name && data.package.version
} }
function __check_data_file(data) { function __check_data_file(data) {
return __check_data_package(data) && data.file.name return __check_data_package(data) && data.file.name
} }
function __get_distribution_pool_path(data) { function __get_distribution_pool_path(data) {
return path.join(config.debomatic_path, data.distribution.name, 'pool') return path.join(config.debomatic_path, data.distribution.name, 'pool')
} }
function __get_package_path(data) { function __get_package_path(data) {
return path.join(__get_distribution_pool_path(data), data.package.name + '_' + data.package.version) return path.join(__get_distribution_pool_path(data), data.package.name + '_' + data.package.version)
} }
function __get_file_path(data) { function __get_file_path(data) {
return path.join(__get_package_path(data), data.package.name + '_' + data.package.version + '.' + data.file.name) return path.join(__get_package_path(data), data.package.name + '_' + data.package.version + '.' + data.file.name)
} }
utils = { utils = {
check_data_distribution: function(data) { check_data_distribution: function(data) {
return __check_data_distribution(data) return __check_data_distribution(data)
}, },
check_data_package: function(data) { check_data_package: function(data) {
return __check_data_package(data) return __check_data_package(data)
}, },
check_data_file: function(data) { check_data_file: function(data) {
return __check_data_file(data) return __check_data_file(data)
}, },
get_distribution_pool_path: function(data) { get_distribution_pool_path: function(data) {
return __get_distribution_pool_path(data) return __get_distribution_pool_path(data)
}, },
get_package_path: function(data) { get_package_path: function(data) {
return __get_package_path(data) return __get_package_path(data)
}, },
get_file_path: function(data) { get_file_path: function(data) {
return __get_file_path(data) return __get_file_path(data)
}, },
} }
module.exports = utils module.exports = utils
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