def _copyDir(self, root, outputDir, name): sourcePath = os.path.join(root, name) destPath = os.path.join(outputDir, name) if os.path.isdir(sourcePath): self._print_copy(sourcePath, destPath) copy_dir(sourcePath, destPath) elif os.path.isfile(sourcePath): # Ignore py file, it maybe a tool script file. if not sourcePath.endswith('.py'): self._print_copy(sourcePath, destPath) shutil.copy(sourcePath, destPath) else: slog.warning('The directory [%s] is non-existence.'%sourcePath)
def _copyDir(self, root, outputDir, name): sourcePath = os.path.join(root, name) destPath = os.path.join(outputDir, name) if os.path.isdir(sourcePath): self._print_copy(sourcePath, destPath) copy_dir(sourcePath, destPath) elif os.path.isfile(sourcePath): # Ignore py file, it maybe a tool script file. if not sourcePath.endswith('.py'): self._print_copy(sourcePath, destPath) shutil.copy(sourcePath, destPath) else: slog.warning('The directory [%s] is non-existence.' % sourcePath)
def read_from_file(self, path): """从一个文本文件中读入信息。 假设该文本文件的格式与 :func:`dump()` 相同。 :param str path: 待读入的文件路径。 """ if not os.path.exists(path): slog.warning("The file %s is not exist.", path) return False txt = read_file(path) dic = eval(txt) self.copy_from_dict(dic) return True
def _getSpecialDir(self, resType): lang = self.args.lang density = self.args.density vendor = self.args.vendor source = self.conf.getGit('resource', 'path') defaultDir = os.path.join(source, '%s@@@'%resType) if not os.path.isdir(defaultDir): slog.error('The directory [%s] is not existence!'%defaultDir) return None, None specialDir = os.path.join(source, '%s@%s@%s@%s'%(resType, density, lang, '')) if os.path.isdir(specialDir): return defaultDir, specialDir slog.warning('The directory [%s] is not existed!'%specialDir) return defaultDir, None
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 _getSpecialDir(self, resType): lang = self.args.lang density = self.args.density vendor = self.args.vendor source = self.conf.getGit('resource', 'path') defaultDir = os.path.join(source, '%s@@@' % resType) if not os.path.isdir(defaultDir): slog.error('The directory [%s] is not existence!' % defaultDir) return None, None specialDir = os.path.join(source, '%s@%s@%s@%s' % (resType, density, lang, '')) if os.path.isdir(specialDir): return defaultDir, specialDir slog.warning('The directory [%s] is not existed!' % specialDir) return defaultDir, None
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 _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 toluaauto(self, bindType): if not self.isAdmin(): return inifile = None cwd = self.conf.getDistPath('tolua', 'auto') for f in list_dir(cwd): if f.endswith('.ini') \ and f.startswith('cocos2dx_') \ and bindType in f.lower(): inifile = f if inifile: xarg = [self.conf.getExe('python2'), 'genbindings.py', inifile] slog.warning('toluaauto args: %s', xarg) slog.warning('toluaauto target path: %s', cwd) py = subprocess.Popen(xarg, cwd=cwd) py.wait() else: slog.error('Cannot find a file named %s!' % bindType)
def toluaauto(self, bindType): if not self.isAdmin(): return inifile = None cwd = self.conf.getDistPath('tolua', 'auto') for f in list_dir(cwd): if f.endswith('.ini') \ and f.startswith('cocos2dx_') \ and bindType in f.lower(): inifile = f if inifile: xarg = [self.conf.getExe('python2'), 'genbindings.py', inifile] slog.warning('toluaauto args: %s', xarg) slog.warning('toluaauto target path: %s', cwd) py = subprocess.Popen(xarg, cwd=cwd) py.wait() else: slog.error('Cannot find a file named %s!'%bindType)
def convert_by_options(tpexe, options, imagefolder): """ options must be a list or a string """ xargs = [tpexe] argslist = None if isinstance(options, list): argslist = options elif isinstance(options, str): argslist = _get_args_list(options) if not argslist: slog.error("Please give some options.") return False for value in argslist: xargs.append(value) xargs.append(imagefolder) tpout = subprocess.check_output(xargs, universal_newlines=True) slog.info("Call TexturePacker, command line is: \n") slog.warning("%s\n", " ".join(xargs)) slog.info("%s\n", tpout) return True