コード例 #1
0
ファイル: proto2js.py プロジェクト: MrPanDaya/Daya
 def __init__(self):
     self.root_path = os.path.dirname(__file__)
     self.js_path = utils.flat_path(os.path.join(self.root_path, 'json'))
     self.proto_path = utils.flat_path(os.path.join(self.root_path, 'proto'))
     self.target_path = utils.flat_path(os.path.join(self.root_path, '../../../assets/scripts/common/core/network/pb'))
     Logging.log_msg("root_path:%s" % self.root_path)
     Logging.log_msg("target_path:%s \n" % self.target_path)
コード例 #2
0
ファイル: utils.py プロジェクト: profiles/buyuV5
def run_shell(cmd, cwd=None, quiet=False):
    if not quiet:
        Logging.log_msg('Running command: %s\n' % cmd)

    p = subprocess.Popen(cmd, shell=True, cwd=cwd)
    p.wait()

    if p.returncode:
        raise_known_error('Command %s failed' % cmd, p.returncode)

    return p.returncode
コード例 #3
0
ファイル: proto2js.py プロジェクト: MrPanDaya/Daya
    def build(self):
        Logging.log_msg("star build proto gen proto.js\n")

        #批处理
        try:
            utils.run_shell('pbjs -t json proto/fishing.proto > json/fishing.js')
        except Exception as e:
            raise_known_error("生成proto.js文件失败 msg=%s" % str(e))

        #修改文件增加'module.exports ='
        jsFile = utils.flat_path(os.path.join(self.js_path, 'fishing.js'))
        f1 = open(jsFile, "r")
        result = f1.read()
        f1.close()
        oResult = "module.exports = %s " % result
        f2 = open(jsFile, "w")
        f2.writelines(oResult)
        f2.close()
        Logging.log_msg("out file:%s" % jsFile)

        #将fishing.js文件拷贝到客户端的pb目录
        if os.path.exists(self.target_path):
            shutil.copy(jsFile, self.target_path)
            Logging.log_msg("move file fishing.js to path : %s \n" % self.target_path)

        Logging.log_msg("proto build success")
コード例 #4
0
def run_shell(cmd, cwd=None, quiet=False):
    if not quiet:
        cwd_info = ''
        if cwd:
            cwd_info = ' (cwd path : %s) ' % cwd
        Logging.log_msg('Running command%s: %s\n' % (cwd_info, cmd))

    p = subprocess.Popen(cmd, shell=True, cwd=cwd)
    p.wait()

    if p.returncode:
        raise_known_error('Command %s failed' % cmd, p.returncode)

    return p.returncode
コード例 #5
0
    def getCompileJsListByModule(self, module):
        jsList = []
        preList = []
        postList = []
        gameConfigPath = os.path.join(self.proj_path, "games", module,
                                      "wxpack.json")
        if os.path.exists(gameConfigPath):
            gameConfig = utils.parse_json(gameConfigPath)
            preposition = gameConfig.get("preposition", [])
            for preFile in preposition:
                jsList.append(preFile)
                preList.append(preFile)
            postposition = gameConfig.get("postposition", [])
            for postFile in postposition:
                postList.append(postFile)
        else:
            Logging.log_msg("wxpack.json 文件不存在 %s" % gameConfigPath)

        for parent, dirnames, filenames in os.walk(self.games_path):
            relpath = os.path.relpath(parent, os.path.join(parent, ".."))
            isSamePath = os.path.normpath(
                os.path.abspath(os.path.join(
                    parent, ".."))) == os.path.normpath(
                        os.path.abspath(self.games_path))
            if module == relpath and isSamePath == True:
                for p, dirname, filenames in os.walk(parent):
                    for filename in filenames:
                        token = filename.split(".")
                        if len(token) != 2 or filename.split(".")[1] != "js":
                            continue

                        filename = os.path.join(os.path.normpath(p), filename)
                        filename = os.path.relpath(filename, self.proj_path)
                        filename = filename.replace("\\", "/")

                        isPass = False
                        for postFile in postList:
                            if postFile == filename:
                                isPass = True
                        for preFile in preList:
                            if preFile == filename:
                                isPass = True
                        if 'manifest' in filename:
                            isPass = True

                        if isPass == False:
                            jsList.append(filename)
        for postFile in postList:
            jsList.append(postFile)
        return jsList
