Commit a5efa1c8 authored by Leo Iannacone's avatar Leo Iannacone

added get packages list and get files package list

parent 92f731e7
......@@ -37,9 +37,12 @@ app.get('/', routes.index);
io.sockets.on('connection', function(socket) {
send.distributions(socket);
socket.on('get-packages', function(distro) {
socket.on('get-packages-list', function(distro) {
send.packages_list(socket, distro);
});
socket.on('get-package', function(package_info) {
send.package(socket, package_info);
});
});
fs.watch(config.debomatic_path, { persistent: true }, function (event, fileName) {
......
......@@ -8,8 +8,8 @@ function get_files_list(dir, onlyDirectories, callback) {
fs.readdir(dir, function(err, files){
result = [];
if (err) {
console.log.error(err);
return;
console.error(err);
return;
}
files.forEach( function(f) {
complete_path = path.join(dir, f);
......@@ -28,16 +28,8 @@ function get_files_list(dir, onlyDirectories, callback) {
});
}
function get_distributions(socket) {
}
function get_packages_list(socket, distro) {
var pool = path.join(BASE_DIR, distro, 'pool');
return pool;
}
debomatic_sender = {
distributions: function(socket) {
get_files_list(BASE_DIR, true, function(distros){
socket.emit('distributions', distros);
......@@ -45,8 +37,33 @@ debomatic_sender = {
},
packages_list: function(socket, distro) {
socket.emit('packages', get_packages_list(socket, distro));
distro_path = path.join(BASE_DIR, distro, 'pool');
get_files_list(distro_path, true, function (packages) {
result = {}
result.distribution = distro;
result.packages = []
packages.forEach( function (p) {
pack = {}
info = p.split('_')
pack.name = info[0]
pack.version = info[1]
result.packages.push(pack)
});
socket.emit('packages', result);
});
},
package: function (socket, package_info) {
package_path = path.join(BASE_DIR, package_info.distribution, 'pool', package_info.package + "_" + package_info.version);
get_files_list(package_path, false, function(files) {
result = []
files.forEach(function (f) {
result.push(f);
});
package_info.files = result;
socket.emit('package-files', package_info);
});
}
}
module.exports = debomatic_sender
......@@ -8,8 +8,15 @@
<script>
function get_path(path) {
info = path.split('/');
if (info.length == 1) {
socket.emit("get-packages", path);
if (info.length >= 1) {
socket.emit("get-packages-list", info[0]);
}
if (info.length >= 3){
data = {}
data.distribution = info[0];
data.package = info[1];
data.version = info[2];
socket.emit("get-package", data);
}
}
var socket = io.connect('//localhost:3000');
......@@ -21,9 +28,22 @@
});
});
socket.on('packages', function(packages) {
console.log("HHHH");
console.log(packages);
socket.on('packages', function(data) {
$('#packages').html('');
distro = data.distribution
data.packages.forEach(function (p){
$('#packages').append('<li><a href="#' + distro + "/" + p.name + "/" + p.version +'">' + p.name + " [" + p.version + "]" + '</li>');
});
});
socket.on('package-files', function(data) {
$('#files').html('');
distro = data.distribution
package = data.package
version = data.version
data.files.forEach(function (f){
$('#files').append('<li><a href="#' + distro + "/" + package + "/" +version +'/'+ f +'">'+ f + '</li>');
});
});
socket.on('error', function() { console.error(arguments) });
......@@ -31,11 +51,17 @@
$(window).on('hashchange', function() {
get_path(window.location.hash.replace('#',''));
});
$(window).on('load', function (){
get_path(window.location.hash.replace('#',''));
});
</script>
</head>
<body>
<ul id='messages'></ul>
<ul id="distributions"></ul>
<ul id="packages"></ul>
<ul id="files"></ul>
<%- body %>
</body>
</html>
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