Commit 92f731e7 authored by Leo Iannacone's avatar Leo Iannacone

refactoring code

parent 96bea022
...@@ -2,25 +2,51 @@ var fs = require('fs') ...@@ -2,25 +2,51 @@ var fs = require('fs')
, path = require('path') , path = require('path')
, config = require('./config.js') , config = require('./config.js')
module.exports = function () { var BASE_DIR = config.debomatic_path;
return {
distributions: function(callback) { function get_files_list(dir, onlyDirectories, callback) {
var callback = callback; fs.readdir(dir, function(err, files){
fs.readdir(config.debomatic_path, function(err, files){ result = [];
if (err) { if (err) {
throw err; console.log.error(err);
return;
} }
distros = []
files.forEach( function(f) { files.forEach( function(f) {
complete_path = path.join(config.debomatic_path, f); complete_path = path.join(dir, f);
if (fs.statSync(complete_path).isDirectory()) distros.push(f); if (onlyDirectories) {
if (fs.statSync(complete_path).isDirectory()) {
result.push(f);
}
}
else {
if (fs.statSync(complete_path).isFile()) {
result.push(f);
}
}
}); });
callback.emit('distributions', distros); callback(result);
});
}
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);
}); });
}, },
distribution: function(socket, distro) {
console.log(distro); packages_list: function(socket, distro) {
socket.emit('distribution', {bla: 'blabla'}); socket.emit('packages', get_packages_list(socket, distro));
} },
}
} }
module.exports = debomatic_sender
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