Пример #1
0
    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)
Пример #2
0
    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)
Пример #3
0
 def checkAni(self):
     if not self.getPieceDirs() and self.getAnisInSpriteSheet():
         slog.error('No animation resources.')
         return False
     if not self.getAnisInPiece():
         return False
     return True
Пример #4
0
    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)
Пример #5
0
 def checkAni(self):
     if not self.getPieceDirs() and self.getAnisInSpriteSheet():
         slog.error('No animation resources.')
         return False
     if not self.getAnisInPiece():
         return False
     return True
Пример #6
0
 def _check_servername(self, typ):
     for sname in typ:
         if sname not in self.servers:
             slog.error('不支持的服务器类型: %s' % sname)
             return None
         if sname == 'redis':
             return ['redis']
     return typ
Пример #7
0
 def _check_servername(self, typ):
     for sname in typ:
         if sname not in self.servers:
             slog.error('不支持的服务器类型: %s'%sname)
             return None
         if sname == 'redis':
             return ['redis']
     return typ
Пример #8
0
 def test(self):
     res = self.conf.getGit('resource', 'path')
     sourcedir = os.path.join(res, 'test')
     targetdir = self.conf.getClientPath('res', 'test')
     self._print_copy(sourcedir, targetdir)
     if not os.path.exists(sourcedir):
         slog.error('No such file or directory: [%s].' % sourcedir)
         return
     if os.path.exists(targetdir):
         shutil.rmtree(targetdir)
     shutil.copytree(sourcedir, targetdir)
     slog.info('Copy done.')
Пример #9
0
 def test(self):
     res = self.conf.getGit('resource', 'path')
     sourcedir = os.path.join(res, 'test')
     targetdir = self.conf.getClientPath('res', 'test')
     self._print_copy(sourcedir, targetdir)
     if not os.path.exists(sourcedir):
         slog.error('No such file or directory: [%s].'%sourcedir)
         return
     if os.path.exists(targetdir):
         shutil.rmtree(targetdir)
     shutil.copytree(sourcedir, targetdir)
     slog.info('Copy done.')
Пример #10
0
 def _merge(self, reponame):
     repopath, curbr = self._check_branch(reponame)
     if not repopath or not curbr:
         return
     code, output = git.call(repopath, 'fetch')
     if code > 0:
         slog.error(output)
         return
     code, output = git.call(repopath, 'merge', 'master')
     if code > 0:
         slog.error(output)
         return
     slog.info(output)
Пример #11
0
 def _merge(self, reponame):
     repopath, curbr = self._check_branch(reponame)
     if not repopath or not curbr:
         return
     code, output = git.call(repopath, 'fetch')
     if code > 0:
         slog.error(output)
         return
     code, output = git.call(repopath, 'merge', 'master')
     if code > 0:
         slog.error(output)
         return
     slog.info(output)
Пример #12
0
 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
Пример #13
0
 def _commit_empty(self, reponame, msg):
     repopath, curbr = self._check_branch(reponame)
     if not repopath or not curbr:
         return False
     code, output = git.call(repopath, 'commit', '--allow-empty', '-m', msg)
     if code > 0:
         slog.error(output)
         return
     code, output = git.call(repopath, 'push', 'origin', curbr)
     if code > 0:
         slog.error(output)
         return False
     slog.info(output)
     return True
Пример #14
0
 def _commit_empty(self, reponame, msg):
     repopath, curbr = self._check_branch(reponame)
     if not repopath or not curbr:
         return False
     code, output = git.call(repopath, 'commit', '--allow-empty', '-m', msg)
     if code > 0:
         slog.error(output)
         return
     code, output = git.call(repopath, 'push', 'origin', curbr)
     if code > 0:
         slog.error(output)
         return False
     slog.info(output)
     return True
Пример #15
0
 def getAnisInPiece(self):
     if not self._pieces:
         if not self._aniArg:
             self._pieces = self.getPieceDirs()
         else:
             anis = []
             for ani in self._aniArg:
                 if not ani.startswith('ani_'):
                     ani = 'ani_' + ani
                 if not ani in self._piecedirs:
                     slog.error('%s is not an animation resource.', ani)
                     return None
                 anis.append(ani)
             self._pieces = anis
     return self._pieces
Пример #16
0
 def getAnisInPiece(self):
     if not self._pieces:
         if not self._aniArg:
             self._pieces = self.getPieceDirs()
         else:
             anis = []
             for ani in self._aniArg:
                 if not ani.startswith('ani_'):
                     ani = 'ani_'+ani 
                 if not ani in self._piecedirs:
                     slog.error('%s is not an animation resource.', ani)
                     return None
                 anis.append(ani)
             self._pieces = anis
     return self._pieces
