Set working directory to standard paths and add timer for async function in order to show progress

pull/135/head
Simon Stürz 2018-11-19 15:55:28 +01:00 committed by Michael Zanetti
parent 80789c256b
commit 384544ca15
2 changed files with 73 additions and 10 deletions

View File

@ -126,11 +126,13 @@ function downloadFile(filePath, fileName) {
}
var generateReportTimer = null;
function generateReport() {
console.log("Requesting to generate report file " + "/debug/report");
var button = document.getElementById("generateReportButton");
var textArea = document.getElementById("generateReportTextArea");
var button = document.getElementById("generateReportButton");
// Request report file generation
var reportGenerateRequest = new XMLHttpRequest();
@ -138,7 +140,10 @@ function generateReport() {
reportGenerateRequest.send(null);
button.disabled = true;
textArea.value = "";
textArea.value = ".";
// Start the timer
generateReportTimer = setTimeout(generateReportTimerTimeout, 1000);
reportGenerateRequest.onreadystatechange = function() {
if (reportGenerateRequest.readyState == 4) {
@ -151,6 +156,9 @@ function generateReport() {
return;
}
// Stop the timer
clearTimeout(generateReportTimer);
console.log(reportGenerateRequest.responseText);
var responseMap = JSON.parse(reportGenerateRequest.responseText);
var fileName = responseMap['fileName'];
@ -181,25 +189,39 @@ function generateReport() {
};
}
function generateReportTimerTimeout() {
var textArea = document.getElementById("generateReportTextArea");
textArea.value += ".";
generateReportTimer = setTimeout(generateReportTimerTimeout, 1000);
}
/* ========================================================================*/
/* Network test functions
/* ========================================================================*/
var pingTimer = null;
function startPingTest() {
console.log("Start ping test");
var textArea = document.getElementById("pingTextArea");
var button = document.getElementById("pingButton");
// Clear the text output
textArea.value = "";
textArea.value = ".";
// Request ping output
var request = new XMLHttpRequest();
request.open("GET", "/debug/ping", true);
request.send(null);
// Start the timer
pingTimer = setTimeout(pingTimerTimeout, 1000);
button.disabled = true;
request.onreadystatechange = function() {
if (request.readyState == 4) {
// Stop the timer
clearTimeout(pingTimer);
console.log(request.responseText);
textArea.value = request.responseText;
button.disabled = false;
@ -207,6 +229,15 @@ function startPingTest() {
};
}
function pingTimerTimeout() {
var textArea = document.getElementById("pingTextArea");
textArea.value += ".";
pingTimer = setTimeout(pingTimerTimeout, 1000);
}
var digTimer = null;
function startDigTest() {
console.log("Start dig test");
@ -214,15 +245,22 @@ function startDigTest() {
var button = document.getElementById("digButton");
// Clear the text output
textArea.value = "";
textArea.value = ".";
// Request dig output
var request = new XMLHttpRequest();
request.open("GET", "/debug/dig", true);
request.send(null);
// Start the timer
digTimer = setTimeout(digTimerTimeout, 1000);
button.disabled = true;
request.onreadystatechange = function() {
if (request.readyState == 4) {
// Stop the timer
clearTimeout(digTimer);
console.log(request.responseText);
textArea.value = request.responseText;
button.disabled = false;
@ -230,6 +268,15 @@ function startDigTest() {
};
}
function digTimerTimeout() {
var textArea = document.getElementById("digTextArea");
textArea.value += ".";
digTimer = setTimeout(digTimerTimeout, 1000);
}
var tracePathTimer = null;
function startTracePathTest() {
console.log("Start trace path test");
@ -237,15 +284,22 @@ function startTracePathTest() {
var button = document.getElementById("tracePathButton");
// Clear the text output
textArea.value = "";
textArea.value = ".";
// Request dig output
var request = new XMLHttpRequest();
request.open("GET", "/debug/tracepath", true);
request.send(null);
// Start the timer
tracePathTimer = setTimeout(tracePathTimerTimeout, 1000);
button.disabled = true;
request.onreadystatechange = function() {
if (request.readyState == 4) {
// Stop the timer
clearTimeout(tracePathTimer);
console.log(request.responseText);
textArea.value = request.responseText;
button.disabled = false;
@ -253,6 +307,13 @@ function startTracePathTest() {
};
}
function tracePathTimerTimeout() {
var textArea = document.getElementById("tracePathTextArea");
textArea.value += ".";
tracePathTimer = setTimeout(tracePathTimerTimeout, 1000);
}
/* ========================================================================*/
/* Start function calls
/* ========================================================================*/

View File

@ -27,6 +27,7 @@
#include <QFile>
#include <QTimer>
#include <QDateTime>
#include <QStandardPaths>
#include <QCryptographicHash>
#include <QProcessEnvironment>
@ -62,7 +63,8 @@ void DebugReportGenerator::generateReport()
qCDebug(dcDebugServer()) << "Start generating debug report";
m_reportFileName = QDateTime::currentDateTime().toString("yyyyMMddhhmm") + "-nymea-debug-report";
m_reportDirectory.setPath(QString("/tmp/%1").arg(m_reportFileName));
m_reportDirectory.setPath(QString("%1/%2").arg(QStandardPaths::writableLocation(QStandardPaths::TempLocation)).arg(m_reportFileName));
//m_reportDirectory.setPath(QString("/tmp/%1").arg(m_reportFileName));
if (!m_reportDirectory.exists()) {
qCDebug(dcDebugServer()) << "Create temporary folder to collect the data" << m_reportDirectory.path();
if (!m_reportDirectory.mkpath(m_reportDirectory.path())) {
@ -121,9 +123,9 @@ void DebugReportGenerator::verifyRunningProcessesFinished()
qCDebug(dcDebugServer()) << "All async processes are finished. Start compressing the file.";
m_compressProcess = new QProcess(this);
m_compressProcess->setProcessChannelMode(QProcess::MergedChannels);
m_compressProcess->setWorkingDirectory("/tmp");
m_compressProcess->setWorkingDirectory(QStandardPaths::writableLocation(QStandardPaths::TempLocation));
connect(m_compressProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(onCompressProcessFinished(int, QProcess::ExitStatus)));
m_compressProcess->start("tar", { "-zcf", m_reportFileName, "-C", "/tmp/", m_reportDirectory.dirName() } );
m_compressProcess->start("tar", { "-zcf", m_reportFileName, "-C", QStandardPaths::writableLocation(QStandardPaths::TempLocation) + "/", m_reportDirectory.dirName() } );
qCDebug(dcDebugServer()) << "Execut command" << m_compressProcess->program() << m_compressProcess->arguments();
}
}
@ -169,7 +171,7 @@ void DebugReportGenerator::saveEnv()
void DebugReportGenerator::cleanupReport()
{
QFile reportFile("/tmp/" + m_reportFileName);
QFile reportFile(QStandardPaths::writableLocation(QStandardPaths::TempLocation) + "/" + m_reportFileName);
if (reportFile.exists()) {
qCDebug(dcDebugServer()) << "Delete report file" << reportFile.fileName();
if (!reportFile.remove()) {
@ -263,7 +265,7 @@ void DebugReportGenerator::onCompressProcessFinished(int exitCode, QProcess::Exi
}
// Read the file
QFile reportFile("/tmp/" + m_reportFileName);
QFile reportFile(QStandardPaths::writableLocation(QStandardPaths::TempLocation) + "/" + m_reportFileName);
if (!reportFile.open(QIODevice::ReadOnly)) {
qCWarning(dcDebugServer()) << "Could not open report file name for reading" << reportFile.fileName();
emit finished(false);