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