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 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 _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 initDef(self): for afile in list_dir(self._aniDir, includeFile=True): if os.path.isdir(afile): self._piecedirs.append(afile) elif afile != 'ani_def_sample.lua' \ and afile.startswith('ani_def_') \ and afile.endswith('.lua') : self._def.append(afile)
def _dirfolder(adir): global lineno names = list_dir(adir) for name in names: if name.endswith('.md'): lineno = 0 proc(os.path.join(adir, name))
def getAnisInSpriteSheet(self): if not self._spritesheets: sp = [] for f in list_dir(self._aniDir): if f.startswith('ani_') and f.endswith('.plist'): sp.append(os.path.splitext(f)[0]) self._spritesheets = sp return self._spritesheets
def _mergeSpecial(self, dirList, outputDir, default, special=None): if special: special_list = list(list_dir(special)) # Copy default directory list. for adir in dirList: self._copyDir(default, outputDir, adir) # Copy special directory list. if special and (adir in special_list): self._copyDir(special, outputDir, adir)
def get_new_draft(self, name=None): draftnames = list(list_dir(self.get_path(self.directory.draft))) draftfile, draftname = None, None if name: draftfile, draftname = self.get_draft(name) if draftname in draftnames: raise BlogError('The draft file "%s" is already existence!' % draftname) else: name = 1 draftfile, draftname = self.get_draft(name) while os.path.exists(draftfile): name += 1 draftfile, draftname = self.get_draft(name) return draftfile, draftname
def get_new_draft(self, name=None): draftnames = list(list_dir(self.get_path(self.directory.draft))) draftfile, draftname = None, None if name: draftfile, draftname = self.get_draft(name) if draftname in draftnames: raise BlogError('The draft file "%s" is already existence!'% draftname) else: name = 1 draftfile, draftname = self.get_draft(name) while os.path.exists(draftfile): name += 1 draftfile, draftname = self.get_draft(name) return draftfile, draftname
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 toluamanual(self, bindType): if not self.isAdmin(): return toluafile = None cwd = self.conf.getDistPath('tolua', 'manual') for f in list_dir(cwd): if f.endswith('.tolua') \ and bindType in f.lower(): toluafile = f if toluafile: bindName = os.path.join(self.conf.getDistPath('tolua', 'manual'), toluafile) php = self.conf.getBin('quick/lib/compile_luabinding.php') xarg = [self.conf.getPHP(), php, '-pfx', 'cc', '-d', self.conf.getDistPath('runtime-src', 'Classes', 'lua-bindings', 'manual'), bindName] subprocess.call(xarg) 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 generateADef(self, ani): if not self._gendef: return pieceNum = len(list(list_dir(os.path.join(self._aniDir, ani)))) sub = { 'spritesheets':[ani], 'animations' :[{ 'name':ani, 'delay_per_unit':0.042, 'loops':1, 'restore_original_frame':'false', 'range':{'start':1,'end':pieceNum}, }], } # animation file is started by "ani_", main name starts from index 4. defName = 'ani_def_%s.lua'%ani[4:] defFile = self._conf.getClientPath('res', 'ani', defName) write_by_jinja(self._conf.getJinjaTempl('ani_def.lua'), defFile, sub) slog.info('Generate a ani_def file: %s.'%defFile)
def toluamanual(self, bindType): if not self.isAdmin(): return toluafile = None cwd = self.conf.getDistPath('tolua', 'manual') for f in list_dir(cwd): if f.endswith('.tolua') \ and bindType in f.lower(): toluafile = f if toluafile: bindName = os.path.join(self.conf.getDistPath('tolua', 'manual'), toluafile) php = self.conf.getBin('quick/lib/compile_luabinding.php') xarg = [ self.conf.getPHP(), php, '-pfx', 'cc', '-d', self.conf.getDistPath('runtime-src', 'Classes', 'lua-bindings', 'manual'), bindName ] subprocess.call(xarg) else: slog.error('Cannot find a file named %s!' % bindType)
def generateADef(self, ani): if not self._gendef: return pieceNum = len(list(list_dir(os.path.join(self._aniDir, ani)))) sub = { 'spritesheets': [ani], 'animations': [{ 'name': ani, 'delay_per_unit': 0.042, 'loops': 1, 'restore_original_frame': 'false', 'range': { 'start': 1, 'end': pieceNum }, }], } # animation file is started by "ani_", main name starts from index 4. defName = 'ani_def_%s.lua' % ani[4:] defFile = self._conf.getClientPath('res', 'ani', defName) write_by_jinja(self._conf.getJinjaTempl('ani_def.lua'), defFile, sub) slog.info('Generate a ani_def file: %s.' % defFile)
def _write_analytic(self): if args.name: match = re.match(r'^(\d*)-(\d*)$', args.name) a, b = None, None if match: if match.group(1): a = int(match.group(1)) if match.group(2): b = int(match.group(2)) dirlist = [] for f in list_dir(conf.get_path(args.dirname)): if not f.endswith('.md'): continue fname = int(f.split('.')[0]) if a != None: if fname < a: continue if b != None: if fname > b: continue dirlist.append(fname) abc = sorted(dirlist) slog.info('\n'.join([str(item) for item in sorted(dirlist)]))
def _write_analytic(self): if args.name: match = re.match(r'^(\d*)-(\d*)$', args.name) a,b = None,None if match: if match.group(1): a = int(match.group(1)) if match.group(2): b = int(match.group(2)) dirlist = [] for f in list_dir(conf.get_path(args.dirname)): if not f.endswith('.md'): continue fname = int(f.split('.')[0]) if a != None: if fname < a: continue if b != None: if fname > b: continue dirlist.append(fname) abc = sorted(dirlist) slog.info('\n'.join([str(item) for item in sorted(dirlist)]))
def getAniDefs(self): anidef = [] for f in list_dir(self._aniDir): if f.startswith('ani_def_') and f.endswith('.lua'): anidef.append(f) return anidef
def test_list_dir(): assert len(list(base.list_dir(workDir))) > 0
def getPieceDirs(self): if not self._piecedirs: self._piecedirs = list(list_dir(self._aniDir, include_file=False)) return self._piecedirs