コード例 #1
0
 def extract_sub_package(self, path):
     for f in os.listdir(path):
         if f.endswith(".zip") and os.path.isfile(os.path.join(path, f)):
             if not os.path.exists(os.path.join(path, f[:-4])):
                 os.mkdir(os.path.join(path, f[:-4]))
             #just extract whatever the file exists
             if not extract(os.path.join(path, f), os.path.join(path, f[:-4])):
                 logger.error("Failed to extract file %s " % os.path.join(path, f))
コード例 #2
0
ファイル: appCleaner.py プロジェクト: y00273676/music_manager
    def get_allow_delete_list(self, lasttime):
        if self._is_today(lasttime):
            return True
        #http://kcloud.v2.service.ktvdaren.com/MusicService.aspx?op=getallmusicfile&depot=0&musictype=5&linkzip=1
        url = "%s/MusicService.aspx?op=getallmusicfile&depot=0&musictype=5&linkzip=1" % self.kcloud_v2
        res = yhttp().get_y(url)
        logger.debug("call url: %s, result: %s" % (url, res))
        resdata = json.loads(res)
        if resdata and int(resdata['code']) == 1:
            if resdata['result']:
                fname = os.path.join(self.downDir,
                                     self.fu.filename(resdata['result']))
                if os.path.exists(fname):
                    #we think it has been loaded into db here
                    #only when cloud side publish new file, it will force to update
                    #also, delete the zip file will cause a force update!
                    return True
                else:
                    ret = self.fu.downfile(resdata['result'], fname, None,
                                           None)
                    if not ret:
                        logger.error("Failed to download cloud_musicinfo file")
                        return False

                #extra
                txtname, _ = os.path.splitext(fname)
                extra_fname = '%s.txt' % os.path.join(self.downDir, txtname)
                if extract(fname, self.downDir):
                    pass
                else:
                    #if failed to extra, delete the zip file to download again
                    if os.path.exists(extra_fname):
                        os.remove(extra_fname)
                logger.error("TODO: load music info into medias table......")

                if load_allowdel_medias(extra_fname):
                    if os.path.exists(extra_fname):
                        os.remove(extra_fname)
                    return True
                else:
                    if os.path.exists(fname):
                        os.remove(fname)
                    if os.path.exists(extra_fname):
                        os.remove(extra_fname)
                    logger.error(
                        "Failed to load allow delete medias from file")
                    return False
        else:
            logger.error("Failed to get allow delete info")
        return False
コード例 #3
0
 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())
コード例 #4
0
    def install_res(self, theme):
        print(theme.theme_path, theme.theme_unpath)
        if theme == None:
            return False
        if not theme.theme_path or not theme.theme_unpath:
            return False

        if extract(theme.theme_path, theme.theme_unpath):
            theme.theme_state = 1
            #theme.theme_unpath = theme.theme_unpath[len('/opt/thunder/www'):]
            #print(theme.theme_unpath)
            ret = self._bll.AddModule_Theme(theme)
            print(str(ret))
        else:
            logger.error("Failed to install themes to server")
コード例 #5
0
ファイル: appNewSong.py プロジェクト: y00273676/music_manager
    def getAllRecords(self, ktvid, dogname, lasttime):
        #http://kcloud.v2.service.ktvdaren.com/MusicService.aspx?op=getallmusicfile&depot=0&musictype=7&linkzip=1
        url = "%s/MusicService.aspx?op=getallmusicfile&depot=0&musictype=7&linkzip=1" % self.kcloud_v2
        res = yhttp().get_y(url)
        logger.debug("call url: %s, result: %s" % (url, res))
        resdata = json.loads(res)
        if resdata and int(resdata['code']) == 1:
            if resdata['result']:
                fname = os.path.join(self.downDir,
                                     self.fu.filename(resdata['result']))
                if not os.path.exists(fname):
                    ret = self.fu.downfile(resdata['result'], fname, None,
                                           None)
                    if not ret:
                        logger.error("Failed to download cloud_musicinfo file")
                        return False
                #extra
                txtname, _ = os.path.splitext(fname)
                extra_fname = '%s.txt' % os.path.join(self.downDir, txtname)
                if extract(fname, self.downDir):
                    pass
                else:
                    #if failed to extra, delete the zip file to download again
                    if os.path.exists(fname):
                        os.remove(fname)
                    if os.path.exists(extra_fname):
                        os.remove(extra_fname)
                logger.error("TODO: load music info into medias table......")

                if loadCloudMusic_fromfile(extra_fname):
                    if os.path.exists(fname):
                        os.remove(fname)
                    if os.path.exists(extra_fname):
                        os.remove(extra_fname)
                    self.lasttime = int(time.time())
                    self.update_lasttime()
                    return True
                else:
                    logger.error(
                        "Failed to load cloud_musicinfo file, fullfile update")
                    return False
        else:
            logger.error("Failed to get cloud_musicinfo from api")

        return False
コード例 #6
0
 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
コード例 #7
0
ファイル: appModule.py プロジェクト: y00273676/music_manager
 def deployModule(self, ver):
     if not ver['fileurl']:
         return False
     if not os.path.exists(ver['fileurl']):
         return False
     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)
             #解压完成后 同步本地文件 到目标文件 本地的文件夹 后面是目标的文件夹
             #添加到模板里面
             res = add_ktvmodule(ver)
             #添加到数据库当前最新使用的模板
             value = module_topath.replace(HTDOCDIR, '')
             if ver['bagtype'] == 1:
                 update_setconfig({"90横版-2.0": value})
             else:
                 update_setconfig({"90竖版-2.0": value})
             return True
         else:
             #incase we got a wrong file in download, just delete it
             if os.path.exists(module_file):
                 os.path.remove(module_file)
             if os.path.exists(module_topath):
                 shutil.rmtree(module_file)
             return False
     except Exception as e:
         logger.error(traceback.format_exc())
     return False
コード例 #8
0
    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())
        '''