Skip to content

Commit

Permalink
MythArchive: fix the missing logs when doing a native archive import/…
Browse files Browse the repository at this point in the history
…export

The new logging stuff was causing both the export and import of native archives
logging to not be shown in the log viewer this fixes that and also makes the
log viewer wait a while for the logs before giving up which should fix the
logs not always showing the first time.

Fixes #10505.
  • Loading branch information
paul-h authored and Paul Harrison committed Mar 24, 2013
1 parent 84c44dd commit 52a7c11
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 22 deletions.
13 changes: 4 additions & 9 deletions mythplugins/mytharchive/mytharchive/exportnative.cpp
Expand Up @@ -476,21 +476,16 @@ void ExportNative::runScript()
QString configDir = tempDir + "config";
QString commandline;

// remove existing progress.log if present
if (QFile::exists(logDir + "/progress.log"))
QFile::remove(logDir + "/progress.log");
// remove any existing logs
myth_system("rm -f " + logDir + "/*.log");

// remove cancel flag file if present
if (QFile::exists(logDir + "/mythburncancel.lck"))
QFile::remove(logDir + "/mythburncancel.lck");

createConfigFile(configDir + "/mydata.xml");
commandline = "mytharchivehelper --nativearchive --outfile " + configDir +
"/mydata.xml"; // job file
commandline += logPropagateArgs;
if (!logPropagateQuiet())
commandline += " --quiet";
commandline += " > " + logDir + "/progress.log 2>&1 &"; // Logs
commandline = "mytharchivehelper --logpath " + logDir + " --nativearchive "
"--outfile " + configDir + "/mydata.xml"; // job file

uint flags = kMSRunBackground | kMSDontBlockInputDevs |
kMSDontDisableDrawing;
Expand Down
12 changes: 4 additions & 8 deletions mythplugins/mytharchive/mytharchive/importnative.cpp
Expand Up @@ -449,16 +449,12 @@ void ImportNative::finishedPressed()

QString logDir = tempDir + "logs";

// remove existing progress.log if prescent
if (QFile::exists(logDir + "/progress.log"))
QFile::remove(logDir + "/progress.log");
// remove any existing logs
myth_system("rm -f " + logDir + "/*.log");

commandline = "mytharchivehelper --importarchive --infile \"" + m_xmlFile +
commandline = "mytharchivehelper --logpath " + logDir + " --importarchive "
"--infile \"" + m_xmlFile +
"\" --chanid " + chanID;
commandline += logPropagateArgs;
if (!logPropagateQuiet())
commandline += " --quiet";
commandline += " > " + logDir + "/progress.log 2>&1 &";

uint flags = kMSRunBackground | kMSDontBlockInputDevs |
kMSDontDisableDrawing;
Expand Down
53 changes: 51 additions & 2 deletions mythplugins/mytharchive/mytharchive/logviewer.cpp
Expand Up @@ -26,12 +26,49 @@ void showLogViewer(void)
{
MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
QString logDir = getTempDirectory() + "logs";
QString progressLog;
QString fullLog;

// wait for a log file to be available
int tries = 10;
while (tries--)
{
if (QFile::exists(logDir + "/progress.log"))
progressLog = logDir + "/progress.log";

if (QFile::exists(logDir + "/mythburn.log"))
fullLog = logDir + "/mythburn.log";

// we wait for both the progress.log and mythburn.log
if ((!progressLog.isEmpty()) && (!fullLog.isEmpty()))
break;

// or we wait for a log from mytharchivehelper
if (progressLog.isEmpty() && fullLog.isEmpty())
{
QStringList logFiles;
QStringList filters;
filters << "*.log";

QDir d(logDir);
logFiles = d.entryList(filters, QDir::Files | QDir::Readable, QDir::Time);

if (logFiles.count())
{
// the first log file should be the newest one available
progressLog = logDir + '/' + logFiles[0];
break;
}
}

sleep(1);
}

// do any logs exist?
if (QFile::exists(logDir + "/progress.log") || QFile::exists(logDir + "/mythburn.log"))
if ((!progressLog.isEmpty()) || (!fullLog.isEmpty()))
{
LogViewer *viewer = new LogViewer(mainStack);
viewer->setFilenames(logDir + "/progress.log", logDir + "/mythburn.log");
viewer->setFilenames(progressLog, fullLog);
if (viewer->Create())
mainStack->AddScreen(viewer);
}
Expand Down Expand Up @@ -244,6 +281,8 @@ QString LogViewer::getSetting(const QString &key)

bool LogViewer::loadFile(QString filename, QStringList &list, int startline)
{
bool strip = !(filename.endsWith("progress.log") || filename.endsWith("mythburn.log"));

list.clear();

QFile file(filename);
Expand All @@ -267,6 +306,16 @@ bool LogViewer::loadFile(QString filename, QStringList &list, int startline)
while ( !stream.atEnd() )
{
s = stream.readLine();

if (strip)
{
// the logging from mytharchivehelper contains a lot of junk
// we are not interested in so just strip it out
int pos = s.indexOf(" - ");
if (pos != -1)
s = s.mid(pos + 3);
}

list.append(s);
}
file.close();
Expand Down
5 changes: 2 additions & 3 deletions mythplugins/mytharchive/mytharchive/mythburn.cpp
Expand Up @@ -942,9 +942,8 @@ void MythBurn::runScript()
QString configDir = tempDir + "config";
QString commandline;

// remove existing progress.log if present
if (QFile::exists(logDir + "/progress.log"))
QFile::remove(logDir + "/progress.log");
// remove any existing logs
myth_system("rm -f " + logDir + "/*.log");

// remove cancel flag file if present
if (QFile::exists(logDir + "/mythburncancel.lck"))
Expand Down

0 comments on commit 52a7c11

Please sign in to comment.