1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/bugagent.cpp Fri Feb 19 13:47:03 2010 +0000
1.3 @@ -0,0 +1,127 @@
1.4 +#include "bugagent.h"
1.5 +
1.6 +#include "branchitem.h"
1.7 +#include "mainwindow.h"
1.8 +#include "vymmodel.h"
1.9 +
1.10 +extern Main *mainWindow;
1.11 +
1.12 +BugAgent::BugAgent (BranchItem *bi,const QString &bug)
1.13 +{
1.14 + if (!bi)
1.15 + {
1.16 + qWarning ("Const BugAgent: bi==NULL");
1.17 + return;
1.18 + }
1.19 + branchID=bi->getID();
1.20 + modelID=bi->getModel()->getID();
1.21 + bugID=bug;
1.22 +
1.23 + script="test/vym-bug.pl";
1.24 +
1.25 + p=new Process;
1.26 +
1.27 + connect (p, SIGNAL (finished(int,QProcess::ExitStatus) ),
1.28 + this, SLOT (processFinished(int,QProcess::ExitStatus) ));
1.29 +
1.30 + p->start (script,QStringList()<<bugID);
1.31 + if (!p->waitForStarted())
1.32 + {
1.33 + qWarning()<<"BugAgent::getBugzillaData couldn't start "<<script;
1.34 + return;
1.35 + }
1.36 +
1.37 + /*
1.38 + QString result=getStdout();
1.39 + while (result.endsWith("\n")) result.chop(1);
1.40 + //qWarning << QString(result);
1.41 + QString err=getErrout();
1.42 + if (!err.isEmpty())
1.43 + {
1.44 + qWarning << "BugAgent::getBugzillaData Error:\n";
1.45 + qWarning <<err;
1.46 + }
1.47 + else if (!result.isEmpty())
1.48 + {
1.49 + qWarning << "ok\n";
1.50 + }
1.51 +
1.52 + */
1.53 +}
1.54 +
1.55 +BugAgent::~BugAgent ()
1.56 +{
1.57 + delete p;
1.58 + qDebug ()<<"dest BugAgent";
1.59 +}
1.60 +
1.61 +void BugAgent::processFinished(int exitCode, QProcess::ExitStatus exitStatus)
1.62 +{
1.63 + if (exitStatus==QProcess::NormalExit)
1.64 + {
1.65 + VymModel *model=mainWindow->getModel (modelID);
1.66 + if (model)
1.67 + {
1.68 + BranchItem *bi=(BranchItem*)(model->findID (branchID));
1.69 + if (bi)
1.70 + {
1.71 + QString oldsel=model->getSelectString ();
1.72 + model->select (bi);
1.73 +
1.74 + // Now do needed changes:
1.75 +
1.76 + QString result=p->getStdout();
1.77 + while (result.endsWith("\n")) result.chop(1);
1.78 + //qWarning() << QString(result);
1.79 + QString err=p->getErrout();
1.80 + if (!err.isEmpty())
1.81 + {
1.82 + qWarning() << "VM::BugAgent Error:\n";
1.83 + qWarning() <<err;
1.84 + }
1.85 + else if (!result.isEmpty())
1.86 + {
1.87 + QString heading,cdate,mdate,state,whiteboard;
1.88 + QRegExp re("short_desc:(.*)\n");
1.89 + re.setMinimal(true);
1.90 + if (re.indexIn (result) !=-1) heading=re.cap(1);
1.91 +
1.92 + re.setPattern ("creation_ts:(.*)\n");
1.93 + if (re.indexIn (result) !=-1) cdate=re.cap(1);
1.94 +
1.95 + re.setPattern ("delta_ts:(.*)\n");
1.96 + if (re.indexIn (result) !=-1) mdate=re.cap(1);
1.97 +
1.98 + re.setPattern ("bug_status:(.*)\n");
1.99 + if (re.indexIn (result) !=-1) state=re.cap(1);
1.100 +
1.101 + re.setPattern ("status_whiteboard:(.*)\n");
1.102 + if (re.indexIn (result) !=-1) whiteboard=re.cap(1);
1.103 +
1.104 + model->setHeading (bugID + " - " + heading);
1.105 + qDebug() << "VM: heading="<<heading;
1.106 + qDebug() << "VM: cdate="<<cdate;
1.107 + qDebug() << "VM: mdate="<<mdate;
1.108 + qDebug() << "VM: state="<<state;
1.109 + qDebug() << "VM: wboard="<<whiteboard;
1.110 +
1.111 + //qDebug() <<"VM::getBugzillaData "<<script<<" returned:\n";
1.112 + //qDebug() <<QString(result);
1.113 + } else
1.114 + qWarning() << "VM::getBugzillaData "<<script<<" returned nothing\n";
1.115 +
1.116 +
1.117 +
1.118 + // Changes finished
1.119 + model->select (oldsel);
1.120 + } else
1.121 + qWarning ()<<"BugAgent: Found model, but not branch #"<<branchID;
1.122 + } else
1.123 + qWarning ()<<"BugAgent: Couldn't find model #"<<modelID;
1.124 + } else
1.125 + qWarning()<< "BugAgent: Process finished with exitCode="<<exitCode;
1.126 + delete (this);
1.127 +}
1.128 +
1.129 +
1.130 +