Exemplo n.º 1
0
    def update(self):
        if os.path.isdir(self.dbpath):
            if not os.path.isdir(self.dbrespath):
                os.makedirs(self.dbrespath)
            tools.clear_dir(self.dbrespath)

            # 构建数据库文件
            self.dbindexes = {}
            for file in os.listdir(self.dbpath):
                if (file.endswith(".xlsx") or
                        file.endswith(".xls")) and not file.startswith("~$"):
                    self.xlsxToJson(self.dbpath + "/" + file)

            # 构建数据库索引
            if not os.path.isdir(self.residxpath):
                os.makedirs(self.residxpath)
            tools.write_utf8json({"db": self.dbindexes},
                                 self.residxpath + "/db_auto.json",
                                 self.config["debug"])

            # 更新资源索引表
            idxconfpath, _ = os.path.split(self.residxconf)
            if not os.path.isdir(idxconfpath):
                os.makedirs(idxconfpath)
            if os.path.isfile(self.residxconf):
                idxconf = tools.read_json(self.residxconf)
            else:
                idxconf = {}
            idxconf[
                "db_auto"] = "$(respath)/" + self.nodename + "/indexes/db_auto.json"
            tools.write_utf8json(idxconf, self.residxconf,
                                 self.config["debug"])
Exemplo n.º 2
0
    def update(self):
        if os.path.isdir(self.protpath):
            if not os.path.isdir(self.protrespath):
                os.makedirs(self.protrespath)
            tools.clear_dir(self.protrespath)

            # 构建协议文件
            self.protindexes = []
            for file in os.listdir(self.protpath):
                if file.endswith(".prot"):
                    self.parseProtFile(self.protpath + "/" + file)

            # 构建协议索引
            if not os.path.isdir(self.residxpath):
                os.makedirs(self.residxpath)
            tools.write_utf8json({"prot": self.protindexes},
                                 self.residxpath + "/prot_auto.json",
                                 self.config["debug"])

            # 更新资源索引表
            idxconfpath, _ = os.path.split(self.residxconf)
            if not os.path.isdir(idxconfpath):
                os.makedirs(idxconfpath)
            if os.path.isfile(self.residxconf):
                idxconf = tools.read_json(self.residxconf)
            else:
                idxconf = {}
            idxconf[
                "prot_auto"] = "$(respath)/" + self.nodename + "/indexes/prot_auto.json"
            tools.write_utf8json(idxconf, self.residxconf,
                                 self.config["debug"])
Exemplo n.º 3
0
def build():
    config = tools.get_scriptconfig()
    configdir = CURPATH + "/publish/config"
    tempdir = CURPATH + "/temp"
    compackdir = CURPATH + "/" + config["path"][
        "packs"] + "/installed/completes"
    pubpackdir = CURPATH + "/" + config["path"]["packs"] + "/publish"
    if not os.path.exists(compackdir):
        raise Exception("未找到安装游戏资源:" + compackdir)
    if os.path.exists(pubpackdir):
        shutil.rmtree(pubpackdir)
    os.makedirs(pubpackdir)
    if not os.path.exists(configdir):
        os.makedirs(configdir)
    if not os.path.exists(tempdir):
        os.makedirs(tempdir)

    playpacks = []
    resversion = {}

    # 搜索剧本依赖与所属包
    localconfig = config["publish"]["localconfig"]
    localplays = {}
    localconfig["plays"] = localplays
    allplays = tools.read_json(CURPATH + "/" + config["path"]["game"] +
                               "/plays.json")

    def addplay(pname):
        if pname in allplays:
            play = allplays[pname]
            pack = play["pack"]
            if pname not in localplays:
                localplays[pname] = play
            if pack not in playpacks:
                playpacks.append(pack)
            if "prefix" in play:
                addplay(play["prefix"])

    for pname in config["publish"]["preplays"]:
        addplay(pname)
    tools.write_json(localconfig, tempdir + "/" + LOCALCONFIG, config['debug'])
    cryptoConfig.do_crypto("E", tempdir + "/" + LOCALCONFIG,
                           configdir + "/" + LOCALCONFIG)

    # 生成pack目录
    allpacks = config["publish"]["basepacks"] + playpacks
    for pack in allpacks:
        shutil.copyfile(compackdir + "/" + pack + ".pack",
                        pubpackdir + "/" + pack + ".pack")
        packvers = 0
        with open(compackdir + "/" + pack + ".pack", "rb") as f:
            packvers = tools.getLongValue(f.read(4))
        resversion[pack] = packvers

    # 生成资源版本文件
    with open(compackdir + "/boot.pack", "rb") as f:
        packvers = tools.getLongValue(f.read(4))
    resversion['boot'] = packvers
    tools.write_json(resversion, configdir + "/" + RESVERSION, config['debug'])
