source: src-qt4/pc-softwaremanager/processManager.cpp @ c24d6287

releng/10.0.1releng/10.0.2releng/10.0.3
Last change on this file since c24d6287 was c24d6287, checked in by Ken Moore <ken@…>, 8 months ago

Make sure that when an upgrade fails in the AppCafe?, it defaults to trying to download the latest PBI manually before throwing an error. This catches the situations where the user is actually "upgrading" to an older version of an application because of an un-approval of the latest PBI for some reason.

  • Property mode set to 100644
File size: 9.1 KB
Line 
1/***************************************************************************
2 *   Copyright (C) 2011 - iXsystems                                       *
3 *   kris@pcbsd.org  *
4 *   tim@pcbsd.org   *
5 *   ken@pcbsd.org   *
6 *                                                                         *
7 *   Permission is hereby granted, free of charge, to any person obtaining *
8 *   a copy of this software and associated documentation files (the       *
9 *   "Software"), to deal in the Software without restriction, including   *
10 *   without limitation the rights to use, copy, modify, merge, publish,   *
11 *   distribute, sublicense, and/or sell copies of the Software, and to    *
12 *   permit persons to whom the Software is furnished to do so, subject to *
13 *   the following conditions:                                             *
14 *                                                                         *
15 *   The above copyright notice and this permission notice shall be        *
16 *   included in all copies or substantial portions of the Software.       *
17 *                                                                         *
18 *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       *
19 *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    *
20 *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
21 *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR     *
22 *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
23 *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
24 *   OTHER DEALINGS IN THE SOFTWARE.                                       *
25 ***************************************************************************/
26 #include "processManager.h"
27
28ProcessManager::ProcessManager(){
29    //Initialize the UPDATE Process
30    upProc = new DLProcess(this);
31        upProc->setDLType("PBI");
32    connect(upProc, SIGNAL(UpdateMessage(QString)), this, SLOT(slotUpProcMessage(QString)) );
33    connect(upProc, SIGNAL(UpdatePercent(QString, QString, QString)), this, SLOT(slotUpProcStats(QString,QString, QString)) );
34    connect(upProc, SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(slotUpProcFinished()) );
35       
36    //Initialize the REMOVE Process
37    remProc = new DLProcess(this);
38        //remProc->setDLType("PBI"); //Does not need download parsing - just use standard message output
39    connect(remProc, SIGNAL(UpdateMessage(QString)), this, SLOT(slotRemProcMessage(QString)) );
40    connect(remProc, SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(slotRemProcFinished()) );
41       
42    //Initialize the DOWNLOAD Process
43    dlProc = new DLProcess(this);
44        dlProc->setDLType("PBI");
45    connect(dlProc, SIGNAL(UpdateMessage(QString)), this, SLOT(slotDlProcMessage(QString)) );
46    connect(dlProc, SIGNAL(UpdatePercent(QString, QString, QString)), this, SLOT(slotDlProcStats(QString,QString, QString)) );
47    connect(dlProc, SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(slotDlProcFinished()) );
48       
49    //Initialize the INSTALL Process
50    inProc = new DLProcess(this);
51        //inProc->setDLType("PBI"); //Does not need download parsing - just use standard message output
52    connect(inProc, SIGNAL(UpdateMessage(QString)), this, SLOT(slotInProcMessage(QString)) );
53    connect(inProc, SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(slotInProcFinished()) );
54   
55    //Initialize the OTHER Process
56    otProc = new DLProcess(this);
57        //otProc->setDLType("PBI"); //Does not need download parsing - just use standard message output
58    connect(otProc, SIGNAL(UpdateMessage(QString)), this, SLOT(slotOtProcMessage(QString)) );
59    connect(otProc, SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(slotOtProcFinished()) );
60}
61
62ProcessManager::~ProcessManager(){
63}
64
65void ProcessManager::goToDirectory(ProcessID ID, QString dir){
66  if( ID == UPDATE ){
67    upProc->setWorkingDirectory(dir);     
68  }else if( ID == REMOVE ){
69    remProc->setWorkingDirectory(dir);           
70  }else if( ID == DOWNLOAD ){
71    dlProc->setWorkingDirectory(dir);     
72  }else if( ID == INSTALL ){
73    inProc->setWorkingDirectory(dir);             
74  }else if( ID == OTHER ){
75    otProc->setWorkingDirectory(dir);             
76  }     
77}
78
79// =========================
80// ===== PUBLIC ACCESS =====
81// =========================
82void ProcessManager::startProcess(ProcessID ID, QString cmd){
83  if( ID == UPDATE ){
84    qDebug() << "Update Process Started:" << cmd;
85    upLog.clear(); //clear the log for action
86    upProc->start(cmd);   
87  }else if( ID == REMOVE ){
88    qDebug() << "Removal Process Started:" << cmd;
89    remLog.clear();
90    if( cmd.contains("pbi_delete") ){ remStrictErrChecking = true; }
91    else{ remStrictErrChecking=false; }
92    remProc->start(cmd);                 
93  }else if( ID == DOWNLOAD ){
94    qDebug() << "Download Process Started:" << cmd;
95    dlLog.clear();
96    dlProc->start(cmd);           
97  }else if( ID == INSTALL ){
98    qDebug() << "Install Process Started:" << cmd;
99    inLog.clear();
100    inProc->start(cmd);           
101  }else if( ID == OTHER ){
102    qDebug() << "Other Process Started:" << cmd;
103    otProc->start(cmd);           
104  }
105       
106}
107
108void ProcessManager::stopProcess(ProcessID ID){
109  if((ID == ALL) || (ID == UPDATE)){
110    upProc->terminate();         
111  }
112  if((ID == ALL) || (ID == REMOVE)){
113    remProc->terminate();         
114  }
115  if((ID == ALL) || (ID == DOWNLOAD)){
116    dlProc->terminate();         
117  }
118  if((ID == ALL) || (ID == INSTALL)){
119    inProc->terminate();         
120  }
121  if((ID == ALL) || (ID == OTHER)){
122    otProc->terminate();         
123  }     
124}
125
126QStringList ProcessManager::getProcessLog(ProcessID ID){
127  if( ID == UPDATE ){ return upLog; }
128  else if( ID == REMOVE ){ return remLog; }
129  else if( ID == DOWNLOAD ){ return dlLog; }
130  else if( ID == INSTALL ){ return inLog; }
131  else{ return QStringList(); }
132}
133
134// =========================
135// ===== PRIVATE SLOTS =====
136// =========================
137  /*DOWNLOAD NOTIFICATION CODES:
138  Download complete: "DLDONE"
139  Download running: "DLSTAT::<percent>::<total size>::<download speed>"
140        -- A value of "??" means that it is unknown
141  Download starting: "DLSTART"
142  */
143
144// == UPDATE PROCESS ==
145void ProcessManager::slotUpProcMessage(QString msg){
146  //Add the message to the log
147  upLog << msg;
148 
149  //Now send it out
150  emit ProcessMessage(UPDATE, msg);
151}
152
153void ProcessManager::slotUpProcStats(QString percent, QString size, QString speed){
154  //Format the display string for output
155  QString out = "DLSTAT::"+percent+"::"+size+"::"+speed;
156  emit ProcessMessage(UPDATE, out);
157}
158
159void ProcessManager::slotUpProcFinished(){
160  if(upProc->exitStatus() != QProcess::NormalExit || upProc->exitCode() != 0){
161    //Emit the command log
162    qDebug() << "Update Process Error Log:\n"<<upLog.join("\n");
163    emit ProcessError(UPDATE, upLog);
164  }else{
165    qDebug() << "Update Process Finished";
166    emit ProcessFinished(UPDATE);         
167  }
168}
169
170// == REMOVE PROCESS ==
171void ProcessManager::slotRemProcMessage(QString msg){
172  //Add the message to the log
173  remLog << msg;
174  //Now send it out
175  emit ProcessMessage(REMOVE, msg);
176}
177
178void ProcessManager::slotRemProcFinished(){
179  if(remProc->exitStatus() != QProcess::NormalExit || (remProc->exitCode() != 0 && remStrictErrChecking) ){
180    qDebug() << "Removal Process Error Log:\n"<<remLog.join("\n");
181    emit ProcessError(REMOVE, remLog);
182  }else{
183    qDebug() << "Removal Process Finished";
184    emit ProcessFinished(REMOVE);         
185  }
186}
187
188// == DOWNLOAD PROCESS ==
189void ProcessManager::slotDlProcMessage(QString msg){
190  //Check for DL start/finish messages
191  //Add the message to the log
192  dlLog << msg;
193  //Now send it out
194  emit ProcessMessage(DOWNLOAD, msg);
195}
196
197void ProcessManager::slotDlProcStats(QString percent, QString size, QString speed){
198  //Format the display string for output
199  QString out = "DLSTAT::"+percent+"::"+size+"::"+speed;
200  emit ProcessMessage(DOWNLOAD, out);
201}
202
203void ProcessManager::slotDlProcFinished(){
204  if(dlProc->exitStatus() != QProcess::NormalExit || dlProc->exitCode() != 0){
205    qDebug() << "Download Process Error Log:\n"<<dlLog.join("\n");
206    emit ProcessError(DOWNLOAD, dlLog);
207  }else{
208    qDebug() << "Download Process Finished";
209    emit ProcessFinished(DOWNLOAD);       
210  }
211}
212
213// == INSTALL PROCESS ==
214void ProcessManager::slotInProcMessage(QString msg){
215  //Add the message to the log
216  inLog << msg;
217  //Now send it out
218  emit ProcessMessage(INSTALL, msg);
219}
220
221void ProcessManager::slotInProcFinished(){
222  if(inProc->exitStatus() != QProcess::NormalExit || inProc->exitCode() != 0){
223    qDebug() << "Install Process Error Log:\n"<<inLog.join("\n");
224    emit ProcessError(INSTALL, inLog);
225  }else{
226    qDebug() << "Install Process Finished";
227    emit ProcessFinished(INSTALL);       
228  }
229}
230
231// == OTHER PROCESS ==
232void ProcessManager::slotOtProcMessage(QString msg){
233  //send it out (no logging - this channel is for quick commands with almost no output)
234  emit ProcessMessage(OTHER, msg);
235}
236
237void ProcessManager::slotOtProcFinished(){
238  if(otProc->exitStatus() != QProcess::NormalExit){
239    QString msg = otProc->readAllStandardError();
240    if(msg.isEmpty()){ msg = otProc->readAllStandardOutput(); }
241    if(msg.isEmpty()){ msg = tr("Unknown Error"); }
242    qDebug() << "Other Process Error:"<<msg;
243    emit ProcessError(OTHER, QStringList(msg));
244  }else{
245    qDebug() << "Other Process Finished";
246    emit ProcessFinished(OTHER);         
247  }
248}
249
Note: See TracBrowser for help on using the repository browser.