def _commonProcess(self, dirList, souName, outName=None): print_sep( '\nStart to process %s in directory [%s].' % (dirList, souName), True, 40) default, special = self._getSpecialDir(souName) if not default: return if not outName: outName = souName # User don't provide any files. if len(dirList) == 0: dirList = list(list_dir(default)) # Some dir maybe in specialDir but not in defaultDir. # Merge them into dirList if special: specialList = list(list_dir(special)) if specialList: dirList = list(set(dirList + specialList)) if len(dirList) == 0: slog.error('The directory [%s] is empty.' % default) return outputDir = self.conf.getClientPath('res', outName) self._rebuildDir(outputDir) self._mergeSpecial(dirList, outputDir, default, special) print_sep( 'Process %s in directory [%s] has done.' % (dirList, souName), False, 40)
def _commonProcess(self, dirList, souName, outName=None): print_sep('\nStart to process %s in directory [%s].' %(dirList, souName), True, 40) default, special = self._getSpecialDir(souName) if not default: return if not outName: outName = souName # User don't provide any files. if len(dirList) == 0: dirList = list(list_dir(default)) # Some dir maybe in specialDir but not in defaultDir. # Merge them into dirList if special: specialList = list(list_dir(special)) if specialList: dirList = list(set(dirList+specialList)) if len(dirList) == 0: slog.error('The directory [%s] is empty.'%default) return outputDir = self.conf.getClientPath('res', outName) self._rebuildDir(outputDir) self._mergeSpecial(dirList, outputDir, default, special) print_sep('Process %s in directory [%s] has done.' %(dirList, souName), False, 40)
def _processAniByCustomDef(self, ani): default, special = _getSpecialDir('ani') if not default: return if special: default = _merge2Tmp(default, special) aniDef = AniDef(default) aniDef.initDef() names = aniDef.getNamesFromList(ani) if not names: return outputDir = self.conf.getClientPath('res', 'ani') _rebuildDir(outputDir) print_sep('Start to convert animation.') for defName in names: plistDirs = aniDef.getPlistDirsFromAniDef(defName) if not plistDirs: continue for adir in plistDirs: _convertSS(default, outputDir, adir) shutil.copy(os.path.join(default, defName), os.path.join(outputDir, defName)) print_sep('Animation convert done.', False)
def upload(appid, token, typ, fil): if not os.path.exists(fil): print_sep('File [%s] is not found, please check ' '[pub_conf.file.ios.file] in config file.'%fil, True, 40) return # 1. get upload info info = requests.get(_getInfo(appid,token,typ)) infoJson = info.json() # 2. upload files slog.info('upload files ...') pkg = infoJson['bundle']['pkg'] req = requests.post( url = pkg['url'], data={'key':pkg['key'], 'token':pkg['token']}, files={ 'file':(os.path.split(fil)[1], open(fil,'rb'), 'application/octet-stream')} ) reqJson = req.json() if reqJson['code'] == 0: if args.desc: desc = {'changelog': args.desc} else: desc = {'changelog': str(datetime.now().strftime('%y-%m-%d %I:%M:%S'))} req = requests.put( url = 'http://fir.im/api/v2/app/%s?token=%s'%(infoJson['id'], token), data=desc ) print_sep(req.json()['short'] + ' upload complete!', False, 40)
def _processAniByCustomDef(self, ani): default, special = _getSpecialDir('ani') if not default: return if special: default = _merge2Tmp(default, special) aniDef = AniDef(default) aniDef.initDef() names = aniDef.getNamesFromList(ani) if not names: return outputDir = self.conf.getClientPath('res', 'ani') _rebuildDir(outputDir) print_sep('Start to convert animation.') for defName in names: plistDirs = aniDef.getPlistDirsFromAniDef(defName) if not plistDirs: continue for adir in plistDirs: _convertSS(default, outputDir, adir) shutil.copy(os.path.join(default, defName), os.path.join(outputDir, defName)) print_sep('Animation convert done.', False)
def upload(appid, token, typ, fil): if not os.path.exists(fil): print_sep( 'File [%s] is not found, please check ' '[pub_conf.file.ios.file] in config file.' % fil, True, 40) return # 1. get upload info info = requests.get(_getInfo(appid, token, typ)) infoJson = info.json() # 2. upload files slog.info('upload files ...') pkg = infoJson['bundle']['pkg'] req = requests.post(url=pkg['url'], data={ 'key': pkg['key'], 'token': pkg['token'] }, files={ 'file': (os.path.split(fil)[1], open(fil, 'rb'), 'application/octet-stream') }) reqJson = req.json() if reqJson['code'] == 0: if args.desc: desc = {'changelog': args.desc} else: desc = { 'changelog': str(datetime.now().strftime('%y-%m-%d %I:%M:%S')) } req = requests.put(url='http://fir.im/api/v2/app/%s?token=%s' % (infoJson['id'], token), data=desc) print_sep(req.json()['short'] + ' upload complete!', False, 40)
def cpp(self): print_sep('\nStart to update the runtime-src directory.', True, 40) gitdir = self.conf.getDistPath('.git') if os.path.isdir(gitdir): slog.info('%s is a git repostory. Do nothing.' % gitdir) return runtimeDir = self.conf.getDistPath('runtime-src') self._downloadAndUnzip(self.conf.lib_conf.cpp, [runtimeDir], self.conf.getDistPath()) print_sep('\nUpdate the runtime-src directory has done.', False, 40)
def cpp(self): print_sep('\nStart to update the runtime-src directory.', True, 40) gitdir = self.conf.getDistPath('.git') if os.path.isdir(gitdir): slog.info('%s is a git repostory. Do nothing.'%gitdir) return runtimeDir = self.conf.getDistPath('runtime-src') self._downloadAndUnzip(self.conf.lib_conf.cpp, [runtimeDir], self.conf.getDistPath()) print_sep('\nUpdate the runtime-src directory has done.', False, 40)
def runapp(self): print_sep('\nStart to generate runapp.', True, 40) if self.conf.is_windows: templ = 'runapp.bat' else: templ = 'runapp.sh' confpath = self.conf.getClientPath(templ) write_by_templ(self.conf.getStringTempl(templ), confpath, {'CLIENT_PATH':self.conf.getClientPath()}, safe=True) print_sep('[%s] has generated.'%confpath, False, 40)
def _processAGit(self, gitConf): print_sep('\nStart to update the git repository [%s].'%gitConf.path, True, 40) exists = os.path.exists(gitConf.path) if exists: if self.args.force: gitArgs = git.get_args(gitConf.path, 'reset', '--hard') slog.info(' '.join(gitArgs)) subprocess.call(gitArgs) gitArgs = git.get_args(gitConf.path, 'pull', 'origin', 'master') slog.info(' '.join(gitArgs)) subprocess.call(gitArgs) print_sep('Update the git repository [%s] has done.'%gitConf.path, False, 40) else: slog.warning('%s is not exists!'%gitConf.path)
def _send_signal(self, signal, typ, repo): print_sep('\nSend signal [%s] to server [%s].'%(signal, ' '.join(typ)), True, 40) reponame = 'serverctrl' if self.args.merge_master: self._merge(reponame) typ = self._check_servername(typ) if not typ: return if 'redis' in typ: msg = 'REDIS '+signal else: msg = 'SERVER %s,%s'%(repo, ' '.join(typ)) if self._commit_empty(reponame, msg): print_sep('Send signal is successful.', False, 40)
def cocos(self): print_sep('\nStart to update the cocos2d-x framewroks.', True, 40) cocos2dx = self.conf.getDistPath('cocos2d-x') if os.path.islink(cocos2dx): slog.info('%s is a link. Do nothing.' % cocos2dx) return None if os.path.isdir(os.path.join(cocos2dx, '.git')): slog.info('%s is a git repostory. Do nothing.' % cocos2dx) return self._downloadAndUnzip(self.conf.lib_conf.cocos, [cocos2dx], self.conf.getDistPath()) print_sep('Update the cocos2d-x frameworks has done.', False, 40)
def gettext(self, gettext): if self.conf.is_windows: gt = Gettext(True, self.conf.getExe('gettext')) else: gt = Gettext() po_file = self.conf.getClientPath("i18n", self.args.lang + '.po') mo_file = self.conf.getClientPath("res", self.args.lang) if not os.path.exists(po_file): slog.error('CANNOT find the po file: [%s]!' % po_file) return if gettext == 'mo': print_sep('\nStart to convert [%s] to [%s].' % (po_file, mo_file), True, 40) gt.fmt(po_file, mo_file) print_sep('Converting PO to MO has done.', False, 40) else: # Include (game/login/conf/root) lua_files = list(get_files(self.conf.getClientPath('src', 'conf'), ext=['.lua'])) + \ list(get_files(self.conf.getClientPath('src', 'game'), ext=['.lua'])) + \ list(get_files(self.conf.getClientPath('src', 'login'), ext=['.lua'])) + \ list(get_files(self.conf.getClientPath('src', 'root'), ext=['.lua'])) print_sep('\nStart to merge new translatations to [%s].' % po_file, True, 40) gt.merge(po_file, lua_files) print_sep('Merging has done.', False, 40)
def plst(self, plist): print_sep('Start to process %s in directory plst.' %plist, True, 40) default, special = self._getSpecialDir('plst') if not default: return if len(plist) == 0: plist = list_dir(default) outputDir = self.conf.getClientPath('res', 'plst') self._rebuildDir(outputDir) sourceDir = default tmpDir = None if special: tmpDir = self._merge2Tmp(default, special, plist) plist = list_dir(tmpDir) sourceDir = tmpDir print_sep('Start to convert spritesheet.') for dir_name in plist: self._convertSS(sourceDir, outputDir, dir_name, self.args.disable_rotation) print_sep('Spritsheet converting has done.', False) if tmpDir: slog.info('Remove temporary directory [%s].'%tmpDir) shutil.rmtree(tmpDir) print_sep('Process %s in directory plst has done.' %list(plist), False, 40)
def plst(self, plist): print_sep('Start to process %s in directory plst.' % plist, True, 40) default, special = self._getSpecialDir('plst') if not default: return if len(plist) == 0: plist = list_dir(default) outputDir = self.conf.getClientPath('res', 'plst') self._rebuildDir(outputDir) sourceDir = default tmpDir = None if special: tmpDir = self._merge2Tmp(default, special, plist) plist = list_dir(tmpDir) sourceDir = tmpDir print_sep('Start to convert spritesheet.') for dir_name in plist: self._convertSS(sourceDir, outputDir, dir_name, self.args.disable_rotation) print_sep('Spritsheet converting has done.', False) if tmpDir: slog.info('Remove temporary directory [%s].' % tmpDir) shutil.rmtree(tmpDir) print_sep('Process %s in directory plst has done.' % list(plist), False, 40)
def cocos(self): print_sep('\nStart to update the cocos2d-x framewroks.', True, 40) cocos2dx = self.conf.getDistPath('cocos2d-x') if os.path.islink(cocos2dx): slog.info('%s is a link. Do nothing.'%cocos2dx) return None if os.path.isdir(os.path.join(cocos2dx, '.git')): slog.info('%s is a git repostory. Do nothing.'%cocos2dx) return self._downloadAndUnzip(self.conf.lib_conf.cocos, [cocos2dx], self.conf.getDistPath()) print_sep('Update the cocos2d-x frameworks has done.', False, 40)
def _send_signal(self, signal, typ, repo): print_sep( '\nSend signal [%s] to server [%s].' % (signal, ' '.join(typ)), True, 40) reponame = 'serverctrl' if self.args.merge_master: self._merge(reponame) typ = self._check_servername(typ) if not typ: return if 'redis' in typ: msg = 'REDIS ' + signal else: msg = 'SERVER %s,%s' % (repo, ' '.join(typ)) if self._commit_empty(reponame, msg): print_sep('Send signal is successful.', False, 40)
def lua(self): print_sep('\nStart to update the lua framworks.', True, 40) src = self.conf.getClientPath('src') cocos = os.path.join(src, 'cocos') quick = os.path.join(src, 'quick') zrong = os.path.join(src, 'zrong') if os.path.islink(cocos) or \ os.path.islink(quick) or \ os.path.islink(zrong): slog.info('%s OR %s OR %s is a link. Remove a link is forbidden.'%( cocos, quick, zrong)) return self._downloadAndUnzip(self.conf.lib_conf.lua, [cocos, quick, zrong], src) print_sep('Update lua framworks has done.', False, 40)
def _merge2Tmp(self, default, special, dirList=None): tempDir = tempfile.mkdtemp(prefix='tbbl_') slog.info("Make a temporary directory: %s", tempDir) print_sep('Start to merge directory [%s] and [%s] to temporary directory.' %(default, special)) # Merge sub-directory one by one. if dirList: self._mergeSpecial(dirList, tempDir, default, special) # Merge root directory. else: if os.path.isdir(default): slog.warning('The directory [%s] is not existed.'%sourcePath) return None copy_dir(default, tempDir) copy_dir(special, tempDir) print_sep('Merging has done.', False) return tempDir
def lua(self): print_sep('\nStart to update the lua framworks.', True, 40) src = self.conf.getClientPath('src') cocos = os.path.join(src, 'cocos') quick = os.path.join(src, 'quick') zrong = os.path.join(src, 'zrong') if os.path.islink(cocos) or \ os.path.islink(quick) or \ os.path.islink(zrong): slog.info('%s OR %s OR %s is a link. Remove a link is forbidden.' % (cocos, quick, zrong)) return self._downloadAndUnzip(self.conf.lib_conf.lua, [cocos, quick, zrong], src) print_sep('Update lua framworks has done.', False, 40)
def _processAGit(self, gitConf): print_sep('\nStart to update the git repository [%s].' % gitConf.path, True, 40) exists = os.path.exists(gitConf.path) if exists: if self.args.force: gitArgs = git.get_args(gitConf.path, 'reset', '--hard') slog.info(' '.join(gitArgs)) subprocess.call(gitArgs) gitArgs = git.get_args(gitConf.path, 'pull', 'origin', 'master') slog.info(' '.join(gitArgs)) subprocess.call(gitArgs) print_sep( 'Update the git repository [%s] has done.' % gitConf.path, False, 40) else: slog.warning('%s is not exists!' % gitConf.path)
def _merge2Tmp(self, default, special, dirList=None): tempDir = tempfile.mkdtemp(prefix='tbbl_') slog.info("Make a temporary directory: %s", tempDir) print_sep( 'Start to merge directory [%s] and [%s] to temporary directory.' % (default, special)) # Merge sub-directory one by one. if dirList: self._mergeSpecial(dirList, tempDir, default, special) # Merge root directory. else: if os.path.isdir(default): slog.warning('The directory [%s] is not existed.' % sourcePath) return None copy_dir(default, tempDir) copy_dir(special, tempDir) print_sep('Merging has done.', False) return tempDir
def gettext(self, gettext): if self.conf.is_windows: gt = Gettext(True, self.conf.getExe('gettext')) else: gt = Gettext() po_file = self.conf.getClientPath("i18n", self.args.lang+'.po') mo_file = self.conf.getClientPath("res", self.args.lang) if not os.path.exists(po_file): slog.error('CANNOT find the po file: [%s]!'%po_file) return if gettext == 'mo': print_sep('\nStart to convert [%s] to [%s].'%(po_file, mo_file), True, 40) gt.fmt(po_file, mo_file) print_sep('Converting PO to MO has done.', False, 40) else: # Include (game/login/conf/root) lua_files = list(get_files(self.conf.getClientPath('src', 'conf'), ext=['.lua'])) + \ list(get_files(self.conf.getClientPath('src', 'game'), ext=['.lua'])) + \ list(get_files(self.conf.getClientPath('src', 'login'), ext=['.lua'])) + \ list(get_files(self.conf.getClientPath('src', 'root'), ext=['.lua'])) print_sep('\nStart to merge new translatations to [%s].'%po_file, True, 40) gt.merge(po_file, lua_files) print_sep('Merging has done.', False, 40)
def ani(self, ani, gen_def): default, special = self._getSpecialDir('ani') if not default: return if special: default = self._merge2Tmp(default, special, ani) aniDef = AniDef(self.conf, default, ani, gen_def) if not aniDef.checkAni(): return outputDir = self.conf.getClientPath('res', 'ani') self._rebuildDir(outputDir) sp = aniDef.getAnisInSpriteSheet() if sp: print_sep('Start to copy existing animations.') for adir in sp: png = adir + '.png' spng = os.path.join(default, png) dpng = os.path.join(outputDir, png) shutil.copyfile(spng, dpng) self._print_copy(spng, dpng) plist = adir + '.plist' splist = os.path.join(default, plist) dplist = os.path.join(outputDir, plist) shutil.copyfile(splist, dplist) self._print_copy(splist, dplist) print_sep('Copy existing animations has done.', False) defs = aniDef.getAniDefs() if defs: print_sep('Start to copy existing ani_def files.') for anidef in defs: sanidef = os.path.join(default, anidef) danidef = os.path.join(outputDir, anidef) shutil.copyfile(sanidef, danidef) self._print_copy(sanidef, danidef) print_sep('Copy existing ani_def files has done.', False) print_sep( 'Start to convert pieces to animations and generate ani_def files.' ) for adir in aniDef.getAnisInPiece(): self._convertSS(default, outputDir, adir) aniDef.generateADef(adir) print_sep('Converting and generating has done.', False)
def ani(self, ani, gen_def): default, special = self._getSpecialDir('ani') if not default: return if special: default = self._merge2Tmp(default, special, ani) aniDef = AniDef(self.conf, default, ani, gen_def) if not aniDef.checkAni(): return outputDir = self.conf.getClientPath('res', 'ani') self._rebuildDir(outputDir) sp = aniDef.getAnisInSpriteSheet() if sp: print_sep('Start to copy existing animations.') for adir in sp: png = adir + '.png' spng = os.path.join(default, png) dpng = os.path.join(outputDir, png) shutil.copyfile(spng, dpng) self._print_copy(spng, dpng) plist = adir + '.plist' splist = os.path.join(default, plist) dplist = os.path.join(outputDir, plist) shutil.copyfile(splist, dplist) self._print_copy(splist, dplist) print_sep('Copy existing animations has done.', False) defs = aniDef.getAniDefs() if defs: print_sep('Start to copy existing ani_def files.') for anidef in defs: sanidef = os.path.join(default, anidef) danidef = os.path.join(outputDir, anidef) shutil.copyfile(sanidef, danidef) self._print_copy(sanidef, danidef) print_sep('Copy existing ani_def files has done.', False) print_sep('Start to convert pieces to animations and generate ani_def files.') for adir in aniDef.getAnisInPiece(): self._convertSS(default, outputDir, adir) aniDef.generateADef(adir) print_sep('Converting and generating has done.', False)