コード例 #6
0
ファイル: ResEncrypt.py プロジェクト: profiles/buyuV5
if __name__ == "__main__":
    from argparse import ArgumentParser
    parser = ArgumentParser(prog="ResEncrypt", description=utils.get_sys_encode_str("对资源文件进行加密和压缩"))

    parser.add_argument("-s", "--src", dest="src", required=True, help=utils.get_sys_encode_str("指定源文件或者文件夹。"))
    parser.add_argument("-d", "--dst", dest="dst", help=utils.get_sys_encode_str("指定目标路径。默认与源文件位置相同。"))
    parser.add_argument("--rm-src", dest="rm_src", action="store_true", help=utils.get_sys_encode_str("删除原始的文件"))
    parser.add_argument("--copy", dest="do_copy", action="store_true", help=utils.get_sys_encode_str("指定拷贝非加密文件"))
    parser.add_argument("--cfg", dest="exclude_cfg", help=utils.get_sys_encode_str("指定一个配置文件,这个文件用于配置排除某些资源文件"))

    (args, unknown) = parser.parse_known_args()

    # record the start time
    begin_time = time.time()
    try:
        if len(unknown) > 0:
            raise_known_error('未知参数 : %s' % unknown, KnownError.ERROR_WRONG_ARGS)

        encryptor = ResEncrypt(args.src, args.dst, args.rm_src, args.exclude_cfg, args.do_copy)
        encryptor.do_encrypt()
    except KnownError as e:
        # a known exception, exit with the known error number
        sys.exit(e.get_error_no())
    except Exception:
        raise
    finally:
        # output the spend time
        end_time = time.time()
        Logging.log_msg('\n总共用时: %.2f 秒\n' % (end_time - begin_time))
コード例 #7
0
ファイル: proto2js.py プロジェクト: MrPanDaya/Daya
        oResult = "module.exports = %s " % result
        f2 = open(jsFile, "w")
        f2.writelines(oResult)
        f2.close()
        Logging.log_msg("out file:%s" % jsFile)

        #将fishing.js文件拷贝到客户端的pb目录
        if os.path.exists(self.target_path):
            shutil.copy(jsFile, self.target_path)
            Logging.log_msg("move file fishing.js to path : %s \n" % self.target_path)

        Logging.log_msg("proto build success")



if __name__ == "__main__":
    # record the start time
    begin_time = time.time()
    try:
        scanner = Proto2Js()
        scanner.build()
    except KnownError as e:
        # a known exception, exit with the known error number
        sys.exit(e.get_error_no())
    except Exception:
        raise
    finally:
        # output the spend time
        end_time = time.time()
        Logging.log_msg('total time: %.2f second' % (end_time - begin_time))
コード例 #8
0
    from argparse import ArgumentParser
    parser = ArgumentParser(prog="ScanUnusedRes",
                            description=utils.get_sys_encode_str("扫描未使用的图片资源"))
    parser.add_argument(
        "--do-delete",
        dest="do_delete",
        action='store_true',
        help=utils.get_sys_encode_str("慎用!!!若指定此参数,则未使用的资源将被删除。"))

    (args, unknown) = parser.parse_known_args()

    # record the start time
    begin_time = time.time()
    try:
        if len(unknown) > 0:
            raise_known_error('unknown args: %s' % unknown,
                              KnownError.ERROR_WRONG_ARGS)

        scanner = Scanner(args)
        scanner.do_scan()
    except KnownError as e:
        # a known exception, exit with the known error number
        sys.exit(e.get_error_no())
    except Exception:
        raise
    finally:
        # output the spend time
        end_time = time.time()
        Logging.log_msg('\ntotal time: %.2f seconds\n' %
                        (end_time - begin_time))