def generateApp(app, dev, platform=""): conf = ConfigParser.ConfigParser() conf.read("generateapp.conf") pidfilename = '/tmp/generateApp.pid' if os.path.isfile(pidfilename): print("generating App!!! please wait") return pid = os.getpid() pidfile = open(pidfilename, 'w') pidfile.write(str(pid)) pidfile.close() def signal_handler(signal, frame): print('capture signal SIGINT') os.remove(pidfilename) exit(0) pass signal.signal(signal.SIGINT, signal_handler) devs = dev.split("|") for dv in devs: generateappcore.generateApp(conf, app, dv, platform) print("finish generateApp") os.remove(pidfilename) commandsutils.execCmd("rm -rf /Volumes/RamDisk/generateApp/")
def setArealist(serverlist,serverdata): tempdir="/tmp/" if os.path.exists("/Volumes/RamDisk/temp/"): tempdir="/Volumes/RamDisk/temp/" if serverlist!="": serverlist = "arealist_"+serverlist.split("/")[-1]+".xml" f = file(tempdir+serverlist,"w") f.write(serverdata) f.close() commandsutils.execCmd("scp -i ~/.ssh/id_server_release "+tempdir+serverlist+" 168:/data0/wg_www/ss.ec.feidou.com/serverlist/"+serverlist)
def sethtmlFile(serverlist,serverdata): tempdir="/tmp/" if os.path.exists("/Volumes/RamDisk/temp/"): tempdir="/Volumes/RamDisk/temp/" if serverlist!="": serverlist = serverlist.split("/")[-1] f = file(tempdir+serverlist,"w") f.write(serverdata) f.close() commandsutils.execCmd("scp -i ~/.ssh/id_server_release "+tempdir+serverlist+" 222:/data0/www/serverlist/notic/"+serverlist)
def excel2tips(excelpath,clientpath): commandsutils.execCmd("cd "+excelpath+"resource/i18n/ && svn up ") commandsutils.execCmd("cd "+clientpath+"script/base/ && svn up ") if os.path.exists(excelpath+"resource/i18n/LangTips.xls"): book = xlrd.open_workbook(excelpath+"resource/i18n/LangTips.xls") sheet=book.sheets()[0] for x in xrange(0,sheet.row_len(0)): value = sheet.cell(0, x).value localtype=value.lower().split("_")[-1] localeLang=[] p = re.compile(r'(?<!\\)"') for i in xrange(1,sheet.nrows): value = sheet.cell(i,x).value.strip() if value!="": value=re.sub(p,'\\"',value) localeLang.append(value.encode('utf8')) if len(localeLang)>0: localeLang='return {"'+'","'.join(localeLang)+'"}' if localtype=="cn": f = open(clientpath+"script/base/UpDateTipS.lua",'wb') else: f = open(clientpath+"script/base/UpDateTipS_"+localtype+".lua",'wb') f.write(localeLang) f.close() commandsutils.execCmd("cd "+clientpath+"script/base/ && svn st | grep '^\?' | tr '^\?' ' ' | sed 's/[ ]*//' | sed 's/[ ]/\\ /g' | xargs svn add") commandsutils.execCmd("cd "+clientpath+"script/base/ && svn commit -m'auto commit datatips' ")
def doResults(upfile):# 显示结果函数 MAXBYTES = 1024000 #定义上传文件大小函数,单位为b filedata = '' #初始化文件内容 stop = False #初始化判断 filename = upfile.filename or '' #获取文件名 fp = upfile.file tmpname = time.strftime('%Y_%m_%d_%H_%M_%S')+filename #设置需要保存文件名称,按日期保存 tempdir="/tmp/" if os.path.exists("/Volumes/RamDisk/temp/"): tempdir="/Volumes/RamDisk/temp/" temp=open(tempdir+tmpname,'w+') temp.write(fp.read()) temp.close() fp.close() #关闭文件 commandsutils.execCmd("scp -i ~/.ssh/id_server_release "+tempdir+tmpname+" 168:/data0/wg_www/ss.ec.feidou.com/serverlist/res/html/"+tmpname) return "/serverlist/res/html/"+tmpname
def setSvnTag(tag): global SVN_TAG global SVN_VERSION global SVN_GAMECLIENT global SVN_SHARED global projectPath global sharedPath SVN_TAG = tag if tag == "trunk": SVN_VERSION = "0.0.0" else: SVN_VERSION = tag.replace("tags/", "") SVN_GAMECLIENT = "%s/work/ungame/client/%s" % (HomePath, SVN_TAG) SVN_SHARED = "%s/work/ungame/shared/%s" % (HomePath, SVN_TAG) #自动更新 创建新的tag后 自动更新 if not os.path.isdir(SVN_GAMECLIENT): commandsutils.execCmd("mkdir -p %s/work/ungame/client/%s" % (HomePath, tag)) commandsutils.execCmd( "svn co %s/client/%s/gameClient %s/work/ungame/client/%s/gameClient" % (SVN_ROOT_PATH, tag, HomePath, tag)) if not os.path.isdir(SVN_SHARED): commandsutils.execCmd("mkdir -p %s/work/ungame/shared/%s/策划文档" % (HomePath, tag)) for fpath in SHARED_FILE_LIST: commandsutils.execCmd( "svn co %s/shared/%s/%s %s/work/ungame/shared/%s/%s" % (SVN_ROOT_PATH, tag, fpath, HomePath, tag, fpath)) # Resource 自动复制出多分 需要多线程发布 if "Resource" == fpath: for target in BuildTarget: if target != BuildTarget[3]: commandsutils.execCmd( "cp -r %s/work/ungame/shared/%s/Resource %s/work/ungame/shared/%s/Resource%s" % (HomePath, tag, HomePath, tag, target)) projectPath = "%s/gameClient" % (SVN_GAMECLIENT) sharedPath = "%s/Resource" % (SVN_SHARED) print("SVN_TAG: %s" % (SVN_TAG)) print("SVN_VERSION: %s" % (SVN_VERSION)) print("SVN_GAMECLIENT: %s" % (SVN_GAMECLIENT)) print("SVN_SHARED: %s" % (SVN_SHARED)) print("projectPath: %s" % (projectPath)) print("sharedPath: %s" % (sharedPath))
def updateAreaList(appName,localetype): curr = os.getcwd() version,tempdir=releaseToWeb(AppConfig.getSvnTag(appName),True,localetype) os.chdir(curr) AppVersion = AppConfig.getAppVersion(appName) SvnVersion = AppConfig.getSvnVersion(appName) resVersion = AppConfig.getResversion(SvnVersion) oldVersion = AppConfig.downloadArealist(appName,tempdir) newResVersion=SvnVersion+"."+resVersion if newResVersion!= oldVersion: BundleID = AppConfig.getserverlistBundleID(appName) # 更新版本 commandsutils.execCmd('sed "s/{resversion}/'+newResVersion+'/g" '+tempdir+'/arealist.xml | sed "s/{BundleID}/'+BundleID+'/g" | sed "s/{serverlist}/'+AppVersion+'/g" | sed "s/{appversion}/'+AppVersion+'/g" > '+tempdir+'/arealist'+AppVersion+'.xml') commandsutils.execCmd('scp -i ~/.ssh/id_server_release '+tempdir+'/arealist'+AppVersion+'.xml [email protected]:/data/wg_www/ss.ec.feidou.com/serverlist/arealist_'+BundleID+'_'+AppVersion+'.xml') commandsutils.execCmd("rm -rf "+tempdir) print "更新成功" return resVersion else: print "无需更新" commandsutils.execCmd("rm -rf "+tempdir) return 0
def releaseToWeb(SVN_TAG,isquick,localetype): curr = os.getcwd() cacheRes="/tmp/" userHome = os.path.expanduser('~') if os.path.exists("/Volumes/RamDisk/"): cacheRes="/Volumes/RamDisk/" cacheRes=cacheRes+time.strftime('%Y_%m_%d_%H_%M_%S') svn_version = AppConfig.getSvn2Version(SVN_TAG) localmd5 = updateCachedRes(SVN_TAG,cacheRes) resVersion = AppConfig.getResversion(svn_version) newResVersion = svn_version+"."+str(int(resVersion)+1) oldResVersion = svn_version+"."+resVersion remotemd5 = AppConfig.md5ToTable(AppConfig.getRemoteMD5(oldResVersion)) resLen=(len(localmd5)==len(remotemd5)) if isquick: keys = localmd5.keys() for key in keys: if remotemd5.has_key(key) and remotemd5[key] == localmd5[key]: os.remove(cacheRes+"/cached_res/"+key) del localmd5[key] delFolder(cacheRes+"/cached_res") os.chdir(curr) if len(localmd5)==0 and resLen: print "无更新" return 0,cacheRes if os.path.exists(cacheRes+"/cached_res/script"): if not compileLuasScripts(cacheRes+"/cached_res/script",cacheRes+"/cached_res/script64","64") or not compileLuasScripts(cacheRes+"/cached_res/script",cacheRes+"/cached_res/script","32"): print "编译脚本错误!" return 0,cacheRes # BundleID = AppConfig.getserverlistBundleID(appName) commandsutils.execCmd("rm -rf "+cacheRes+"/cached_res/*.txt") commandsutils.execCmd("rm -rf "+cacheRes+"/cached_res/config/config.txt") for x in xrange(0,len(AppConfig.LOCALETYPES)): commandsutils.execCmd("rm -rf "+cacheRes+"/cached_res/config/"+AppConfig.LOCALETYPES[x].replace("_","-")+"/config.txt") delFolder(cacheRes+"/cached_res") # 压缩文本文件 for root, subdirs, files in os.walk(cacheRes+"/cached_res"): for file in files: if file.find("md5")<0 and file!="md5.txt" and file!="md5all.txt" and file!="md5.zip" and file!=".DS_Store" and os.path.splitext(file)[1] != '.eg': filefullpath = os.path.join(root, file) filerelpath = os.path.relpath(filefullpath, cacheRes+"/cached_res") if filerelpath[0]!=".": ext = os.path.splitext(file)[1] if ext==".txt" or ext==".lua" or ".plist"==ext: # print filefullpath f = open(filefullpath,'r+') line=f.read() result = zlib.compress(line) f.seek(0) f.truncate() f.write(result) f.close() commandsutils.execCmd("cd "+cacheRes+"/cached_res && zip -9 -r --exclude=*.svn* --exclude=*.DS_Store* "+newResVersion+".zip .") commandsutils.execCmd("scp "+cacheRes+"/cached_res/"+newResVersion+".zip root@"+AppConfig.CDN_IP+":/data0/cdn/sgqy/"+newResVersion+".zip") commandsutils.execCmd('ssh root@'+AppConfig.CDN_IP+' "[ -d /data0/cdn/sgqy/'+newResVersion+'/ ] && rm -rf /data0/cdn/sgqy/'+newResVersion+'"') commandsutils.execCmd('ssh root@'+AppConfig.CDN_IP+' "[ -d /data0/cdn/sgqy/'+oldResVersion+'/ ] && cp -rf /data0/cdn/sgqy/'+oldResVersion+'/ /data0/cdn/sgqy/'+newResVersion+'/"') commandsutils.execCmd('ssh root@'+AppConfig.CDN_IP+' "unzip -o /data0/cdn/sgqy/'+newResVersion+'.zip -d /data0/cdn/sgqy/'+newResVersion+'/"') commandsutils.execCmd('ssh root@'+AppConfig.CDN_IP+' "rm -rf /data0/cdn/sgqy/'+newResVersion+'.zip"') commandsutils.execCmd('ssh root@'+AppConfig.CDN_IP+' "echo \''+str(int(resVersion)+1)+'\'>/data0/cdn/sgqy/'+svn_version+'.txt"') # 更新版本 # commandsutils.execCmd('sed "s/{resversion}/'+newResVersion+'/g" '+cacheRes+'/arealist.xml | sed "s/{BundleID}/'+BundleID+'/g" | sed "s/{serverlist}/'+AppVersion+'/g" | sed "s/{appversion}/'+AppVersion+'/g" > '+cacheRes+'/arealist'+AppVersion+'.xml') # commandsutils.execCmd('scp -i ~/.ssh/id_server_release '+cacheRes+'/arealist'+AppVersion+'.xml [email protected]:/data/wg_www/ss.ec.feidou.com/serverlist/arealist_'+BundleID+'_'+AppVersion+'.xml') # commandsutils.execCmd('ssh -i ~/.ssh/id_server_release root@"+AppConfig.CDN_IP+" "[ -d /data0/cdn/sgqy/'+BundleID+'/'+oldResVersion+'/ ] && rm -rf /data0/cdn/sgqy/'+BundleID+'/'+oldResVersion+'/"') return newResVersion ,cacheRes
def compileLuasScripts(src,output,bitmode): result = commandsutils.execCmd("$QUICK_V3_ROOT/quick/bin/compile_scripts.sh -m files -i "+src+" -o "+output+" -b "+bitmode) if result.find("ERR:")>-1: return False return True
def updateCachedRes(svntag,target): if not os.path.exists(target): print target os.makedirs(target) svnurl="svn://svn2.intra.kaixin001.com/dev2/webgame/qunying/client/trunk/gameClient/cached_res" if svntag!="trunk": svnurl="svn://svn2.intra.kaixin001.com/dev2/webgame/qunying/client/"+svntag+"/gameClient/cached_res" cacheRes=svntag if os.path.isdir("cgi-bin/"): cacheRes="cgi-bin/"+svntag if not os.path.exists(cacheRes+"/cached_res"): os.mkdir(cacheRes+"/cached_res") commandsutils.execCmd("svn co "+svnurl +" "+cacheRes+"/cached_res") else: commandsutils.execCmd("cd "+cacheRes+"/cached_res && svn revert --depth infinity . && svn up ") commandsutils.execCmd('mkdir '+target+"/cached_res") commandsutils.execCmd('cp -rf '+cacheRes+'/cached_res/config '+target+"/cached_res/") commandsutils.execCmd('cp -rf '+cacheRes+'/cached_res/image '+target+"/cached_res/") commandsutils.execCmd('cp -rf '+cacheRes+'/cached_res/script '+target+"/cached_res/") commandsutils.execCmd('find '+target+'/cached_res/ -name "*.mine" -exec rm -f {} \;') commandsutils.execCmd('find '+target+'/cached_res/ -name "*.lua.r*" -exec rm -f {} \;') commandsutils.execCmd('find '+target+'/cached_res/ -name "*.eg" -exec rm -f {} \;') commandsutils.execCmd('find '+target+'/cached_res/ -name ".DS_Store" -exec rm -f {} \;') commandsutils.execCmd('find '+target+'/cached_res/ -name "*.bak" -exec rm -f {} \;') commandsutils.execCmd("rm -rf "+target+"/cached_res/image/hero/halfbody/*.png") commandsutils.execCmd("rm -rf "+target+"/cached_res/image/zh-CN") commandsutils.execCmd("rm -rf "+target+"/cached_res/image/fonts") commandsutils.execCmd("rm -rf "+target+"/cached_res/image/*.ttf") commandsutils.execCmd("rm -rf "+target+"/cached_res/*.zip") commandsutils.execCmd("rm -rf "+target+"/cached_res/*.txt") commandsutils.execCmd("rm -rf "+target+"/cached_res/image/db/dfsdfsdfsdf.jpg") commandsutils.execCmd("rm -rf "+target+"/cached_res/image/MainScene.csb") uiDirs=["/cached_res/image/ui"] for x in AppConfig.LOCALETYPES: uiDirs.append("/cached_res/image/%s/ui/" %(x.replace("_","-"))) for subDir in uiDirs: for root, subdirs, files in os.walk(target+subDir): for dirname in subdirs: filefullpath = os.path.join(root, dirname) if os.path.exists(filefullpath+".plist"): commandsutils.execCmd("rm -rf %s" %(filefullpath)) if os.path.exists(target+"/cached_res/image/ui/locatype.pvr.ccz"): commandsutils.execCmd("rm -rf "+target+"/cached_res/script/mvc/instance/model/cfg2profile/LangAuto*.lua") calMD5ForFolder(target+"/cached_res",target+"/cached_res/md5") commandsutils.execCmd('cd '+cacheRes+'/cached_res/ && svn info | grep "Rev" > '+target+'/cached_res/revicion.zip') f = open(target+"/cached_res/md5all.txt",'r') line=f.read() f.close() return AppConfig.md5ToTable(line)
appName ="app2" # ios 提审包 1.1.1 # appName ="app7" # 三分天下 # appName ="sgqyz_sftx" # 应用宝 # appName="app2" # ios 提审包 测试 # appName = "app130" try: createlockFile() if quick: newResVersion = updateAreaList(appName,localetype) else: newResVersion,tempdir=releaseToWeb(appName,True,localetype) commandsutils.execCmd("rm -rf "+tempdir) except Exception as e: print e print "操作失败" finally: removeLockFile() print "Content-Type: text/html" print if newResVersion == 0: print "资源为最新,无需更新" elif newResVersion: print "更新成功 "+ newResVersion else: print "更新失败 可能无更新文件"
def excel2client(excelpath,clientpath): global connconfig commandsutils.execCmd("cd "+clientpath+" && svn revert --depth infinity .") commandsutils.execCmd("cd "+excelpath+" && svn revert --depth infinity .") status ,output = commands.getstatusoutput("cd "+clientpath+" && svn update ") print output status ,output = commands.getstatusoutput("cd "+excelpath+" && svn update ") print output excel2tips(excelpath,clientpath) excelpath=excelpath+"表生成工具/runnable_jar/" a = os.popen("cd "+excelpath+" && sh genmiddle.sh&").read() commandsutils.execCmd("rm -rf "+excelpath+"export/db") commandsutils.execCmd("rm -rf "+excelpath+"export/txt/zip") commandsutils.execCmd("mkdir "+excelpath+"export/db") sqlite3datafile = excelpath+'export/db/config.txt' if os.path.isfile(sqlite3datafile): os.remove(sqlite3datafile) connconfig["zh-CN"] = sqlite3.connect(sqlite3datafile) for root, subdirs, files in os.walk(excelpath+"export/txt/"): if len(subdirs)>0: for dirs in subdirs: if dirs.find("_")>1: if not os.path.exists(excelpath+'export/db/'+dirs.replace("_","-")): os.mkdir(excelpath+'export/db/'+dirs.replace("_","-")) sqlite3datafile = excelpath+'export/db/'+dirs.replace("_","-")+'/config.txt' if os.path.isfile(sqlite3datafile): os.remove(sqlite3datafile) connconfig[dirs] = sqlite3.connect(sqlite3datafile) if root == excelpath+"export/txt/": for file in files: file = os.path.splitext(file) if file[1] == '.txt': saveTother={"zh-CN":True} for conn in connconfig: if conn !="zh-CN": if os.path.exists(root+conn+"/"+file[0]+file[1]): saveTother[conn]=True for conn in connconfig: if conn !="zh-CN": if os.path.exists(root+conn+"/"+file[0]+file[1]): txttosql(excelpath ,file[0],conn,saveTother) txttosql(excelpath,file[0],"zh-CN",saveTother) for conn in connconfig: connconfig[conn].close() a = os.popen("svn update "+clientpath+"config"+"&").read() a = os.popen("svn update "+clientpath+"image"+"&").read() commandsutils.execCmd("rm -rf "+clientpath+"config/*") commandsutils.execCmd("cp -rf "+excelpath+"export/db/*.txt "+clientpath+"config/") zipFile(excelpath+"export/lua/LangAuto.lua",clientpath+"image") for localtype in AppConfig.LOCALETYPES: localtype_ = localtype.replace("_","-") if os.path.exists(excelpath+"export/db/"+localtype_): if not os.path.exists(clientpath+"config/"+localtype_): os.makedirs(clientpath+"config/"+localtype_) commandsutils.execCmd("cp -rf "+excelpath+"export/db/"+localtype_+"/*.txt "+clientpath+"config/"+localtype_+"/") localtypes = localtype.lower().split("_") for langtype in localtypes: if os.path.exists(excelpath+"export/lua/LangAuto_"+langtype+".lua"): if not os.path.exists(clientpath+"image/"+localtype_): os.makedirs(clientpath+"image/"+localtype_+"/ui") commandsutils.execCmd("svn add "+clientpath+"image/"+localtype_) zipFile(excelpath+"export/lua/LangAuto_"+langtype+".lua",clientpath+"image/"+localtype_) break copytree(excelpath+"export/lua/",clientpath+"script/mvc/instance/model/cfg2profile/") commandsutils.svnCommit(clientpath+"config") commandsutils.svnCommit(excelpath+"luaxls") commandsutils.svnCommit(clientpath+"script/mvc/instance/model/cfg2profile/")
def createlockFile(): f = file("lockCreatePlist", "w") f.close() def removeLockFile(): if os.path.isfile("lockCreatePlist"): os.remove("lockCreatePlist") form = cgi.FieldStorage() userHome = os.path.expanduser('~') cversion = "trunk" # 获取数据 if form.getvalue('cversion'): cversion = form.getvalue('cversion') if os.path.isfile("lockCreatePlist"): print "Content-Type: text/html" print print "正在生成中,请稍后再试" else: createlockFile() BASEDIR_SVN = userHome + "/work/qunying/share/" + cversion + "/美术资源" GAMECLIENT_PATH = userHome + "/work/qunying/client/" + cversion + "/gameClient/cached_res" commandsutils.execCmd("sh cgi-bin/packimage.sh " + BASEDIR_SVN + " " + GAMECLIENT_PATH) print "Content-Type: text/html" print print "生成成功" removeLockFile()
form = cgi.FieldStorage() cversion = form.getvalue('cversion') if not cversion: cversion = "trunk" rootdir = userHome + "/work/qunying/client/" + cversion + "/gameClient/cached_res" saveDir = userHome + "/work/qunying/share/" + cversion + "/程序目录/resource/i18n" ClientLangDir = saveDir + "/ClientLang.xls" svnLuaDir = "$HOME/work/qunying/client/" + cversion + "/gameClient/cached_res/script" svnExcelDir = "$HOME/work/qunying/share/" + cversion + "/程序目录/resource/i18n" cversionDir = userHome + "/work/qunying/share/" + cversion if os.path.isdir(cversionDir): commandsutils.execCmd("svn update " + svnLuaDir) commandsutils.execCmd("svn update " + svnExcelDir) NeedReplaceStr = [] NeedReplaceStrReverse = {} NeedReplaceStrMap = {} NeedReplaceStrMapOld = {} SaveIndex = 0 # 保存excel多余的index起始索引 if os.path.exists(ClientLangDir): data = xlrd.open_workbook(ClientLangDir) table = data.sheets()[0] num = table.nrows SaveIndex = num for x in range(0, num):
form = cgi.FieldStorage() cversion = form.getvalue('cversion') if not cversion: cversion = "trunk" rootdir = userHome + "/work/qunying/share/" + cversion + "/UI/qunying/cocosstudio" saveDir = userHome + "/work/qunying/share/" + cversion + "/程序目录/resource/i18n" LangCsdDir = saveDir + u"/LangCsd.xls" svnDir = "$HOME/work/qunying/share/" + cversion + "/程序目录/resource/i18n" svnCsdDir = "$HOME/work/qunying/share/" + cversion + "/UI/qunying" cversionDir = userHome + "/work/qunying/share/" + cversion if os.path.isdir(cversionDir): commandsutils.execCmd("svn update " + svnCsdDir) commandsutils.execCmd("svn update " + svnDir) NeedReplaceStr = [] NeedReplaceStrReverse = {} #检查重复key使用 repectKey = [] NeedReplaceStrMapOld = {} SaveIndex = 0 if os.path.exists(LangCsdDir): print "读取表数据" data = xlrd.open_workbook(LangCsdDir) table = data.sheets()[0] num = table.nrows SaveIndex = num for x in range(0, num):