Exemplo n.º 4
0
	def load_config(self):
		if not self.redownload_file(self.rmconfpath,self.tmpconfpath):
			self.packsconf = {}
			self.rmgameconf = {
				"packs":self.packsconf
			}
			
			self.writeLog("build new config\n")
			
		else:
			confaes = self.getConfigAES()
			tools.decrypto_aes(confaes["key"],confaes["iv"],self.tmpconfpath,self.tmpconfjson)
			self.rmgameconf = tools.read_json(self.tmpconfjson)
			if "packs" in self.rmgameconf:
				self.packsconf = self.rmgameconf["packs"]
			else:
				self.packsconf = {}
				self.rmgameconf["packs"] = self.packsconf
			
			self.writeLog("load config from server\n")
		# 更新剧本
		self.rmgameconf["plays"] = tools.read_json(CURPATH + "/" + self.config["path"]["game"] + "/plays.json")
Exemplo n.º 5
0
	def syncNode(self,nodename,verscode):
		self.writeLog("Node Name : %s\n" % nodename)
		self.writeLog("Node Version : %s\n\n" % tools.getVersionName(verscode))
		
		self.writeLog("Sync Complete Pack ... ...\n")
		
		# 同步整包
		rmcompdir = self.syncconf["dataroot"] + "/packs/completes/" + nodename + "/" + tools.getVersionName(verscode)
		if not self.is_dirsexsit(rmcompdir):
			rmcomptmp = self.syncconf["dataroot"] + "/packs/completes/" + nodename + "/temp"
			self.mkdirs(rmcomptmp)
			self.cleardir(rmcomptmp)
			lccmptmp = self.temppath + "/completetemp"
			if not os.path.isdir(lccmptmp):
				os.makedirs(lccmptmp)
			tools.clear_dir(lccmptmp)
			
			filecount = tools.split_file(self.compspath + "/" + nodename + ".pack",lccmptmp,ZLIBFORMAT,self.syncconf["zlibmaxsize"],True)
			
			self.writeLog("Split Complete Pack To %d Files \n" % filecount)
			
			totalsize = 0
			for file in os.listdir(lccmptmp):
				upresult = self.reupload_file(lccmptmp + "/" + file,rmcomptmp + "/" + file,True)
				totalsize += os.path.getsize(lccmptmp + "/" + file)
				
				self.writeLog("Upload Split File %s/%s %s\n" % (nodename,file,"SUCCESS" if upresult else "FAILURE"))
			
			if nodename not in self.packsconf:
				self.packsconf[nodename] = {}
			self.packsconf[nodename]["verscode"] = verscode
			self.packsconf[nodename]["versname"] = tools.getVersionName(verscode)
			self.packsconf[nodename]["complete"] = {
				"path" : rmcompdir[len(self.syncconf["dataroot"]):],
				"format" : ZLIBFORMAT,
				"count" : filecount,
				"size" : totalsize
			}
			
			tools.write_json(self.packsconf[nodename], self.temppath + "/complete.config.json")
			upresult = self.reupload_file(self.temppath + "/complete.config.json",rmcomptmp + "/config.json",True)
			
			self.ftp.rename(rmcomptmp,rmcompdir)
		else:
			downresult = self.redownload_file(rmcompdir + "/config.json",self.temppath + "/complete.config.json")
			if not downresult:
				raise Exception("read fail : " + rmcompdir + "/config.json")
			completeconf = tools.read_json(self.temppath + "/complete.config.json")
			if nodename not in self.packsconf:
				self.packsconf[nodename] = {}
			self.packsconf[nodename]["verscode"] = completeconf["verscode"]
			self.packsconf[nodename]["versname"] = completeconf["versname"]
			self.packsconf[nodename]["complete"] = completeconf["complete"]
			
		self.writeLog("Sync Complete Pack End\n")
		
		# 检查多余的整包
		packvers = []
		for fname,attr in self.ftp.mlsd(self.syncconf["dataroot"] + "/packs/completes/" + nodename + "/",["type"]):
			if attr['type'] == "dir":
				packvers.append(tools.getVersionCode(fname))
		if len(packvers) > self.completenum:
			self.writeLog("\n")
			packvers = sorted(packvers, reverse=True)[self.completenum:]
			for packver in packvers:
				self.rmdir(self.syncconf["dataroot"] + "/packs/completes/" + nodename + "/" + tools.getVersionName(packver))
				self.writeLog("Remove Unnecessary Complete Pack %s\n" % (nodename + "/" + tools.getVersionName(packver)))
	
		# 同步补丁
		if os.path.isdir(self.patchspath + "/" + nodename):
			self.writeLog("\nSync Patch ... ...\n")
	
			rmpatchroot = self.syncconf["dataroot"] + "/packs/patchs/%s" % nodename
			rmpatchtmp = rmpatchroot + "/temp"
			self.mkdirs(rmpatchtmp)
			lcpatchtmp = self.temppath + "/patchtemp"
			if not os.path.isdir(lcpatchtmp):
				os.makedirs(lcpatchtmp)
			if nodename not in self.packsconf:
				self.packsconf[nodename] = {}
			if "patchs" not in self.packsconf[nodename]:
				self.packsconf[nodename]["patchs"] = {}
			for patch in os.listdir(self.patchspath + "/" + nodename):
				patchname,patchext = os.path.splitext(patch)
				rmpatchdir = rmpatchroot + "/" + patchname
				if not self.is_rmpatchexsit(nodename, patchname):
					if not self.is_dirsexsit(rmpatchdir):
						self.cleardir(rmpatchtmp)
						tools.clear_dir(lcpatchtmp)
						filecount = tools.split_file(self.patchspath + "/" + nodename + "/" + patch,lcpatchtmp,ZLIBFORMAT,self.syncconf["zlibmaxsize"],True)
						
						self.writeLog("Split %s To %d Files \n" % (patch,filecount))
						
						totalsize = 0
						for file in os.listdir(lcpatchtmp):
							upresult = self.reupload_file(lcpatchtmp + "/" + file,rmpatchtmp + "/" + file,True)
							totalsize += os.path.getsize(lcpatchtmp + "/" + file)
							
							self.writeLog("Upload Split File %s/%s/%s %s\n" % (nodename,patchname,file,"SUCCESS" if upresult else "FAILURE"))
						
						self.packsconf[nodename]["patchs"][patchname] = {
							"path" : rmpatchdir[len(self.syncconf["dataroot"]):],
							"format" : ZLIBFORMAT,
							"count" : filecount,
							"size" : totalsize
						}
						
						tools.write_json(self.packsconf[nodename]["patchs"][patchname], self.temppath + "/patch.config.json")
						upresult = self.reupload_file(self.temppath + "/patch.config.json",rmpatchtmp + "/config.json",True)
				
						self.ftp.rename(rmpatchtmp,rmpatchdir)
					else:
						downresult = self.redownload_file(rmpatchdir + "/config.json",self.temppath + "/patch.config.json")
						if not downresult:
							raise Exception("read fail : " + rmpatchdir + "/config.json")
						self.packsconf[nodename]["patchs"][patchname] = tools.read_json(self.temppath + "/patch.config.json")
						
					self.writeLog("Sync Patch %s End\n" % patch)

			self.writeLog("Sync All Patch End\n")
