bugagent.cpp
author insilmaril
Fri, 09 Apr 2010 14:24:04 +0000
changeset 846 f0fe7c36ec5c
parent 825 1ad892c1a709
permissions -rw-r--r--
Version 1.13.3 and added treeeditor.png
insilmaril@823
     1
#include "bugagent.h"
insilmaril@823
     2
insilmaril@823
     3
#include "branchitem.h"
insilmaril@823
     4
#include "mainwindow.h"
insilmaril@823
     5
#include "vymmodel.h"
insilmaril@823
     6
insilmaril@823
     7
extern Main *mainWindow;
insilmaril@823
     8
insilmaril@823
     9
BugAgent::BugAgent (BranchItem *bi,const QString &bug)
insilmaril@823
    10
{
insilmaril@823
    11
	if (!bi) 
insilmaril@823
    12
	{
insilmaril@823
    13
		qWarning ("Const BugAgent: bi==NULL");
insilmaril@823
    14
		return;
insilmaril@823
    15
	}
insilmaril@823
    16
	branchID=bi->getID();
insilmaril@823
    17
	modelID=bi->getModel()->getID();
insilmaril@823
    18
	bugID=bug;
insilmaril@823
    19
insilmaril@823
    20
	script="test/vym-bug.pl";
insilmaril@823
    21
insilmaril@823
    22
	p=new Process;
insilmaril@823
    23
insilmaril@823
    24
	connect (p, SIGNAL (finished(int,QProcess::ExitStatus) ), 
insilmaril@823
    25
		this, SLOT (processFinished(int,QProcess::ExitStatus) ));
insilmaril@823
    26
insilmaril@823
    27
	p->start (script,QStringList()<<bugID);
insilmaril@823
    28
	if (!p->waitForStarted())
insilmaril@823
    29
	{
insilmaril@823
    30
		qWarning()<<"BugAgent::getBugzillaData couldn't start "<<script;
insilmaril@823
    31
		return;
insilmaril@823
    32
	}	
insilmaril@823
    33
}
insilmaril@823
    34
insilmaril@823
    35
BugAgent::~BugAgent ()
insilmaril@823
    36
{
insilmaril@823
    37
	delete p;
insilmaril@823
    38
}
insilmaril@823
    39
insilmaril@823
    40
void BugAgent::processFinished(int exitCode, QProcess::ExitStatus exitStatus)
insilmaril@823
    41
{
insilmaril@823
    42
	if (exitStatus==QProcess::NormalExit)
insilmaril@823
    43
	{
insilmaril@823
    44
		VymModel *model=mainWindow->getModel (modelID);
insilmaril@823
    45
		if (model)
insilmaril@823
    46
		{
insilmaril@823
    47
			BranchItem *bi=(BranchItem*)(model->findID (branchID));		
insilmaril@823
    48
			if (bi)
insilmaril@823
    49
			{
insilmaril@823
    50
				QString oldsel=model->getSelectString ();
insilmaril@823
    51
				model->select (bi);
insilmaril@823
    52
insilmaril@823
    53
				// Now do needed changes:
insilmaril@823
    54
insilmaril@823
    55
				QString result=p->getStdout();
insilmaril@823
    56
				while (result.endsWith("\n")) result.chop(1); 
insilmaril@823
    57
				//qWarning() << QString(result);
insilmaril@823
    58
				QString err=p->getErrout();
insilmaril@823
    59
				if (!err.isEmpty())
insilmaril@823
    60
				{
insilmaril@823
    61
					qWarning() << "VM::BugAgent Error:\n";
insilmaril@823
    62
					qWarning() <<err;
insilmaril@823
    63
				}
insilmaril@823
    64
				else if (!result.isEmpty())
insilmaril@823
    65
				{
insilmaril@823
    66
					QString heading,cdate,mdate,state,whiteboard;
insilmaril@823
    67
					QRegExp re("short_desc:(.*)\n");
insilmaril@823
    68
					re.setMinimal(true);
insilmaril@823
    69
					if (re.indexIn (result) !=-1) heading=re.cap(1);
insilmaril@823
    70
insilmaril@823
    71
					re.setPattern ("creation_ts:(.*)\n");
insilmaril@823
    72
					if (re.indexIn (result) !=-1) cdate=re.cap(1);
insilmaril@823
    73
insilmaril@823
    74
					re.setPattern ("delta_ts:(.*)\n");
insilmaril@823
    75
					if (re.indexIn (result) !=-1) mdate=re.cap(1);
insilmaril@823
    76
insilmaril@823
    77
					re.setPattern ("bug_status:(.*)\n");
insilmaril@823
    78
					if (re.indexIn (result) !=-1) state=re.cap(1);
insilmaril@823
    79
insilmaril@823
    80
					re.setPattern ("status_whiteboard:(.*)\n");
insilmaril@823
    81
					if (re.indexIn (result) !=-1) whiteboard=re.cap(1);
insilmaril@823
    82
insilmaril@823
    83
					model->setHeading (bugID + " - " + heading);
insilmaril@823
    84
					qDebug() << "VM: heading="<<heading;
insilmaril@823
    85
					qDebug() << "VM:   cdate="<<cdate;
insilmaril@823
    86
					qDebug() << "VM:   mdate="<<mdate;
insilmaril@823
    87
					qDebug() << "VM:   state="<<state;
insilmaril@823
    88
					qDebug() << "VM:  wboard="<<whiteboard;
insilmaril@823
    89
					
insilmaril@823
    90
					//qDebug() <<"VM::getBugzillaData  "<<script<<" returned:\n";
insilmaril@823
    91
					//qDebug() <<QString(result);
insilmaril@823
    92
				} else	
insilmaril@823
    93
					qWarning() << "VM::getBugzillaData "<<script<<"  returned nothing\n";
insilmaril@823
    94
insilmaril@823
    95
insilmaril@823
    96
insilmaril@823
    97
				// Changes finished
insilmaril@823
    98
				model->select (oldsel);
insilmaril@823
    99
			} else
insilmaril@823
   100
				qWarning ()<<"BugAgent: Found model, but not branch #"<<branchID;
insilmaril@823
   101
		} else
insilmaril@823
   102
			qWarning ()<<"BugAgent: Couldn't find model #"<<modelID;
insilmaril@823
   103
	} else		
insilmaril@823
   104
		qWarning()<< "BugAgent: Process finished with exitCode="<<exitCode;
insilmaril@823
   105
	delete (this);
insilmaril@823
   106
}
insilmaril@823
   107
insilmaril@823
   108
insilmaril@823
   109