Initial checkin
[opensuse:qtobs.git] / buildstatxmlreader.cpp
1 /*
2  *  Qt OBS - A Qt based OBS client
3  *
4  *  Copyright (C) 2010 Novell Inc, Klaas Freitag <freitag@suse.de>
5  *
6  *  This program is free software: you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation, either version 2 of the License, or
9  *  (at your option) version 3.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  *
19  *  --
20  *  Written by Klaas Freitag <freitag@suse.de>
21  *  Contributors:
22  */
23
24 #include <QDebug>
25 #include <QApplication>
26
27 #include "buildstatxmlreader.h"
28 #include "obsbuildresults.h"
29
30 BuildStatXmlReader::BuildStatXmlReader()
31     :OBSXmlReader()
32 {
33
34 }
35
36 bool BuildStatXmlReader::read(QIODevice *device)
37 {
38   // setDevice( device );
39   QByteArray arr = device->readAll();
40   qDebug() << "ALL contents: " << arr;
41   addData( arr );
42   return true;
43 }
44
45 bool BuildStatXmlReader::parse()
46 {
47   while (!atEnd()) {
48     readNext();
49
50     /*
51      * <result project="home:kfreitag:Kraft" repository="Debian_Etch" arch="i586">
52      * <status package="ctemplate" code="disabled"/>
53      * <status package="python-ReportLab" code="excluded"/>
54      * <status package="python-trml2pdf" code="disabled"/>
55      * <status package="Kraft" code="succeeded"/>
56      * </result>
57      */
58
59     if( isStartElement() ) {
60       qDebug() << "XML name: " << name();
61       if( name() == "result" ) {
62         QString repo = attributes().value("repository").toString();
63         QString arch = attributes().value("arch").toString();
64         QString prj  = attributes().value("project").toString();
65
66         OBSProjectBuildResult prjBuildResult;
67         prjBuildResult.setProject( prj );
68         prjBuildResult.setArchitecture( arch );
69         prjBuildResult.setRepository( repo );
70
71         prjBuildResult.setPackageBuildResults( parsePackageBuildResults() );
72
73         mProjectBuildResults.append( prjBuildResult );
74       }
75     }
76   }
77   qDebug() << "Paring error: " << error();
78   return !error();
79
80 }
81
82 QList<OBSPackageBuildResult> BuildStatXmlReader::parsePackageBuildResults()
83 {
84   Q_ASSERT( isStartElement() );
85   QList<OBSPackageBuildResult> list;
86   while (QXmlStreamReader::StartElement != readNext()) {}
87
88   Q_ASSERT( name() == "status" );
89
90   while (! (isEndElement() && name() == "result" ) ) {
91     QXmlStreamAttributes attribs = attributes();
92     if( name() == "status"  && isStartElement() ) {
93       list.append( OBSPackageBuildResult( attribs.value( "package" ).toString(),
94                                           attribs.value( "code" ).toString() ) );      
95     }
96     readNext();
97   }
98   return list;
99 }
100
101 OBSProjectBuildResults BuildStatXmlReader::buildResultList()
102 {
103   return mProjectBuildResults;
104 }