BuildLogViewer/AtAGlance.cpp
author John Kern <johnk@symbian.org>
Thu, 03 Sep 2009 16:31:30 -0700
changeset 2 6894bf2709c0
parent 1 8e9c5760ce6f
child 3 e6d1a78b6db9
permissions -rwxr-xr-x
add some regex to parse status information.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
     1
#include <QFile>
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
     2
#include <QFileInfo>
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
     3
#include <QDomDocument>
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
     4
#include <QDomElement>
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
     5
#include <QDomNode>
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
     6
#include <QMessageBox>
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
     7
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
     8
#include <QtGlobal>
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
     9
#include <QRegExp>
2
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
    10
#include <QStringList>
1
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    11
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    12
#include <QGridLayout>
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    13
#include <QLabel>
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    14
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    15
#include <iostream>
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    16
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    17
using namespace std;
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    18
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    19
#include "AtAGlance.h"
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    20
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    21
AtAGlance::AtAGlance(QString filename, QWidget *parent)
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    22
{
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    23
    setAttribute(Qt::WA_DeleteOnClose);
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    24
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    25
    QFile file(filename);
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    26
    QFileInfo fi(file);
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    27
    this->setWindowTitle("Status " + fi.baseName());
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    28
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    29
    m_buildStatus = new BuildStatus();
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    30
    m_buildStatus->setTime(fi.lastModified());
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    31
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    32
    if (!file.open(QIODevice::ReadOnly)) {
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    33
        QMessageBox::warning(this, tr("Build Log Viewer"), tr("Cannot open log."));
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    34
        return ;
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    35
    }
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    36
    m_log = new QDomDocument("Build Log");
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    37
    if (!m_log->setContent(&file)) {
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    38
        QMessageBox::warning(this, tr("Build Log Viewer"), tr("Cannot set content."));
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    39
        file.close();
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    40
        return ;
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    41
    }
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    42
    file.close();
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    43
}
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    44
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    45
AtAGlance::~AtAGlance()
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    46
{
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    47
    delete m_log;
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    48
    delete m_buildStatus;
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    49
}
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    50
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    51
// Walk Dom tree.
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    52
void AtAGlance::traveAndPopulate()
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    53
{
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    54
    this->traveAndPopulate(m_log->documentElement());
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    55
}
2
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
    56
1
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    57
void AtAGlance::traveAndPopulate(QDomElement e)
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    58
{
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    59
    QString name = e.tagName();
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    60
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    61
    if (e.isNull())
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    62
    {
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    63
        return;
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    64
    }
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    65
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    66
    //  if this is an info tags, look for
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    67
    //      <info>System Definition file sf/app/organizer/package_definition.xml</info>
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    68
    if (name.compare("info",Qt::CaseInsensitive)== 0 )
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    69
    {
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    70
        // example
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    71
        // System Definition file sf/app/organizer/package_definition.xml
2
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
    72
        QRegExp re("System*package_definition.xml");
1
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    73
        re.setPatternSyntax(QRegExp::Wildcard);
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    74
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    75
        if (re.exactMatch( e.text() ) )
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    76
        {
2
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
    77
            QRegExp reToken("*package_definition.xml");
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
    78
            // Which regex syntax should be used? Wildcard is ...
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
    79
            reToken.setPatternSyntax(QRegExp::Wildcard);
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
    80
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
    81
            QStringList tokens = e.text().split(" ");
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
    82
            QStringList::const_iterator constIterator;
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
    83
            for (constIterator = tokens.constBegin();
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
    84
                    constIterator != tokens.constEnd();
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
    85
                    ++constIterator)
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
    86
            {
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
    87
                if (reToken.exactMatch(*constIterator))
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
    88
                {
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
    89
                    m_buildStatus->setName((*constIterator).toLocal8Bit().constData());
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
    90
                }
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
    91
            }
1
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    92
        }
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    93
    }
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    94
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    95
    // if this is a status tag and the exit attribute is failed, the build failed.
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    96
    if (name.compare("status",Qt::CaseInsensitive)== 0 )
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
    97
    {
2
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
    98
        QString rc = e.attribute("exit");
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
    99
        if (!rc.isEmpty() && (rc.compare("failed", Qt::CaseInsensitive) == 0))
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
   100
        {
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
   101
            m_buildStatus->setStatus(false);
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
   102
        }
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
   103
    }
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
   104
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
   105
    // unforunately, the build log isn't valid xml.  The recipe tag often contains
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
   106
    // trace output from a shell program in addition to the status tag.  Sigh.
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
   107
    // So this condition looks for the status tag in the body for the recipe tag.
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
   108
    // here is what the status tag should look like:
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
   109
    //   <status exit='ok' attempt='1' />
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
   110
    if (name.compare("recipe",Qt::CaseInsensitive)== 0 )
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
   111
    {
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
   112
        QRegExp re("*status exit*fail*");
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
   113
        re.setPatternSyntax(QRegExp::Wildcard); 
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
   114
        if (re.exactMatch(e.text()))
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
   115
        {
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
   116
            m_buildStatus->setStatus(false);
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
   117
        }
1
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   118
    }
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   119
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   120
    QString text_debug;
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   121
    QDomElement e1 = e.firstChild().toElement();
2
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
   122
    name = e1.tagName();
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
   123
    text_debug = e1.text();
1
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   124
    while(!e1.isNull())
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   125
    {
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   126
        this->traveAndPopulate(e1);
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   127
        e1 = e1.nextSibling().toElement();
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   128
        name = e1.tagName();
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   129
        text_debug = e1.text();
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   130
    }
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   131
}
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   132
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   133
void AtAGlance::decideOnLayout()
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   134
{
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   135
    QGridLayout *layout = new QGridLayout(this);
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   136
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   137
    layout->addWidget(new QLabel("What: "), 1, 1);
2
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
   138
    layout->addWidget(new QLabel(*m_buildStatus->name()),1,2);
1
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   139
    layout->addWidget(new QLabel("When: "), 2, 1);
2
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
   140
    layout->addWidget(new QLabel(m_buildStatus->time()) ,2,2);
1
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   141
    layout->addWidget(new QLabel("Status: "), 3, 1);
2
6894bf2709c0 add some regex to parse status information.
John Kern <johnk@symbian.org>
parents: 1
diff changeset
   142
    layout->addWidget(new QLabel(*m_buildStatus->status()),3,2);
1
8e9c5760ce6f working on a status view
John Kern <johnk@symbian.org>
parents:
diff changeset
   143
}