Пример #17
0
 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
Пример #18
0
    def fmt(self, po_file, mo_file):
        """将 po 文件转换成 mo 文件。

        :param string po_file: 待转换的 po 文件路径。
        :param string mo_file: 目标 mo 文件的路径。

        """
        if not os.path.exists(po_file):
            slog.error('The PO file [%s] is non-existen!'%po_file)
            return
        txt = subprocess.check_output([self._msgfmt, 
            '--check', "--strict", '--verbose', 
            "--output-file", mo_file, po_file], 
                stderr=subprocess.STDOUT, 
                universal_newlines=True)
        slog.info(txt)
Пример #19
0
    def fmt(self, po_file, mo_file):
        """将 po 文件转换成 mo 文件。

        :param string po_file: 待转换的 po 文件路径。
        :param string mo_file: 目标 mo 文件的路径。

        """
        if not os.path.exists(po_file):
            slog.error('The PO file [%s] is non-existen!' % po_file)
            return
        txt = subprocess.check_output([
            self._msgfmt, '--check', "--strict", '--verbose', "--output-file",
            mo_file, po_file
        ],
                                      stderr=subprocess.STDOUT,
                                      universal_newlines=True)
        slog.info(txt)
Пример #20
0
 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)
Пример #21
0
 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)
Пример #22
0
 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)
Пример #23
0
 def getNamesFromList(self, aniList):
     if len(aniList) == 0:
         return list(self._def)
     def _expendDef(self, name):
         return 
     existList = []
     for ani in aniList:
         if not ani.startswith('ani_def_'):
             fullName = 'ani_def_%s.lua'%ani
         else:
             fullName = ani+'.lua'
         if fullName in self._def:
             existList.append(fullName)
         else:
             slog.error('The ani_def file %s is not existed'%fullName)
     if len(existList) == 0:
         slog.error('No ani_def file in providing list!')
         return None
     return existList
Пример #24
0
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
Пример #25
0
 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)
Пример #26
0
    def getNamesFromList(self, aniList):
        if len(aniList) == 0:
            return list(self._def)

        def _expendDef(self, name):
            return

        existList = []
        for ani in aniList:
            if not ani.startswith('ani_def_'):
                fullName = 'ani_def_%s.lua' % ani
            else:
                fullName = ani + '.lua'
            if fullName in self._def:
                existList.append(fullName)
            else:
                slog.error('The ani_def file %s is not existed' % fullName)
        if len(existList) == 0:
            slog.error('No ani_def file in providing list!')
            return None
        return existList
Пример #27
0
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
Пример #28
0
    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)
Пример #29
0
def update_submodules(path, init=True, update=True):
    """更新子模块。

    :param str path: git 仓库文件夹路径。
    :param bool init: 是否初始化子模块。
    :param bool update: 是否更新子模块。

    """
    succ = None
    if init:
        arg = get_args(path, 'submodule', 'init')
        slog.info(' '.join(arg))
        succ = subprocess.call(arg)
        if succ>0:
            slog.error('git execute error!')
            return succ
    if update:
        arg = get_args(path, "submodule", "update")
        slog.info(' '.join(arg))
        succ = subprocess.call(arg)
        if succ>0:
            slog.error('git execute error!')
            return succ
    return succ
Пример #30
0
 def _check_branch(self, reponame):
     repopath = self.conf.getGit(reponame, 'path')
     if not os.path.exists(repopath):
         slog.error('Please initialize "{0}" repostory first! '
                 'You can type "hhlb init --{0}" to do it.'.format(reponame))
         return None, None
     if not git.isclean(repopath):
         slog.error('Your git repostory [%s] is not clean! '
                 'Please commit it first.'%repopath)
         return None, None
     branches = git.get_branches(repopath)
     curbr = branches[0]
     if not curbr:
         slog.error('Get branches error!')
         return None, None
     if curbr != self.conf.user_conf.name:
         slog.error('Your git branch is [%s], but your name is [%s], '
                 'Please correct it.'%(curbr, self.conf.user_conf.name))
         return None, None
     return repopath, curbr