Exemplo n.º 6
0
	def updateConfig(self,configfile):
		# 遍历所有模型配置
		mdsconf = tools.read_json(configfile)
		for mdconf in mdsconf["models"]:
			self.gen_model(mdconf)
Exemplo n.º 7
0
	def publish(self):
		if not os.path.exists(self.andprojpath):
			raise Exception("android project %s not found !" % self.andprojpath)
		self.projectname = self.get_project_name()
		if self.projectname == None:
			raise Exception("android project name not detected !")
		if not os.path.exists(self.andpubpath):
			os.makedirs(self.andpubpath)
		buildPublish.build()
			
		pubconffile = self.publishpath + "/config.json"
		if not os.path.isfile(pubconffile):
			tools.write_json({},pubconffile,True)
		self.publishconf = tools.read_json(pubconffile)
		if "android" not in self.publishconf:
			self.publishconf["android"] = {}
		self.andpubconf = self.publishconf["android"]
		
		self.logfile = open(self.publishpath + "/android_logs.txt","w")
		
		if "verscode" in self.andpubconf:
			self.buildvers = self.andpubconf["verscode"]
			if "addversion" in self.options:
				addversion = self.options["addversion"]
			else:
				addversion = 1
			addvers = int(math.pow(1000,addversion-1))
			self.buildvers -= self.buildvers % addvers
			self.buildvers += addvers
		else:
			self.buildvers = APKROOTVERSION
		
		self.writeLog("---------------------------------PUBLISH--------------------------------\n")
		self.writeLog("Project Name : %s\n" % self.projectname)
		self.writeLog("Build Version : %s\n" % tools.getVersionName(self.buildvers))
		
		self.buildmode = "debug" if self.config["publish"]["debug"] else "release"
		self.writeLog("Build Mode : %s\n\n" % self.buildmode)
		
		if "gamename" in self.config["publish"]:
			pubapkname = self.config["publish"]["gamename"]
		else:
			pubapkname = self.projectname
		pubapkname += "_" + tools.getVersionName(self.buildvers) + ("_debug" if self.buildmode == "debug" else "") + ".apk"
		pubapkpath = self.andpubpath + "/" + pubapkname
		if os.path.exists(pubapkpath):
			os.remove(pubapkpath)
		
		self.writeLog("Gradle Build Begin ......\n")
		buildapkpath = self.gradle_build_apk()
		self.writeLog("Gradle Build End\n\n")
		
		if os.path.isfile(buildapkpath):
			shutil.copyfile(buildapkpath, pubapkpath)
			
			self.andpubconf["verscode"] = self.buildvers
			tools.write_json(self.publishconf,pubconffile,True)
			
			self.writeLog("Build APK File : %s\n" % pubapkpath)
			self.writeLog("Publish Success\n")
		else:
			self.writeLog("Publish Failure : build apk %s not found !!!\n" % buildapkpath)
		
		self.writeLog("------------------------------------------------------------------------\n\n")