Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
    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
Ejemplo n.º 4
0
    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
Ejemplo n.º 5
0
    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
Ejemplo n.º 6
0
    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
Ejemplo n.º 7
0
    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
Ejemplo n.º 8
0
    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
Ejemplo n.º 9
0
    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