Exemple #1
0
 def operation(self):
     try:
         while len(self.stepList):
             #================上传Log=================
             if self.stepList[0] == 'up':
                 if self.data[self.stepList[0]][0] == '!':
                     notNullWildcard = [uploadFileName for uploadFileName in re.split('\|', self.data[self.stepList[0]][1:]) if uploadFileName]
                     print notNullWildcard
                     self.copyLog(self.localpath, notNullWildcard)
                 else:
                     notNullWildcard = [uploadFileName for uploadFileName in re.split('\|', self.data[self.stepList[0]]) if uploadFileName]
                     self.copyLog(self.localpath, notNullWildcard, isfull = True)
                 if self.copyLogNames:
                     self.stepList[0] = 'chkCopyLog'
                 else:
                     del(self.stepList[0])
                 continue
             #================上传Log=================
             #================下载文件=================
             elif self.stepList[0] == 'down':
                 chkPath('%shistory' % self.localpath)
                 for flag in re.split('\|', self.data[self.stepList[0]]):
                     tcmd = '%shistory\\%s' % (self.localpath, flag)
                     runCMD('del /q /f "%s(5)"' % tcmd)
                     runCMD('ren "%s(4)" "%s(5)"' % (tcmd, flag))
                     runCMD('ren "%s(3)" "%s(4)"' % (tcmd, flag))
                     runCMD('ren "%s(2)" "%s(3)"' % (tcmd, flag))
                     runCMD('ren "%s(1)" "%s(2)"' % (tcmd, flag))
                     runCMD('copy /y "%s%s" "%s(1)"' % (self.localpath, flag, tcmd))
                     runCMD('del /q /f "%s%s"' % (self.localpath, flag))
                     log.LOG.info('成功下载文件%s' % flag)
                     self.result.append('成功下载文件%s\n'%flag)
                 log.LOG.debug(mylib.rar.decompression('down', self.localpath)) #异步解压文件
                 self.stepList[0] = 'chkDecompression'
                 continue
             elif self.stepList[0] == 'chkCopyLog':
                     for n in self.copyLogNames:
                         try:
                             tempfile = open(r'.\temp\%s'%n, 'r')
                             tempfile.close()
                         except:
                             return
                     os.popen('start msg %username% "log已收集,请继续测试!"')
                     log.LOG.debug(mylib.rar.compression('up', '.\\temp\\', self.copyLogNames))
                     self.stepList[0] = 'chkCompression'
                     continue
             elif self.stepList[0] == 'chkCompression':
                 if 'Rar.exe' in os.popen('tasklist /FI "IMAGENAME eq rar.exe"').read():
                     return
                 else:
                     try:
                         tempfile = open(r'.\temp\up.rar', 'r')
                         tempfile.close()
                         if self.login:
                             package = mylib.package.pack4('%s_%s'%(USER, self.returnIP))
                         else:
                             package = mylib.package.pack4(self.returnIP)
                         self.result.append('成功压缩文件')
                         self.s_pack.append(package)
                     except:
                         self.result.append('压缩失败!')
                         log.LOG.error('压缩失败')
                     del(self.stepList[0])
                     continue
             elif self.stepList[0] == 'chkDecompression':
                 if 'Rar.exe' in os.popen('tasklist /FI "IMAGENAME eq rar.exe"').read():
                     return
                 else:
                     for fileName in re.split('\|', self.data['down']):
                         if os.path.exists('%s%s'%(self.localpath, fileName)):
                             log.LOG.info('%s成功解压到%s' % (fileName, self.localpath))
                             self.result.append('%s成功解压到%s\n' % (fileName, self.localpath))
                         else:
                             self.result.append('%s文件下载失败\n'%fileName)
                             log.LOG.info('%s文件下载失败\n'%fileName)
                     del(self.stepList[0])
                     continue
             #================下载文件=================
             for flag in re.split('\|', self.data[self.stepList[0]]):
                 #================杀进程=================
                 if self.stepList[0] == 'kill':
                     self.result.append(killProcess(flag))
                 #================杀进程=================
                 #================开进程=================
                 elif self.stepList[0] == 'open':
                     runCMD('start "" /d "%s" "%s"' % (self.localpath, flag))
                     log.LOG.info('运行文件%s'%flag)
                     self.result.append('运行文件%s'%flag)
                 #================开进程=================
                 #================CMD命令=================
                 elif self.stepList[0] == 'cmd':
                     self.result.append('%s\n'%runCMD(flag))
                 #================CMD命令=================
                 #================修改config文件=================
                 elif self.stepList[0] == 'conf':
                     para = re.split('-', self.data[self.stepList[0]])
                     CONF.save(para[0], para[1], para[2])
                     fileRestart = open('restart.bat', 'w')
                     cmds = r'''
                             taskkill /f /im client.exe
                             taskkill /f /im gmclient_watcher.exe
                             start.vbs
                             del /q /f restart.bat
                             exit
                             '''
                     fileRestart.write(cmds)
                     fileRestart.close()
                     self.socket.close()
                     os.system('restart.bat')
                 #================修改config文件=================
                 #================自我更新=================
                 elif self.stepList[0] == 'update':
                     chkPath(r'.\update')
                     os.popen(r'del /q /f .\update\*.*')
                     log.LOG.debug(mylib.rar.decompression('down', '.\\update\\', False)) #解压update文件
                     fileUpdate = open('update.bat', 'w')
                     cmds = r'''
                             taskkill /f /im client.exe
                             taskkill /f /im gmclient_watcher.exe
                             ping -n 2 127.0.0.1
                             copy /y ".\update\*.*" ".\"
                             start.vbs
                             del /q /f update.bat
                             exit
                             '''
                     fileUpdate.write(cmds)
                     fileUpdate.close()
                     self.socket.close()
                     os.system('update.bat')
                 #================自我更新=================
                 #================删除文件=================
                 elif self.stepList[0] == 'delete':
                     delReturn = runCMD('del /q /f "%s%s"' % (self.localpath, flag))
                     if delReturn:
                         self.result.append('%s%s'%(flag, delReturn))
                     else:
                         self.result.append('成功删除%s\n'%flag)
                 #================删除文件=================
             del(self.stepList[0])
     except :
         self.stepList = []
         self.result = [self.returnIP, ' error : ', format_exc(), '\n', self.localpath, '\n'] + self.result
         log.LOG.error(''.join(self.result))
Exemple #2
0
                            chr(PASSWD.__len__()),
                            PASSWD])
        len_msg_data = len(msg_data)
        string = pack("<HLHHL%ss" % len_msg_data, #第一和第二字段宽度对换
                      len_msg_data + 12, #12 = 4+2+2+2+4-2
                      0xAAAC, # magic code
                      len_msg_data + 12,
                      0x9001,
                      0,
                      msg_data)
        self.socket.sendall(string)

if __name__ == '__main__':
    log.run_log()
    log.uuid_log()
    runCMD('title test_manage')
    PORT = CONF.getPort()
    GMPORT = CONF.getGMPort()
    SERVER = CONF.getServer()
    PATH = CONF.getCltPath()
    USER = CONF.getUser()
    PASSWD = CONF.getPasswd()
    DELAYKILL = CONF.getDelayKill()
    IP = _getIP()
    killProcess('heartTest_clt.exe')
    os.system('start /B heartTest_clt.exe')
    while 1:
        try:
            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            sock.connect((SERVER, PORT))
            log.LOG.info('connecting ...')