Commit 857b13be authored by Efthymia Bika's avatar Efthymia Bika

Use spawn for timeview section

parent c6996c6e
......@@ -145,6 +145,12 @@ function remove_all(force) {
}
function load_timeview() {
$('#backup_details').hide();
$("#loader").show();
call_duplicity("timeview", get_backup_set(), false);
}
function call_duplicity(mode, backup_set, force) {
var win_cmd = "";
if(process.platform == 'win32') {
......@@ -192,6 +198,7 @@ function call_duplicity(mode, backup_set, force) {
break;
case "status":
case "timeview":
args = ["collection-status", "swift://" + backup_set.container];
break;
case "remove":
......@@ -217,6 +224,7 @@ function call_duplicity(mode, backup_set, force) {
// call duplicity
var wProcess = spawn(DUPLICITY_PATH, args);
var output_str = "";
function dup_call_out(data) {
if(mode == "status") {
toggle_msgs(data, "status_contents");
......@@ -234,6 +242,8 @@ function call_duplicity(mode, backup_set, force) {
$("#force-delete").hide();
}
}
} else if(mode == "timeview") {
output_str += data.toString();
} else {
toggle_msgs(data, "msg");
if(mode == "backup") {
......@@ -288,13 +298,21 @@ function call_duplicity(mode, backup_set, force) {
} else {
check_restore_errors(code);
}
} else if(mode == "timeview") {
if(code == 0) {
parse_collection_status(output_str);
} else if(code == DUP_ERR_CODES.CONNECTION_FAILED) {
show_cloud_error();
}
} else {
if(code == DUP_ERR_CODES.CONNECTION_FAILED) show_cloud_error();
}
}
// bind listeners
wProcess.stdout.setEncoding("utf8");
wProcess.stdout.on('data', dup_call_out);
wProcess.stderr.setEncoding('utf8');
wProcess.stderr.on('data', dup_call_err);
wProcess.on('exit', dup_call_exit);
......
......@@ -170,41 +170,21 @@ function get_contents_by_date(value) {
}
}
function load_timeview() {
$("#backup_details").hide();
$("#loader").show();
function puts(error, stdout, stderr) {
$("#loader").hide();
toggle_error(error, stderr);
if(!error) {
var datetime_reg = /\d{4}-\d{2}-\d{2}.\d{2}:\d{2}:\d{2}\s+\d+/g;
var dates = stdout.match(datetime_reg);
var dates_list = "";
if(dates) {
dates = dates.sort();
$.each(dates, function(i, value) {
value = value.substring(0, 19);
var iso_time = value.replace('.', 'T');
dates_list += "<a href='#' onclick='get_contents_by_date(\""
+ iso_time + "\")' id='" + iso_time + "'>" +
value.replace('.', ' ') + "</a><br>";
});
}
$("#time-dates").html(dates_list);
}
}
var cacert_arg = " --ssl-cacert-file " +
clouds[$("#cloud").val()].cert;
var dup_cmd = DUPLICITY_PATH + cacert_arg +
" collection-status swift://" + container;
if(process.platform == 'win32') {
var cmd = build_win_commands();
var args = ["-c", cmd + dup_cmd];
execFile(CYGWIN_BASH, args, puts);
} else {
set_envs();
exec(dup_cmd, {maxBuffer: 1000*1024} , puts);
function parse_collection_status(data) {
var datetime_reg = /\d{4}-\d{2}-\d{2}.\d{2}:\d{2}:\d{2}\s+\d+/g;
var dates = data.match(datetime_reg);
var dates_list = "";
if(dates) {
dates = dates.sort();
$.each(dates, function(i, value) {
value = value.substring(0, 19);
var iso_time = value.replace('.', 'T');
dates_list += "<a href='#' onclick='get_contents_by_date(\""
+ iso_time + "\")' id='" + iso_time + "'>" +
value.replace('.', ' ') + "</a><br>";
});
}
$("#time-dates").html(dates_list);
}
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