def __init__(self): #文件下载的地址 self._localsavepath = os.path.join(AppSet()._trandownpath, 'o2oad') if not os.path.exists(self._localsavepath): os.mkdir(self._localsavepath) #o2o 下载广告的地址 self._localdatapath = os.path.join(AppSet().ApachPath, "data", "o2o") #验证文件夹是否存在 if not os.path.exists(self._localdatapath): os.makedirs(self._localdatapath) #广告的地址 self.ad_data = os.path.join(self._localdatapath, "ad.json") self.ad_del = os.path.join(self._localdatapath, "ad_del.json") self.fu = fileUtils('o2oadinfo') self._down_dict = {} if platform.system().lower() == 'windows': self.server_localpath = "c:\\thunder\\ktvservice\\ktv_o2oadinfo" self.server_localpathlinux = "/opt/thunder/www/ktvservice/ktv_o2oadinfo/" else: #for linux self.server_localpath = "/opt/thunder/ktvservice/ktv_o2oadinfo" self.server_localpathlinux = "/opt/thunder/www/ktvservice/ktv_o2oadinfo/" self.synutils = synchronousutils() self.res_adcaption = None self._ad = None
def getsqlscript(self): baseurl = AppSet().GetCloudKtvIniValue('Alter90URL') endurl = "/CodeService.aspx?" param = "op=getonlyoncejson&dogname=" + yhttp().UrlEncode( str(AppSet()._dogname)) + "&storeId=" + str(self.ktvinfo._ktvid) print(baseurl + endurl + param) res = yhttp().get_y(baseurl + endurl + param) res = json.loads(res) if res['code'] == 1 and res['result']: return res['result']['matches'] return None
def refresh_ktvinfo(self): try: DogName = AppSet()._dogname url = AppSet().GetCloudKtvIniValue( "KtvInfoURL" ) + "/ktvservice.aspx?op=getktvbydog&dogname=" + yhttp().UrlEncode( DogName) print(url) result = yhttp().get_y(url, 10) dic_res = json.loads(result) logger.debug("get ktvinfo: %s, result: %s" % (url, result)) if dic_res and str(dic_res['code']) == '1': if isinstance(dic_res['result'], dict): dic_ktv = dic_res['result'] ktv = dic_ktv['matches'][0] self._info = ktv_info() self._info.ktvid = int(ktv['StoreId']) self._info.ktvname = ktv['StoreName'] self._info.jd = float(ktv['Jd']) self._info.wd = float(ktv['Wd']) self._info.city = ktv['City'] self._info.provincename = ktv['Province'] self._info.country = ktv['Country'] self._info.hostaddress = ktv['Hostaddress'] self._info.stbsystemboot = ktv['stbsystemboot'] #获取ktv省市id try: url = AppSet().GetCloudKtvIniValue( "KtvInfoURL" ) + "/ktvservice.aspx?op=getktvcity&storeid=" + str( self._info.ktvid) result = yhttp().get_y(url, 10) dic_res = json.loads(result) if dic_res and str(dic_res['code']) == '1': if isinstance(dic_res['data'], dict): dic_city = dic_res['data'] self._info.province = str( dic_city['provincenum']) except Exception as ex: self._info = None logging.error('KtvInfo init excepted') logging.error(str(ex)) logging.error(traceback.format_exc()) # self.init_ktvmeta(self._info.ktvid) self.ktvconfig() except Exception as ex: self._info = None logging.error('KtvInfo init excepted') logging.error(str(ex)) logging.error(traceback.format_exc())
def getnewthemes(self, lasttime="1990-01-01 00:00:00"): themeList = [] try: self.ktvinfo = hdl_ktvinfo.get_ktvinfo() if not self.ktvinfo: return False self.ktvid = self.ktvinfo.ktvid baseurl = "{0}/ModuleService.aspx?".format(AppSet().KtvApi) #param="op=getmoduletheme&lasttime=%s&storeid=%s&dogname=%s" % (str(lasttime),str(self.ktvid),urllib.parse.quote(AppSet()._dogname)) param = {} param['op'] = 'getmoduletheme' param['lasttime'] = str(lasttime) param['storeid'] = str(self.ktvid) param['dogname'] = AppSet()._dogname param['time'] = str(int(time.time())) #print (param) paramurl = yhttp().ParamSign(param) url = baseurl + paramurl if self.lk == 1: url += '&lk=1' #url=getSignedUrl(str(baseurl),str(param)) print(url) result = yhttp().get_y(url, 10) dic_res = json.loads(result) #print(dic_res ) if dic_res and str(dic_res['code']) == '1': if isinstance(dic_res['result'], dict): mresult = dic_res['result']['matches'] if len(mresult) > 0: for obj in mresult: theme = Ktvmodule_theme() theme.theme_id = obj["theme_id"] theme.theme_author = obj["theme_author"] theme.theme_authorize = obj["theme_authorize"] theme.theme_bagtype = obj["theme_bagtype"] theme.theme_date = obj["theme_date"] theme.theme_desc = obj["theme_desc"] theme.theme_exptime = obj["theme_exptime"] theme.theme_name = obj["theme_name"] theme.theme_path = obj["theme_path"] theme.theme_state = obj["theme_state"] theme.theme_type = obj["theme_type"] themeList.append(theme) else: return themeList return themeList except Exception as e: logger.error(traceback.format_exc()) return None
def __init__(self): self.dbtype=AppSet().DBtype self.setbll=SettingBll() basename = "lib/modulesyn.dll" cwd = os.path.dirname(os.getcwd()) start=cwd.split("ThunderServer")[0] self.syfilename = os.path.join(start+"ThunderServer", basename)
def __init__(self): self.setbll = SettingBll() self.res_savepath = "resource" self.fu = fileUtils('resource') self.store_path = os.path.join(AppSet()._trandownpath, self.res_savepath) if not os.path.exists(self.store_path): os.makedirs(self.store_path) self.topath = os.path.join(AppSet().ApachPath, self.res_savepath) self.ktvid = hdl_ktvinfo._info.ktvid self.lk = hdl_ktvinfo.lk self.last_update = self.setbll.GetSettingInfo('climax_update') if self.last_update.isdigit(): self.last_update = int(self.last_update) else: self.last_update = 0
def __init__(self): self.setbll = SettingBll() self.ktvid = 0 self.dogname = None #self.iswork=False self.patchDir = os.path.join(AppSet()._trandownpath, 'appUpdate') self.tempDir = os.path.join(AppSet().tempDir, 'Upgrade') self.helper = Thunder().Ins().Karaokdbhelper self.ktvinfo = self.getKtvInfo() self.dogname = self.getDogname() self.transip = self.getTransIP() self.version = self.setbll.getKaraokVer() self.fu = fileUtils('appupgrade') self.lk = KtvInfo().lk print(self.dogname, self.transip, self.version)
def __init__(self): self._bll = KtvModuleVerBll() self._mapi = moduleapi() self.theme_savepath = "themes" self.fu = fileUtils('ktvtheme') self.store_path = os.path.join(AppSet()._trandownpath, self.theme_savepath) if not os.path.exists(self.store_path): os.makedirs(self.store_path) self.topath = os.path.join(AppSet().ApachPath, 'themes') #本地的主题 self.local_themes = {} #全局的主题 self.ver_themes = {} #执行出错的主题 self.err_themes = {}
def geto2oadcaption(self): url = '{0}/ad/caption/{1}'.format(AppSet().O2OAPI, self.ktvinfo.ktvid) #url = "http://api.stage.ktvsky.com/ad/caption/1"; data = yhttp().get_y(url, 10) jsonres = json.loads(data) logger.debug("get o2o ad caption, url:%s result: %s" % (url, jsonres)) if "errcode" in jsonres and jsonres['errcode'] == 200: return jsonres return None
def getnewmodule(self, m_ver, bagtype, appver): logger.debug("getnewmodule") self.ktvinfo = hdl_ktvinfo.get_ktvinfo() if not self.ktvinfo: return False self.ktvid = self.ktvinfo.ktvid #获取模板信息 if self.lk == 1 or self.lk == 2: url = "%s/module_verservice.aspx?op=getmoduleverjson&version=%s&dogname=%s&bagtype=%s&storeId=%s&type=v2&appver=%s&lk=%d" % ( AppSet.songlist, m_ver, yhttp().UrlEncode( AppSet()._dogname), bagtype, self.ktvid, appver, self.lk) else: url = "%s/module_verservice.aspx?op=getmoduleverjson&version=%s&dogname=%s&bagtype=%s&storeId=%s&type=v2&appver=%s" % ( AppSet.songlist, m_ver, yhttp().UrlEncode( AppSet()._dogname), bagtype, self.ktvid, appver) logger.debug(url) result = yhttp().get_y(url, 10) dic_res = json.loads(result) arrver = [] if dic_res and str(dic_res['code']) == '1': if isinstance(dic_res['result'], dict): mresult = dic_res['result']['matches'] var = KtvModule_Ver() if len(mresult) > 0: for item in mresult: var.msgtime = item['MsgTime'] var.version = item['Version'] var.fileurl = item['FileUrl'] var.desc = item['Desc'] var.addtime = str(int(time.time())) var.needun = 0 var.revision = item['ReVision'] var.bagtype = item['BagType'] var.unpath = "" var.name = item['Name'] var.isshow = item['IsShow'] var.id = item['Id'] var.isuse = 1 var.vertype = item['VerType'] var.isdefault = item['IsDefault'] arrver.append(var) return arrver return arrver
def deletefilefromlinux(self,filepath,filetype): return True username ='******' password ='******' execpath=os.path.join(AppSet().ApachPath,str(int(time.time()))+'.txt') #self.servers 需要获取所有视频服务器的ip地址 servers=list() for item in self.setbll.GetServer(): servers.append(item['FileServer_IpAddress']) deletefile(execpath,username,password,servers,filepath.rstrip("/"))
def __init__(self): self._setbll = SettingBll() self.synutil = synchronousutils() self.ktvinfo = hdl_ktvinfo._info self.excename = "Moduleinfo" self.modulename = "modules" self.store_path = os.path.join(AppSet()._trandownpath, self.modulename) if not os.path.exists(self.store_path): os.mkdir(self.store_path) self.topath = os.path.join(AppSet().ApachPath, 'modules') self.fu = fileUtils(self.excename) self.curmodule = {} self.redis = radisutils() self.firsttime = 0 #本地的字典数据 self.local_dict = {} self.module_dict = {} self.error_dict = {} self.appver = self._setbll.getKaraokVer()
def o2oplaystat(self, adid, roomid, roominfo, cnt, playtime, stime, etime, adp, mac): iurl = AppSet().O2OAPI1 url = "{0}/ad/policy".format(iurl) endurl = "?ad_id={0}&ktv_id={1}&room_id={2}&room_info={3}&cnt={4}&time={5}&stt={6}&edt={7}&adp={8}&mac={9}".format( adid, roomid, roominfo, cnt, playtime, stime, etime, adp, mac) data = yhttp().get_y(url + endurl, 10) jsonres = json.loads(data) if "errcode" in jsonres: return jsonres return None
def syncadinfo(self, tv, check=True): if check: url_suc = False _server_localpath = self.server_localpath if tv.type == 0 else os.path.join( AppSet().ApachPath, 'gif') if tv.url: ext = os.path.splitext(tv.url)[1] localpath = os.path.join(self._localsavepath, md5(tv.url) + str(ext)) logger.debug("download url:%s to file %s" % (tv.url, localpath)) #同步并下载文件 if self.fu.downfile(tv.url, localpath, None, None): if int(AppSet().DBtype) == 1: self.synutils.synfiletoserver(localpath, self.server_localpath, 1) else: self.synutils.synfiletoserver( localpath, self.server_localpathlinux, 1) else: #没有下载成功时的操作 pass if tv.url2: ext = os.path.splitext(tv.url2)[1] localpath = os.path.join(self._localsavepath, md5(tv.url2) + str(ext)) logger.debug("download url2:%s to file %s" % (tv.url2, localpath)) #同步并下载文件 if self.fu.downfile(tv.url2, localpath, None, None): if int(AppSet().DBtype) == 1: self.synutils.synfiletoserver(localpath, self.server_localpath, 1) else: self.synutils.synfiletoserver( localpath, self.server_localpathlinux, 1) else: #没有下载成功时的操作 pass return 1
def syncthemetoserver(self, themelist): if themelist: for theme in themelist: #本地存储的地址 local_theme_path = os.path.join( AppSet()._trandownpath, self.theme_savepath, os.path.basename(theme.theme_path)) #下载主题列表 if self.fileutil.downfile(theme.theme_path, local_theme_path, None, None): # tlocalname = os.path.basename(theme.theme_path) name = os.path.splitext(tlocalname)[0] theme.theme_unpath = os.path.join(self.topath, self.theme_savepath, "htheme_" + name) ''' #win if int(AppSet().DBtype)==1: theme.theme_unpath=os.path.join(self.towinpath, self.theme_savepath,"htheme_" + name) #linux else: theme.theme_unpath=os.path.join(self.tolinuxpath,self.theme_savepath,"htheme_" + name) ''' unpath = os.path.join(AppSet()._trandownpath, self.theme_savepath) #开始解压 if extract(local_theme_path, unpath): #开始同步文件 到服务端 suc_status = self.synutil.synfiletoserver( local_theme_path, theme.unpath, 1) #同步成功 if suc_status == 1: #需要将已经同步的主题插入数据库 theme.theme_path = local_theme_path theme.theme_state = 1 self._bll.AddModule_Theme(theme) else: logger.error("Failed to sync themes to server") #同步失败 pass
def ktvconfig(self): try: url = AppSet().GetCloudKtvIniValue( "Alter90URL" ) + "/KtvAppService.aspx?op=getstorejson&dogname=" + yhttp( ).UrlEncode(AppSet()._dogname) + "&storeid=" + str( self._info.ktvid) result = yhttp().get_y(url, 10) dic_res = json.loads(result) if dic_res and str(dic_res['code']) == '1': if isinstance(dic_res['result'], dict): result = dic_res['result']['matches'] logger.debug("getstoreJson: result:%s" % result) for item in result: self._info.mtype = item['ModuleType'] self._info.projectver = item['ProjectVer'] self._info.updatetime = item['StoreUpdateTime'] work_update = item["StoreIsWorkingUpdate"] except Exception as e: logger.error(traceback.format_exc()) pass
def getconnect(self,dbname): tpath=AppSet().thunder_ini cf = IniConfig() cf.readfp(codecs.open(tpath, "r", 'utf-8')) host = cf.get('MainServer', 'DataBaseServerIp') username = cf.get('MainServer', 'UserName') password = cf.get('MainServer', 'Password') try: conn = MySQLdb.connect(host=host, port=3306, user=username, passwd=password, db='karaok', charset='utf8', cursorclass=cursors.DictCursor) return conn except Exception as e: logger.error(traceback.format_exc())
def __init__(self): #能够删除的集合 self.candelect = [] #模板主题删除的集合 self.candel_v2 = [] #标记一下文件夹下应该有的 self.nodel_path = [] self.ApacheDocsPath = AppSet().GetCloudKtvIniValue('ApacheDocsPath') #模板所处的位置 self._modulepath = os.path.join(self.ApacheDocsPath, "modules") self._bll = KtvModuleVerBll()
def __init__(self): self.myname = "wallpapers" self._wpapi = wallpageapi() self._trandownpath = AppSet()._trandownpath self.fu = fileUtils('Wallpapers') self.savepath = os.path.join(AppSet()._trandownpath, "ktvservice") self.paper_dict = {} self.wallpaperpath = os.path.join(self.savepath, 'wallpaper') print(self.wallpaperpath) if not os.path.exists(self.wallpaperpath): os.makedirs(self.wallpaperpath) if platform.system().lower == 'windows': self._filesavepath = "C:\\thunder\\Apache\\htdocs\\looppics\\picfile\\" self._filesavepath_turn = "C:\\thunder\\Apache\\htdocs\\looppics\\picfile_turn\\" else: self._filesavepath = "/opt/thunder/www/looppics/picfile/" self._filesavepath_turn = "/opt/thunder/www/looppics/picfile_turn/" self.synch = synchronousutils() self.localfilelist = list() self.tagfilelist = list() self.radias = radisutils()
def geto2oadinfolist(self): iurl = AppSet().O2OAPI1 url = "{0}/ad/policy/{1}".format(iurl, str(self.ktvinfo.ktvid)) data = yhttp().get_y(url, 10) jsonres = json.loads(data) logger.debug("geto2oadinfolist: url:%s \nresult:%s\n" % (url, jsonres)) ad = o2oad() if jsonres and 'errcode' in jsonres and jsonres['errcode'] == 200: if "ad_pos" in jsonres.keys(): ad_pos = jsonres['ad_pos'] if "start" in ad_pos.keys(): ad.start_action = self.parseo2oaction(ad_pos["start"]) if "mv" in ad_pos.keys(): ad.mv_action = self.parseo2oaction(ad_pos["mv"]) if "end" in ad_pos.keys(): ad.end_action = self.parseo2oaction(ad_pos["end"]) if "no_song" in ad_pos.keys(): ad.nosong_action = self.parseo2oaction(ad_pos["no_song"]) if "horizon_lock_screen" in ad_pos.keys(): ad.horizon_action = self.parseo2oaction( ad_pos["horizon_lock_screen"]) if "verticle_lock_screen" in ad_pos.keys(): ad.verticle_action = self.parseo2oaction( ad_pos["verticle_lock_screen"]) if "redpack" in ad_pos.keys(): ad.redpack_action = self.parseo2oaction(ad_pos["redpack"]) if "7000plus" in ad_pos.keys(): ad.redpack_action = self.parseo2oaction(ad_pos["7000plus"]) if "ad_info" in jsonres.keys(): ad_info = jsonres["ad_info"] if ad_info: for item in ad_info: mo2oad = o2oad_tvinfo() mo2oad.id = item['ad'] mo2oad.url = item['url'] mo2oad.url2 = item['url2'] mo2oad.url2 = item['url2'] if item["type"].lower() == 'video': mo2oad.type = 0 elif item["type"].lower() == 'gif': mo2oad.type = 1 else: mo2oad.type = 2 mo2oad.typestr = item["type"] mo2oad.time = item['time'] mo2oad.monitor_url = [] mo2oad.md5 = item['md5'] for mstr in item["monitor_url"]: mo2oad.monitor_url.append(mstr) ad.ad_dict.append(mo2oad) return ad
def synimportmodule(self, ver): if not ver.fileurl: return try: #文件存在的地方 filename = os.path.basename(ver.fileurl) logger.info("(%s) (%s)" % (ver, filename)) #解压的文件夹 module_file = os.path.join(self.store_path, filename) module_topath = os.path.join(self.topath, "90plus_" + os.path.splitext(filename)[0]) logger.info("(%s) (%s) (%s)" % (filename, module_file, module_topath)) if extract(module_file, module_topath): #ARM 服务器开始,DBAss没有加入解压库,所以下载模板时顺便解压 self.extract_sub_package(module_topath) #解压完成后 同步本地文件 到目标文件 本地的文件夹 后面是目标的文件夹 #suc_status = self.synutil.synfiletoserver(module_topath, ver.unpath, 1) suc_status = 1 if suc_status==1: #添加到模板里面 res = KtvModuleVerBll().AddModule(ver) #添加到数据库当前最新使用的模板 value = module_topath.replace(AppSet().ApachPath, '') if ver.bagtype == 1: self._setbll.SetSettingInfo("90横版-2.0", value) else: self._setbll.SetSettingInfo("90竖版-2.0", value) #同步成功 self.local_dict[ver.id] = ver ''' #需要更改redis 里面的数据 redisdata = self.redis.getshortinfobyname(self.excename) if redisdata: redislist = json.loads(redisdata) redislistcopy = [] for item in redislist: if item['id'] == ver.id: item['isuse'] = 1 redislistcopy.append(item) #更改数据添加到redis self.redis.savedatabyshort(self.excename,json.dumps(redislistcopy)) ''' else: logger.error("Failed to sync module files to other server") #同步失败 pass except Exception as e: logger.error(traceback.format_exc())
def Karaokdbhelper(self): if Thunder._Karaokdbhelper: return Thunder._Karaokdbhelper else: try: istry = False print(AppSet().Karaok.mysqlconnstring) if MysqlDbHelper.Ins(AppSet().Karaok.mysqlconnstring).Connected(): print('连上了') Thunder._Karaokdbhelper = MysqlDbHelper.Ins(AppSet().Karaok.mysqlconnstring) #AppSet().SetCloudKtvIniValue("DBtype", 2) return Thunder._Karaokdbhelper else: print('没连上') sys.exit(0) if not istry: istry = True except Exception as ex: logging.error('Karaokdbhelper excepted: %s' % str(ex)) logging.error(traceback.format_exc()) sys.exit(0) return None
def GetMediaNewSongTime(self): try: dbtype = AppSet().DBtype if str(dbtype) == "1": sql = "select top 1 Media_InTime from MediaNewSong order by Media_Sort" else: sql = "select Media_InTime from MediaNewSong order by Media_Sort limit 1" # sql="select {0} Media_InTime from MediaNewSong order by Media_Sort {1}" data = self.helper.ExecuteSql(sql)['Media_InTime'] if not data: return '1990-01-01' return data except Exception as e: logger.error(traceback.format_exc()) return None
def checkthemestatus(self, id): result = 0 try: param = {} param['id'] = id param['time'] = str(int(time.time())) param['op'] = "checkinvalidtheme" paramurl = yhttp().ParamSign(param) baseurl = "{0}/ModuleService.aspx?".format(AppSet().KtvApi) url = baseurl + paramurl print(url) result = yhttp().get_y(url, 10) dic_res = json.loads(result) if dic_res and str(dic_res['code']) == '1': result = dic_res['result'] return result except Exception as e: print(e) return result
def erpdbhelper(self): if Thunder._erpdbhelper: return Thunder._erpdbhelper else: try: appset = AppSet() if DbHelper.Ins(appset.Erp.connstring).Connected(): Thunder._erpdbhelper = DbHelper.Ins(appset.Erp.connstring) return Thunder._erpdbhelper if MysqlDbHelper.Ins(appset.Erp.mysqlconnstring).Connected(): Thunder._erpdbhelper = MysqlDbHelper.Ins(appset.Erp.mysqlconnstring) return Thunder._erpdbhelper except Exception as ex: logging.error('erpdbhelper excepted') logging.error(str(ex)) logging.error(traceback.format_exc()) logging.error('Get erpdbhelper Failed') return None
def GetOverdueKtv_tvadList(self): try: param = {} param['op'] = 'getoverduektv_tvadlist' param['dogname'] = self.ktvinfo.ktvname param['time'] = str(int(time.time())) endurl = yhttp().ParamSign(param) url = "{0}/Ktv_tvadinfoService.aspx?".format(AppSet().songlist) url += endurl data = yhttp().get_y(url, 10) jsonres = json.loads(data) logger.debug("GetOverdueKtv_tvadList: url:%s \nresult:%s\n" % (url, jsonres)) if jsonres: if jsonres['code'] < 0: return [] if jsonres['result'] and len(jsonres['result']) > 0: matches = jsonres['result']['matches'] return matches except Exception as e: logger.error(traceback.format_exc()) pass return None
def GetKtv_tvadininterval(self): try: tvadininterval = 0 param = {} param['op'] = 'getktv_tvadconf' param['ktvid'] = str(self.ktvinfo.ktvid) param['time'] = str(int(time.time())) endurl = yhttp().ParamSign(param) url = "{0}/Ktv_tvadinfoService.aspx?".format(AppSet().songlist) url += endurl data = yhttp().get_y(url, 10) jsonres = json.loads(data) logger.debug("GetKtv_tvadininterval: url:%s \nresult:%s\n" % (url, jsonres)) if jsonres: if jsonres['code'] < 0: return tvadininterval if jsonres['result'] and len(jsonres['result']) > 0: matches = jsonres['result']['matches'] return matches[0]['tvadininterval'] except Exception as e: logger.error(traceback.format_exc()) return None
def apacheCacheSize(self): app = AppSet() cf = app.cloudktvini cf.readfp(codecs.open(app.cloudktvsong_ini, "r", 'utf_8_sig')) size = cf.get('CloudKtvSong', "ApacheCacheSize") return size
def UpdateApp(self): if os.path.exists(self.patchDir) == False: os.makedirs(self.patchDir) if self.dogname == None: time.sleep(113) #这里需要打印加密狗,然后调用接口需要解密狗名称进行验证 logger.debug('DogName:' + self.dogname) if self.lk == 1 or self.lk == 2: self.url = '%s/ProgramPatchService.aspx?op=getcloudappupdatelist' \ '&apptype=2&version=%s&minversion=0.0.0.0&os=linux&time=%d' \ '&dogname=%s&lk=%d' % (AppSet().KtvApi, self.version, int(time.time()), quote(self.dogname), self.lk) else: self.url = '%s/ProgramPatchService.aspx?op=getcloudappupdatelist' \ '&apptype=2&version=%s&minversion=0.0.0.0&os=linux&time=%d' \ '&dogname=%s' % (AppSet().KtvApi, self.version, int(time.time()), quote(self.dogname)) maxver = None try: req = urlopen(self.url) retstr = req.read() data = unquote(retstr) jsonobj = json.loads(data) logger.debug("read ProgramPatchService info: url:%s, result:%s" % (self.url, jsonobj)) self.ver_val = VersionConvert(self.version) print(self.version, self.ver_val) if jsonobj['result'] and jsonobj['result']['matches']: for upver in jsonobj['result']['matches']: if (upver['app_maxver'] > 0 and self.ver_val > upver['app_maxver']) \ or (self.ver_val < upver['app_minver'] and self.ver_val != upver['app_curver']): logger.debug("local:%d, min:%d, max:%d, upto:%d" \ % (self.ver_val, upver['app_minver'], upver['app_maxver'], upver['app_curver'])) continue if not maxver: maxver = upver else: if maxver['app_curver'] < upver['app_curver']: maxver = upver logger.debug("would upgrade to %s" % maxver['curver']) if not maxver: logger.debug("no app update version found") return True fname = self.fu.filename(maxver['app_url']) tempfileName = "tmp_%s" % fname.split('.')[0] #下载并解压缩erp fileName = os.path.join(self.patchDir, fname) #检测文件是否存在,然后下载 if os.path.exists(fileName) == False: ret = self.fu.downfile(maxver['app_url'], fileName, None, None) if not ret: logger.error( "Failed to download file %s->%s, will remove local file" % (maxver['app_url'], fileName)) os.remove(fileName) #检测文件夹是否存在,如果存在,删除重新解压缩 if os.path.exists(self.tempDir) == True: subprocess.getstatusoutput("rm -rf %s" % self.tempDir) if os.path.exists(self.tempDir) == False: os.makedirs(self.tempDir) #很久之前解压缩后前要通过md5sum.txt将所有文件进行MD5值验证,现在没有这个文件就不需要验证了 logger.debug( "extrating file %s to folder %s" % (fileName, os.path.join(self.patchDir, tempfileName))) res = extract(fileName, self.tempDir) if res: pkpath = self.searchTUP() if not pkpath: return False #TODO launch the upgrade service client side, from Shaolin cmd = "LD_PRELOAD=/opt/lib/preloadable_libiconv.so LD_LIBRARY_PATH=/opt/lib /opt/thunder/bin/update/ThunderUpdateTools "\ "-f '%s' -v '%s'" % (pkpath, maxver['curver']) logger.debug("Upgrade command:\n%s\n" % cmd) out = '' ret, out = subprocess.getstatusoutput(cmd) if ret == 0: logger.debug("Upgrade success") else: logger.error("Upgrade Failed") logger.debug("upgrade output:\n%s\n" % out.decode('utf-8')) except BadZipfile as ex: if os.path.exists(fileName): os.remove(fileName) except Exception as ex: print('upgrade failed %s(%s)' % (str(ex), self.dogname)) logger.error(traceback.format_exc()) '''
def getDogname(self): return AppSet().get_DogName()