-
Notifications
You must be signed in to change notification settings - Fork 0
/
xzprocessexecute.cpp
123 lines (112 loc) · 4.29 KB
/
xzprocessexecute.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include "xzprocessexecute.h"
#include "mainwindow.h"
#include "xzdatebase.h"
#include "xzconfig.h"
#include <QFileInfo>
XZProcessExecute::XZProcessExecute()
{
}
XZProcessExecute::XZProcessExecute(void *mwindow)
{
XZOUTPUT
this->setTerminationEnabled(true);
stop_flag = 0;
xzconfig.Log(LOG_INFO,"Create instance of XZProcessExecute");
cssh = new XZSSh(this);
this->lisExecute = 0;
this->lisHostInfo = 0;
connect(this,SIGNAL(ChangeStatus(QString)),(MainWindow*)mwindow,SLOT(setStatusBarTip(QString)));
}
void XZProcessExecute::onClickStop()
{
xzconfig.Log(LOG_INFO,"You clicked STOP");
emit this->ChangeStatus(QString("stopping..."));
this->stop_flag = 1;
this->terminate();
}
//execute the xz_execute item
void XZProcessExecute::process(QList<DB_XZ_EXECUTE>* lisExecute,QList<DB_XZ_HOSTINFO>* lisHostInfo)
{
this->lisExecute = lisExecute;
this->lisHostInfo = lisHostInfo;
this->start();
}
XZProcessExecute::~XZProcessExecute()
{
cssh->xzssh_disconnect();
}
void XZProcessExecute::run()
{
xzconfig.Log(LOG_INFO,"begin to process xz_execute item");
emit this->ChangeStatus(QString("Running..."));
if(lisExecute == 0 || lisHostInfo == 0)
{
xzconfig.Log(LOG_ERROR,"XZProcessExecute::process : input parameter not corrent!");
return;
}
xzconfig.Log(LOG_INFO, QString("sizeof(lisExecute) = ") + QString::number(lisExecute->size()));
for(QList<DB_XZ_EXECUTE>::Iterator cur = this->lisExecute->begin();
cur != this->lisExecute->end();
cur ++)
{
if(this->stop_flag == 1)
{
this->stop_flag = 0;
break;
}
xzconfig.Log(LOG_OUTPUT,QString(tr("Current Item: ") + QString::number(cur - this->lisExecute->begin() + 1) + '|' + cur->Name));
emit this->CurrentExecuteNo(cur - this->lisExecute->begin() + 1);
//xzconfig.Log(LOG_INFO, QString("sizeof(lisHostInfo) = ") + QString::number(lisHostInfo->size()));
QList<DB_XZ_HOSTINFO>::Iterator iter;
for(iter = lisHostInfo->begin();
iter != lisHostInfo->end();
iter ++)
{
//xzconfig.Log(LOG_INFO, QString("iter->key = ") + QString::number(iter->Key) + "; cur->Key = " + QString::number(cur->Key));
if (iter->Key == cur->Host)
{
if(cssh->xzssh_connect(iter->IP,22,iter->User,iter->Passwd))
{
xzconfig.Log(LOG_ERROR,QString(tr("Cannot connect to the server:")) + iter->IP);
return;
}
xzconfig.Log(LOG_OUTPUT,QString(tr("Connected to the server:")) + iter->Name);
if(cur->Type == 1)
{
QFileInfo fi(cur->Command);
if(cssh->xzssh_sftpGet(cur->Command,(QString("recv/") + fi.fileName())))
{
xzconfig.Log(LOG_ERROR,QString(tr("Cannot get the file:"))
+ cur->Command
+ tr(", ErrDesc: ") + cssh->xzssh_getErrMsg());
emit this->ChangeStatus(QString("ready"));
emit this->CurrentExecuteNo(0);
return;
}
xzconfig.Log(LOG_OUTPUT,QString("Successfully get file: ") + cur->Command);
}
else if(cur->Type == 0)
{
if(cssh->xzssh_exec(cur->Command,NULL))
{
xzconfig.Log(LOG_ERROR,QString(tr("Cannot execute the command:"))
+ cur->Command
+ tr(", ErrDesc: ") + cssh->xzssh_getErrMsg());
emit this->ChangeStatus(QString("ready"));
emit this->CurrentExecuteNo(0);
return;
}
xzconfig.Log(LOG_OUTPUT,QString("Successfully execute command: ") + cur->Command);
}
break;
}
}
if (iter == lisHostInfo->end())
{
xzconfig.Log(LOG_ERROR,QString(tr("Cannot find Hostinfo ID: ")) + QString:: number(cur->Host));
}
}
emit this->CurrentExecuteNo(0);
emit this->ChangeStatus(QString("ready"));
return;
}