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 |
1 | 1 |
#include <QFile> |
2 |
#include <QFileInfo> |
|
3 |
#include <QDomDocument> |
|
4 |
#include <QDomElement> |
|
5 |
#include <QDomNode> |
|
6 |
#include <QMessageBox> |
|
7 |
||
8 |
#include <QtGlobal> |
|
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 | 11 |
|
12 |
#include <QGridLayout> |
|
13 |
#include <QLabel> |
|
14 |
||
15 |
#include <iostream> |
|
16 |
||
17 |
using namespace std; |
|
18 |
||
19 |
#include "AtAGlance.h" |
|
20 |
||
21 |
AtAGlance::AtAGlance(QString filename, QWidget *parent) |
|
22 |
{ |
|
23 |
setAttribute(Qt::WA_DeleteOnClose); |
|
24 |
||
25 |
QFile file(filename); |
|
26 |
QFileInfo fi(file); |
|
27 |
this->setWindowTitle("Status " + fi.baseName()); |
|
28 |
||
29 |
m_buildStatus = new BuildStatus(); |
|
30 |
m_buildStatus->setTime(fi.lastModified()); |
|
31 |
||
32 |
if (!file.open(QIODevice::ReadOnly)) { |
|
33 |
QMessageBox::warning(this, tr("Build Log Viewer"), tr("Cannot open log.")); |
|
34 |
return ; |
|
35 |
} |
|
36 |
m_log = new QDomDocument("Build Log"); |
|
37 |
if (!m_log->setContent(&file)) { |
|
38 |
QMessageBox::warning(this, tr("Build Log Viewer"), tr("Cannot set content.")); |
|
39 |
file.close(); |
|
40 |
return ; |
|
41 |
} |
|
42 |
file.close(); |
|
43 |
} |
|
44 |
||
45 |
AtAGlance::~AtAGlance() |
|
46 |
{ |
|
47 |
delete m_log; |
|
48 |
delete m_buildStatus; |
|
49 |
} |
|
50 |
||
51 |
// Walk Dom tree. |
|
52 |
void AtAGlance::traveAndPopulate() |
|
53 |
{ |
|
54 |
this->traveAndPopulate(m_log->documentElement()); |
|
55 |
} |
|
2
6894bf2709c0
add some regex to parse status information.
John Kern <johnk@symbian.org>
parents:
1
diff
changeset
|
56 |
|
1 | 57 |
void AtAGlance::traveAndPopulate(QDomElement e) |
58 |
{ |
|
59 |
QString name = e.tagName(); |
|
60 |
||
61 |
if (e.isNull()) |
|
62 |
{ |
|
63 |
return; |
|
64 |
} |
|
65 |
||
66 |
// if this is an info tags, look for |
|
67 |
// <info>System Definition file sf/app/organizer/package_definition.xml</info> |
|
68 |
if (name.compare("info",Qt::CaseInsensitive)== 0 ) |
|
69 |
{ |
|
70 |
// example |
|
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 | 73 |
re.setPatternSyntax(QRegExp::Wildcard); |
74 |
||
75 |
if (re.exactMatch( e.text() ) ) |
|
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 | 92 |
} |
93 |
} |
|
94 |
||
95 |
// if this is a status tag and the exit attribute is failed, the build failed. |
|
96 |
if (name.compare("status",Qt::CaseInsensitive)== 0 ) |
|
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 | 118 |
} |
119 |
||
120 |
QString text_debug; |
|
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 | 124 |
while(!e1.isNull()) |
125 |
{ |
|
126 |
this->traveAndPopulate(e1); |
|
127 |
e1 = e1.nextSibling().toElement(); |
|
128 |
name = e1.tagName(); |
|
129 |
text_debug = e1.text(); |
|
130 |
} |
|
131 |
} |
|
132 |
||
133 |
void AtAGlance::decideOnLayout() |
|
134 |
{ |
|
135 |
QGridLayout *layout = new QGridLayout(this); |
|
136 |
||
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 | 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 | 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 | 143 |
} |