Пример #31
0
 def _check_branch(self, reponame):
     repopath = self.conf.getGit(reponame, 'path')
     if not os.path.exists(repopath):
         slog.error(
             'Please initialize "{0}" repostory first! '
             'You can type "hhlb init --{0}" to do it.'.format(reponame))
         return None, None
     if not git.isclean(repopath):
         slog.error('Your git repostory [%s] is not clean! '
                    'Please commit it first.' % repopath)
         return None, None
     branches = git.get_branches(repopath)
     curbr = branches[0]
     if not curbr:
         slog.error('Get branches error!')
         return None, None
     if curbr != self.conf.user_conf.name:
         slog.error('Your git branch is [%s], but your name is [%s], '
                    'Please correct it.' %
                    (curbr, self.conf.user_conf.name))
         return None, None
     return repopath, curbr
Пример #32
0
def proc(fullname):
    global lineno
    slog.info('analyse:%s',fullname)

    f = open(fullname, mode='r', encoding='utf-8')
    flag = 0

    ps = []
    p = Protocol()
    datas = []
    pdatas = None
    indent = 0
    for line in f:
        lineno += 1

        line = line.replace('\t','    ')
        line = line.rstrip()
        if line[0:2] == '//' or not line: # or not (line.strip()):
            continue

        slog.info('lineno: %s, line: %s', lineno, line)
        #line = line.strip()
        if line[0:1] == '#' or flag == 0:
            if line[0:1] == "#":
                if indent == 0 :
                    ps.append(p)
                    p = Protocol()
                    flag = 0
                else:
                    indent -= 4
                    #pdatas = datas.pop()
                    ps.append(p)
                    p = Protocol()
                    flag = 0
            p = Protocol()
            datas = []
            pdatas = None
            indent = 0
            pdatas = p.datas
            datas.append(pdatas)

            if line[0:3] == "###" and line[3:5]=="**" and "**" in line[5:]:
                #proto start
                code = line[5:]
                ss = code.split('**')
                try:
                    p.code = int(ss[0])
                    p.title = ss[1].strip()
                    flag = 1
                    slog.info('code: %s, title: %s', p.code, p.title)
                except:
                    slog.error("%s has err!!!%s" ,lineno,line)
                    return
            continue
        elif flag == 1:
            if line[0:4] == "ver:":
                try:
                    p.ver=int(line[4:])
                    flag = 2
                except:
                    slog.info("%s has err!!!need ver ,but is :%s" ,lineno,line)
                    return
            else:
                slog.info("%s has err!!!need ver ,but is :%s" ,lineno,line)
                return
            continue

        elif flag == 2:
            #parse datas
            if line[0:5] == "data:":
                flag = 3
                continue
            slog.info("%s line has err!!!need data,but is :%s" ,lineno,line)
            return

        elif flag == 3:
            if line[0:1] == "#":
                if indent == 0 :
                    ps.append(p)
                    p = Protocol()
                    flag = 0
                    slog.info('------------------------')
                else:
                    indent -= 4
                    ps.append(p)
                    p = Protocol()
                    flag = 0
                    #pdatas = datas.pop()
                    slog.info('---...............---------------------')
                continue

            ss = line.split("+")
            if len(ss) == 1:
                if len(p.datas)==0:
                    slog.info("%s line has err!!!need '+ ',but is :%s" ,lineno,line)
                    flag = 0
                    continue
                else:
                    #parse one protocol ,then write to xml or other
                    if indent == 0 :
                        ps.append(p)
                        p = Protocol()
                        flag = 0
                    else:
                        indent -= 4
                        #pdatas = datas.pop()
                        ps.append(p)
                        p = Protocol()
                        flag = 0
                    continue

            if '[(' in ss[1] or ')...]' in ss[1]:
                continue

            if len(ss[0]) < indent:
                #this layer is end
                indent -= 4
                #pdatas = datas.pop()

            if indent > 0 :
                continue

            ss = ss[1]
            ss = ss.split(",")

            da = ProtoData()
            da.number = int(ss[0])
            da.datatype = ss[1].strip()
            if da.datatype == "":
                da.datatype = "uvint"

            if da.datatype not in ["uvint","vint","uint32","uint16","string","list"]:
                slog.info("%s datatype is wrong!!!" ,lineno)
                #slog.info("%s datatype is wrong!!!line:%s" ,lineno,line)
                return

            da.fieldname = ss[2].strip()
            da.comment = ss[3].strip()

            # slog.info(indent)
            # slog.info(da.number)
            # slog.info(da.fieldname)
            # slog.info(da.datatype)
            # slog.info(da.comment)

            pdatas.append(da)

            if da.datatype == "list":
                #da.datas= []
                #flag == 4
                indent += 4

                #datas.append(pdatas)
                #pdatas = da.datas

            continue

    slog.info('---------')
    if p and len(p.datas)>0:
        ps.append(p)

    f.close()
    renderLua(ps)