def changeAreaOption(self, ip, continentIndex, languageCountry, hwSettings): print('changeAreaOption : ' + languageCountry + ', ' + hwSettings) result = TvModel() isConnected = self.tvController.connect(ip) if isConnected: result = self.tvController.execCommand( LunaCommands.changeAreaOption(self, languageCountry, hwSettings, continentIndex)) if result.resultType == RESULT_SUCCESS: try: result = self.tvController.execCommand( LunaCommands.setContinentIndex(self, continentIndex)) if result.resultType == RESULT_SUCCESS: result = self.tvController.execCommand( LunaCommands.setLanguageCountry( self, languageCountry)) if result.resultType == RESULT_SUCCESS: result = self.tvController.execCommand( LunaCommands.setHwSettings(self, hwSettings)) if result.resultType == RESULT_SUCCESS: result = self.__refreshSettingValueWithGroup( result) except Exception as e: print('*** Caught exception: %s: %s' % (e.__class__, e)) traceback.print_exc() result.message = MESSAGE_ERROR + str(e) self.tvController.disconnect() else: result.message = MESSAGE_TV_ABNORMAL return result
def inquery(self, ip, platform, displayType, hasGroup): print('inquery : ' + platform) result = TvModel() self.countryModel = CountryModel() self.countryModel.platform = platform self.countryModel.displayType = displayType isConnected = self.tvController.connect(ip) if isConnected: result = self.tvController.execCommand( LunaCommands.getAreaOptionValues(self)) if result.resultType == RESULT_SUCCESS: try: self.__loadAreaOption(result.resultValue) if hasGroup: result = self.__refreshSettingValueWithGroup(result) else: result = self.__refreshSettingValue(result) except Exception as e: print('*** Caught exception: %s: %s' % (e.__class__, e)) traceback.print_exc() result.message = MESSAGE_ERROR + str(e) self.tvController.disconnect() else: result.message = MESSAGE_TV_ABNORMAL return result
def downloadCountryFile(self, ip): print('downloadCountryFile : ') result = TvModel() #### TBD : 확인해보기 self.countryModel = CountryModel() isConnected = self.tvController.connect(ip) if isConnected: result = self.tvController.execCommand( LunaCommands.getCountryListPath(self)) if result.resultType == RESULT_SUCCESS: try: res = json.loads(result.resultValue) countryListPath = res['path'].strip() # cmd = 'cp '+str(countryListPath)+' /tmp/' # print("cmd === ",cmd) # self.tvController.execSimpleCommand(cmd) # time.sleep(0.3) fileName = countryListPath.split('/')[-1] if os.path.exists('download/' + fileName): print("already existed!!!") else: result = self.tvController.downloadFile( countryListPath) if result.resultType == RESULT_SUCCESS: try: # cmd = 'mv ../download/'+str(fileName)+' ../resources/' # print("cmd === ",cmd) # self.tvController.execSimpleCommand(cmd) # time.sleep(0.3) # if os.exist('../resources/'+fileName): # self.countryModel.countryFilePath = '../resources/'+fileName if os.path.exists('download/' + fileName): self.countryModel.countryFilePath = 'download/' + fileName else: print("error anything!!!") except Exception as e: print('*** Caught move exception: %s: %s' % (e.__class__, e)) traceback.print_exc() result.message = MESSAGE_ERROR + str(e) else: print( "download fail!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" ) except Exception as e: print('*** Caught download exception: %s: %s' % (e.__class__, e)) traceback.print_exc() result.message = MESSAGE_ERROR + str(e) self.tvController.disconnect() else: result.message = MESSAGE_TV_ABNORMAL return result
def downloadFile(self, ip, fileName): print('downloadFile : ' + fileName) result = TvModel() isConnected = self.tvController.connect(ip) if isConnected: result = self.tvController.downloadFile(fileName) self.tvController.disconnect() else: result.message = MESSAGE_TV_ABNORMAL return result
def searchApp(self, ip, appTitle): print('searchApp : ' + appTitle) result = TvModel() isConnected = self.tvController.connect(ip) if isConnected: result = self.tvController.execCommand( LunaCommands.searchApp(self, appTitle)) self.tvController.disconnect() else: result.message = MESSAGE_TV_ABNORMAL return result
def doScreenCapture(self, ip, fileName): fileName = '/tmp/captured_' + fileName + '.png' print('captureApp : ' + fileName) result = TvModel() isConnected = self.tvController.connect(ip) if isConnected: result = self.tvController.execCommand( LunaCommands.doScreenCapture(self, fileName)) if result.resultType == RESULT_SUCCESS: result = TvModel() result = self.tvController.downloadFile(fileName) self.tvController.disconnect() return result
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 doScreenCapture_OSD(self, ip, fileName): result = TvModel() isConnected = self.tvController.connect(ip) if isConnected: # result = self.tvController.execCommand(LunaCommands.doScreenCapture(self, fileName)) os.system("/tmp/usb/sda/sda1/gmd") time.sleep(0.5) result = TvModel() result = self.tvController.downloadFile("/var/log/*.png") if result.resultValue == False: os.system("cp /var/log/*.png /tmp/usb/sda/sda1/") result.resultValue = True self.tvController.disconnect() return result
def execNormalCommand(self, command, timeout=0): tvModel = TvModel() print(command) try: session = self.tvTransport.open_session() session.exec_command(command + '\n') if timeout == 0: session.recv_exit_status() cur_timeout = 0 byteText = session.recv(8000) message = byteText.decode(encoding='UTF-8') else: cur_time = 0 while True: if session.exit_status_ready(): break time.sleep(1) cur_time += 1 if cur_time > timeout: break while session.recv_ready(): byteText = session.recv(8000) print(byteText.decode(encoding='UTF-8')) # print(session.recv(1024)) message = byteText.decode(encoding='UTF-8') except Exception as e: print('*** Caught exception: %s: %s' % (e.__class__, e)) traceback.print_exc() message = str(e) return message
def changeCountryWithGroup(self, ip, countryName): print('changeCountry : ' + countryName) result = TvModel() isConnected = self.tvController.connect(ip) if isConnected: country = self.countryModel.getCountryByName(countryName) if country != None: result = self.tvController.execCommand( LunaCommands.changeCountry(self, country[KEY_CODE2], country[KEY_CODE3])) self.tvController.disconnect() else: result.message = MESSAGE_TV_ABNORMAL return result
def getAppListFromTV(self, ip, path): # execNormalCommand result = TvModel() isConnected = self.tvController.connect(ip) if isConnected: result = self.tvController.execNormalCommand("cat " + path) self.tvController.disconnect() return result else: return False
def inputKey(self, ip, key, times): result = TvModel() isConnected = self.tvController.connect(ip) if isConnected: for i in range(times): result = self.tvController.execCommand( LunaCommands.inputKey(self, key)) self.tvController.disconnect() return result
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
def checkForegroundAppIsHome(self, ip): result = TvModel() isConnected = self.tvController.connect(ip) if isConnected: result = self.tvController.execCommand( LunaCommands.getForegroundApp(self)) self.tvController.disconnect() foregroundApp = json.loads(result.resultValue) for app in foregroundApp[FOREGROUND_APP_INFO]: if app["appId"] == "com.webos.app.home": return True return False
def changeCountry(self, ip, countryName): print('changeCountryAndGroup : ' + countryName) result = TvModel() isConnected = self.tvController.connect(ip) if not isConnected: for i in range(7): isConnected = self.tvController.connect(ip) if isConnected: break time.sleep(0.5) if isConnected: country = self.countryModel.getCountryByName(countryName) if country != None: self.countryModel.currentLanguageCountry = country[KEY_CODE] languageCountry = self.countryModel.currentLanguageCountry hwSettings = self.countryModel.currentHwSettings continentIndx = str(self.countryModel.currentContinentIndex) result = self.tvController.execCommand( LunaCommands.changeAreaOption(self, languageCountry, hwSettings, continentIndx)) if result.resultType == RESULT_SUCCESS: result = self.tvController.execCommand( LunaCommands.setLanguageCountry(self, languageCountry)) if result.resultType == RESULT_SUCCESS: result = self.tvController.execCommand( LunaCommands.setHwSettings(self, hwSettings)) if result.resultType == RESULT_SUCCESS: result = self.tvController.execCommand( LunaCommands.changeCountry( self, country[KEY_CODE2], country[KEY_CODE3])) if result.resultType == RESULT_SUCCESS: self.countryModel.currentCountry = countryName self.tvController.disconnect() else: result.message = MESSAGE_TV_ABNORMAL return result
def checkHomeShowing(self, ip): print('checkHomeShowing') result = TvModel() isConnected = self.tvController.connect(ip) if isConnected: result = self.tvController.execCommand( LunaCommands.confirmCurrentState(self)) self.tvController.disconnect() if self.__loadCurrentState(result.resultValue) == STATE_HOME: return True, STATE_HOME elif self.__loadCurrentState(result.resultValue) == STATE_ALERT: print("STATE ALERT!!!!!!!!!!!!!!!!!!!!!") return False, STATE_ALERT else: return False, 'None'
def setEULA(self, ip, state=False): try: result = TvModel() isConnected = self.tvController.connect(ip) time.sleep(0.1) if isConnected: print('set EULA to - ',state) result = self.tvController.execCommand(LunaCommands.setEULA(ip, state)) self.tvController.disconnect() else: self.setEULA(ip, state) time.sleep(3) return result except Exception as e: print('*** keyBlock, Caught exception: %s: %s' % (e.__class__, e)) self.setEULA(ip, state) time.sleep(3)
def keyBlock(self, ip, block=True): try: result = TvModel() isConnected = self.tvController.connect(ip) time.sleep(0.1) if isConnected: print('key block!!!') result = self.tvController.execCommand(LunaCommands.keyBlock(block)) self.tvController.disconnect() else: self.keyBlock(ip, block) time.sleep(3) return result except Exception as e: print('*** keyBlock, Caught exception: %s: %s' % (e.__class__, e)) self.keyBlock(ip, block) time.sleep(3)
def reboot(self, ip, excelVer): try: result = TvModel() isConnected = self.tvController.connect(ip) time.sleep(0.1) if isConnected: if excelVer == EXCEL_VERSION[0]: result = self.tvController.execCommand(LunaCommands.reboot(self)) else: result = self.tvController.execCommandForWO35(LunaCommands.reboot(self)) self.tvController.disconnect() else: self.reboot(ip, excelVer) time.sleep(3) return result except Exception as e: print('*** reboot, Caught exception: %s: %s' % (e.__class__, e)) self.reboot(ip, excelVer) time.sleep(3)