def execCommandForWO35(self, command): tvModel = TvModel() try: session = self.tvTransport.open_session() session.exec_command(command + '\n') if 'reboot' in command: return tvModel session.recv_exit_status() while session.recv_ready(): byteText = session.recv(8000) message = byteText.decode(encoding='UTF-8') if '\"returnValue\":true' in message.replace(" ", ""): tvModel.resultType = RESULT_SUCCESS tvModel.resultValue = message else: tvModel.resultType = RESULT_FAIL tvModel.message = MESSAGE_ERROR + command + '\n' + message except Exception as e: print('*** execCommandForWO35, Caught exception: %s: %s' % (e.__class__, e)) traceback.print_exc() tvModel.message = MESSAGE_ERROR + str(e) tvModel.resultType = RESULT_FAIL return tvModel
def downloadFile(self, fileName): print('start to downloadFile : ' + fileName) tvModel = TvModel() try: with SCPClient(self.tvTransport) as scp: # print(str(os.path.isdir('download'))) if os.path.isdir('download') is False: os.mkdir('download') os.chdir('download') #now = datetime.datetime.now().strftime('%Y%m%d-%HH%MM%SS') # print(now) # os.mkdir(now) # os.chdir(now) scp.get(fileName, recursive=True) success = False for base, dirs, files in os.walk('./'): for downloadedFiled in files: success = True break for downloadedDir in dirs: success = True break # os.chdir('../../') scp.close() self.disconnect() if success: tvModel.resultType = RESULT_SUCCESS else: tvModel.message = MESSAGE_SCP_ERROR except Exception as e: print('*** downloadFile, Caught exception: %s: %s' % (e.__class__, e)) traceback.print_exc() tvModel.message = MESSAGE_ERROR + str(e) finally: os.chdir('../') print('finish to download file') return tvModel