Ejemplo n.º 1
0
 def del_js_file(self, path, name):
     js_file_path = utils.flat_path(os.path.join(path, name + '.js'))
     if os.path.isfile(js_file_path):
         os.remove(js_file_path)
     jsc_file_path = utils.flat_path(os.path.join(path, name + '.jsc'))
     if os.path.isfile(jsc_file_path):
         os.remove(jsc_file_path)
Ejemplo n.º 2
0
    def do_encrypt(self):
        if os.path.isfile(self.src_path):
            self.encrypt_file(self.src_path, self.dst_path)
        else:
            for (parent, subdirs, files) in os.walk(self.src_path):
                dst_path = utils.flat_path(
                    os.path.join(self.dst_path,
                                 os.path.relpath(parent, self.src_path)))
                for f in files:
                    if f == '.DS_Store':
                        continue

                    full_path = utils.flat_path(os.path.join(parent, f))
                    basename, ext = os.path.splitext(full_path)
                    if ext.lower() in ENCRYPT_CFG.keys():
                        self.encrypt_file(full_path, dst_path)
                    elif f == 'manifest':
                        self.encrypt_file(full_path, dst_path)
                    elif self.do_copy and not self.dst_is_src:
                        # 需要拷贝非 lua 文件
                        if not os.path.isdir(dst_path):
                            os.makedirs(dst_path)
                        self.output_info('%s 文件被拷贝' % full_path)
                        shutil.copy(
                            full_path,
                            os.path.join(dst_path,
                                         os.path.basename(full_path)))
Ejemplo n.º 3
0
    def __init__(self, args):
        # 配置文件
        self.batch_cfg_file = utils.flat_path(args.proj_cfg)
        if not os.path.isfile(self.batch_cfg_file):
            raise_known_error("文件 %s 不存在" % self.batch_cfg_file,
                              KnownError.ERROR_PATH_NOT_FOUND)
        self.root_dir = os.path.dirname(self.batch_cfg_file)
        self.batch_info = self._parse_json(self.batch_cfg_file)
        if not self.batch_info:
            raise_known_error('解析文件 %s 失败' % self.batch_cfg_file,
                              KnownError.ERROR_PARSE_FILE)

        self.app_id = self.batch_info['appid']
        self.channel_id = self.batch_info['channel']
        self.proj_parth = utils.flat_path(
            os.path.join(self.root_dir, self.batch_info['proj_root']))
        self.pack_parth = utils.flat_path(
            os.path.join(self.root_dir, self.batch_info['pack_root']))
        # 是否需要重编creator
        self.rebuild_creator = args.rebuild_creator
        if self.rebuild_creator:
            # 检查Creator的安装目录
            self.creator_exe_path = utils.check_environment_variable(
                'CREATOR_PATH')
            if not os.path.isdir(self.creator_exe_path):
                raise_known_error("环境变量 CREATOR_PATH 未设置")
            self.creator_proj_path = utils.flat_path(
                os.path.join(self.proj_parth, '../../'))

        self.encrypt_res = args.encrypt_res

        Logging.debug_msg('是否重新编译creator工程 : %s' % self.rebuild_creator)
        Logging.debug_msg('是否加密图片资源 : %s' % self.encrypt_res)
        Logging.debug_msg('------------------------------------\n')
Ejemplo n.º 4
0
def createZip(zipDir, dst, versionName):
    tempPath = utils.flat_path(os.path.join(dst, ""))
    publishPath = utils.flat_path(os.path.join(dst, "../publish"))
    print(tempPath)
    print(publishPath)

    manifest = {}
    manifest["version"] = versionName
    manifest["packageUrl"] = ''
    manifest["remoteManifestUrl"] = ''
    manifest["remoteVersionUrl"] = ''
    manifest["searchPaths"] = []
    manifest["assets"] = {}

    assets = manifest["assets"]
    get_file_path_md5(tempPath, '/res', assets)

    #创建project.manifest
    project_manifest = utils.flat_path(
        os.path.join(tempPath, 'project.manifest'))
    file_m = open(project_manifest, "wb")
    file_m.writelines(json.dumps(manifest))
    file_m.close()

    #生成zip包
    out_dir = '%s/%s.zip' % (publishPath, versionName)
    utils.zip_folder(tempPath, out_dir)
Ejemplo n.º 5
0
def start(absDir):#遍历当前目录以及递归的子目录,找到所有的png图片
    global ext_path
    global PngMap
    global Uncompress
    ext_path = utils.flat_path(os.path.join(os.path.dirname(__file__), "../../png_quant/bin/win32/pngquant"))
    print(ext_path)
    absDir = utils.flat_path(absDir)
    print(absDir)
    json_file = utils.flat_path(os.path.join(os.path.dirname(__file__), "PngMap.json"))
    print(json_file)
    try:
        f = open(json_file)
        PngMap = json.load(f)
        f.close()
    except:
        pass

    #print(PngMap['res/raw-assets/6a/6a811324-26ea-4e78-b238-4509160c26ad.png'])
    json_file = utils.flat_path(os.path.join(os.path.dirname(__file__), "uncompress.json"))
    print(json_file)
    try:
        f = open(json_file)
        Uncompress = json.load(f)['uncompress_dir']
        f.close()
    except:
        pass
    print(Uncompress)
    traverseDir(absDir)
Ejemplo n.º 6
0
 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)
Ejemplo n.º 7
0
    def _modify_apihelper(self, channel_id, isThirdPart, rollback_obj):
        library_android_path = utils.flat_path(
            os.path.join(self.proj_parth, 'project_android_20/unityLibrary'))
        nativeHelper = os.path.join(
            library_android_path, 'src/main/java/com/weile/api/ApiHelper.java')
        # 备份文件
        rollback_obj.record_file(utils.flat_path(nativeHelper))
        f = open(nativeHelper)
        lines = f.readlines()
        f.close()

        new_lines = []
        pattern_channelId = 'private static int ChannelId ='
        pattern_thirdPart = 'private static boolean isThirdPart ='
        strThirdPart = "false"
        if isThirdPart:
            strThirdPart = "true"
        for line in lines:
            check_str = line.strip()
            matchChannelId = re.match(pattern_channelId, check_str)
            if matchChannelId:
                line = '\tprivate static int ChannelId = ' + channel_id + ';\n'
            matchThirdPart = re.match(pattern_thirdPart, check_str)
            if matchThirdPart:
                line = '\tprivate static boolean isThirdPart = ' + strThirdPart + ';\n'

            new_lines.append(line)

        f = open(nativeHelper, 'w')
        f.writelines(new_lines)
        f.close()
Ejemplo n.º 8
0
    def __init__(self, src, dst, rm_src, exclude_cfg, do_copy, quiet=False):
        self.src_path = utils.flat_path(src)
        if not os.path.exists(self.src_path):
            raise_known_error('%s 不存在' % self.src_path, KnownError.ERROR_WRONG_ARGS)

        if not dst:
            if os.path.isdir(src):
                self.dst_path = self.src_path
            else:
                self.dst_path = os.path.dirname(self.src_path)
        else:
            self.dst_path = utils.flat_path(dst)

        if os.path.isfile(self.dst_path):
            raise_known_error('-d 参数必须为文件夹', KnownError.ERROR_WRONG_ARGS)

        self.dst_is_src = (os.path.isdir(self.src_path) and self.src_path == self.dst_path )

        self.rm_src = rm_src
        self.do_copy = do_copy
        self.quiet = quiet
        if exclude_cfg is None:
            self.exclude_cfg = None
        elif isinstance(exclude_cfg, list):
            self.exclude_cfg = self.convert_rules(exclude_cfg)
        else:
            self.exclude_cfg = self.parse_exclude_cfg(exclude_cfg)
Ejemplo n.º 9
0
 def _modify_res(self, apk_cfg_info, cfg_dir, rollback_obj):
     #备份res
     rollback_obj.record_folder(
         os.path.join(self.proj_android_path, 'launcher/src/main/res'))
     for p in apk_cfg_info[PackAPK.CFG_JAVA_RES].split(','):
         java_res_path = utils.flat_path(os.path.join(cfg_dir, p.strip()))
         copy_cfg = {'from': '.', 'to': 'res', 'exclude': ['**/.DS_Store']}
         res_path = utils.flat_path(
             os.path.join(self.proj_android_path, 'launcher/src/main'))
         excopy.copy_files_with_config(copy_cfg, java_res_path, res_path)
Ejemplo n.º 10
0
    def update_resources(self):
        Logging.debug_msg('正在拷贝资源到tmp目录..')
        # 拷贝资源到tmp目录
        for res in self.batch_info['include']:
            if not res:
                continue
            copy_cfg = {'from': res, 'to': res, 'exclude': ['**/.DS_Store']}
            excopy.copy_files_with_config(copy_cfg, self.proj_parth,
                                          self.temp_dir)

        # 先删除CfgPackage.js或CfgPackage.jsc
        scripts_path = utils.flat_path(
            os.path.join(self.temp_dir, 'src/assets/scripts'))
        self.del_js_file(scripts_path, 'CfgPackage')
        self.del_js_file(scripts_path, 'manifest')

        # 替换CfgPackage.js文件
        pack_cfg_path = utils.flat_path(
            os.path.join(self.pack_parth, self.app_id, self.channel_id))
        copy_cfg = {
            'from': 'cfg',
            'to': 'src/assets/scripts',
            'exclude': ['**/.DS_Store']
        }
        excopy.copy_files_with_config(copy_cfg, pack_cfg_path, self.temp_dir)

        Logging.debug_msg('正在生成资源列表的md5信息..')
        # 生成资源列表的md5信息
        assetsObj = self.manifest_obj['assets']
        self.get_file_path_md5(self.temp_dir, assetsObj)

        # 替换掉文件 manifest.js
        tmp_str = "(function() { window.CustomManifestAssets = holdString})();"
        tmp_str = tmp_str.replace("holdString", json.dumps(assetsObj))
        src_path = utils.flat_path(os.path.join(self.temp_dir, 'src'))
        manifest_js_path = utils.flat_path(
            os.path.join(src_path, 'assets/scripts/manifest.js'))
        file_m = open(manifest_js_path, "wb")
        file_m.writelines(tmp_str)
        file_m.close()

        # 重新计算manifest.js的md5值
        rel_path = 'src/assets/scripts/manifest.js'
        assetsObj[rel_path] = {
            'size': os.path.getsize(manifest_js_path),
            'md5': self.get_file_md5(manifest_js_path)
        }

        Logging.debug_msg('生成project.manifest文件..')
        # 创建project.manifest
        version_manifest = utils.flat_path(
            os.path.join(self.temp_dir, 'project.manifest'))
        file_m = open(version_manifest, "wb")
        file_m.writelines(json.dumps(self.manifest_obj))
        file_m.close()
Ejemplo n.º 11
0
    def __init__(self, args):
        self.src_file = utils.flat_path(args.src_file)
        if not os.path.isfile(self.src_file):
            raise_known_error('文件 %s 不存在' % self.src_file, KnownError.ERROR_PATH_NOT_FOUND)

        if args.dst_file:
            self.dst_file = utils.flat_path(args.dst_file)
        else:
            name, ext = os.path.splitext(self.src_file)
            self.dst_file = '%s_new%s' % (name, ext)

        Logging.debug_msg("原始文件路径:%s" % self.src_file)
        Logging.debug_msg("输出文件路径:%s" % self.dst_file)
Ejemplo n.º 12
0
    def __init__(self, args):
        self.no_rollback = args.no_rollback
        self.no_build_creator = args.no_build_creator
        self.root_dir = os.path.dirname("./")

        # 检查Creator的安装目录跟工程目录
        self.creator_proj_parth = utils.flat_path(
            os.path.join(os.path.dirname(__file__), '../../../../'))
        self.proj_parth = utils.flat_path(
            os.path.join(os.path.dirname(__file__),
                         '../../../../build/web-mobile'))
        print(self.creator_proj_parth)
        print(self.proj_parth)
Ejemplo n.º 13
0
    def _do_remove_agora(self, rollback_obj):
        for f in PackAPK.AGORA_LIBS:
            agora_lib_path = utils.flat_path(
                os.path.join(self.library_android_path, f))
            if not os.path.isfile(agora_lib_path):
                raise_known_error('Agora 库文件: %s 不存在' % agora_lib_path,
                                  KnownError.ERROR_PATH_NOT_FOUND)

            # 记录库文件,方便回滚
            rollback_obj.record_file(agora_lib_path)
            # 删除库文件
            os.remove(agora_lib_path)

        # 需要替换 wlgame.so
        src_so = utils.flat_path(
            os.path.join(self.library_android_path, PackAPK.NO_AGORA_SO))
        if not os.path.isfile(src_so):
            raise_known_error('不包含 Agora 的库文件: %s 不存在' % src_so,
                              KnownError.ERROR_PATH_NOT_FOUND)
        replace_so = utils.flat_path(
            os.path.join(self.library_android_path,
                         PackAPK.NO_AGORA_NEED_REPLACE_SO))
        if not os.path.isfile(replace_so):
            raise_known_error('库文件: %s 不存在' % replace_so,
                              KnownError.ERROR_PATH_NOT_FOUND)
        rollback_obj.record_file(replace_so)
        shutil.copy2(src_so, os.path.dirname(replace_so))

        # 需要修改 AppActivity.java 文件
        java_file = utils.flat_path(
            os.path.join(self.proj_android_path,
                         "src/weile/games/AppActivity.java"))
        if not os.path.isfile(java_file):
            raise_known_error('文件 %s 不存在' % java_file,
                              KnownError.ERROR_PATH_NOT_FOUND)

        rollback_obj.record_file(java_file)
        f = open(java_file)
        lines = f.readlines()
        f.close()
        pattern1 = "agora-rtc-sdk-jni"
        pattern2 = "apm-plugin-agora-cocos2dx"
        new_lines = []
        for l in lines:
            if l.find(pattern1) >= 0 or l.find(pattern2) >= 0:
                l = '// ' + l
            new_lines.append(l)

        f = open(java_file, 'w')
        f.writelines(new_lines)
        f.close()
Ejemplo n.º 14
0
    def _check_cfg_info(self, cfg_info, dir):
        ret = None
        sample_str = None
        for key in PackAPK.CHECK_CFG_INFO.keys():
            key_paths = key.split('.')
            check_info = PackAPK.CHECK_CFG_INFO[key]
            sample_str = check_info.get("sample")
            if len(key_paths) > 1:
                parent = cfg_info.get(key_paths[0], None)
                if (parent is None) or (not isinstance(parent, dict)):
                    ret = "配置文件中 %s 的值错误" % parent
                    break
                check_value = parent.get(key_paths[1], None)
            else:
                check_value = cfg_info.get(key, None)

            if check_value is None:
                ret = "配置文件中 %s 的值错误" % key
                break

            check_value = utils.non_unicode_str(check_value)
            if check_info["type"] == 'file':
                check_value = utils.flat_path(os.path.join(dir, check_value))
                if not os.path.isfile(check_value):
                    ret = "配置文件中 %s 的值并不是一个有效的文件" % key
                    break
            elif check_info["type"] == 'dir':
                check_value = utils.flat_path(os.path.join(dir, check_value))
                if not os.path.isdir(check_value):
                    ret = "配置文件中 %s 的值并不是一个有效的文件夹" % key
                    break
            elif check_info["type"] == 'dir_list':
                if not self._check_dir_list(dir, check_value):
                    ret = "配置文件中 %s 的值并不是一个有效的文件夹列表" % check_value
                    break
            else:
                if not isinstance(check_value, str):
                    ret = "配置文件中 %s 的值并不是字符串" % key
                    break

                pattern = check_info.get("pattern")
                if pattern:
                    match = re.match(pattern, check_value)
                    if not match:
                        ret = "配置文件中 %s 的值格式错误" % key
                        break

        if ret and sample_str:
            ret = "%s,正确示例:%s " % (ret, sample_str)

        return ret
Ejemplo n.º 15
0
    def __init__(self, args):
        self.no_rollback = args.no_rollback
        self.no_encrypt = args.no_encrypt
        self.no_build_creator = args.no_build_creator
        self.is_qq = args.is_qq
        self.root_dir = os.path.dirname("./")

        # 检查Creator的安装目录跟工程目录
        self.creator_proj_path = utils.flat_path(
            os.path.join(os.path.dirname(__file__), '../../../../'))
        self.proj_parth = utils.flat_path(
            os.path.join(os.path.dirname(__file__),
                         '../../../../build/wechatgame'))
        print("creator_proj_parth:%s" % self.creator_proj_path)
        print("proj_parth:%s" % self.proj_parth)
Ejemplo n.º 16
0
    def do_build(self):
        dst = utils.flat_path('./temp/')
        print("dst:%s" % dst)
        # 编译creator工程
        if not self.no_build_creator:
            self.build_creator_proj()

        cfgPath = utils.flat_path('./CfgPackage.js')
        # 获得版本号
        f = open(cfgPath, 'rU')
        content = f.read()
        f.close()

        # 获取版本号
        pattern = re.compile(
            r'window\.APP_VERSION[ \t]*=[ \t]*\[([^\[\]]*)\]')  # 查找数字
        tb = pattern.findall(content)
        versionStr = tb[0]
        versionStr = versionStr.replace(",", ".")
        versionStr = versionStr.replace(" ", "")
        print('version: ' + versionStr)

        # 获得微信id wxappid: "wx31fa4358d97a7923"
        pattern = re.compile(r'wxappid[ \t]*:[ \t]*\"(.*)\"')
        tb = pattern.findall(content)
        wxid = tb[0]
        print('wxid:' + wxid)

        time.sleep(1)

        packArgs = {}
        packArgs['confuseResImport'] = False
        packArgs['exclude'] = False
        packArgs['compressPng'] = True
        packArgs['encrytPng'] = False
        packArgs['encrytJS'] = False
        packArgs['cfgPackagePath'] = cfgPath
        packArgs['nativePath'] = ''
        packArgs['zipDir'] = 'minigame'
        packArgs['minigame'] = True
        packArgs['mergeJson'] = True
        packArgs['wxid'] = wxid
        # packArgs['currentChannel'] = currentChannel

        file___ = os.path.split(__file__)[0]
        packArgs['mod_file_path'] = file___

        genResMiniGame.start(versionStr, self.proj_parth, dst, packArgs)
Ejemplo n.º 17
0
def start(version, srcDir, dstDir, packArgs):  #遍历当前目录
    # removeClass('--------------,AndroidXiaomi:[function(t,e,i){}],--------------', 'AndroidXiaomi')
    # if True:
    #     return
    print(srcDir)
    print(dstDir)
    if os.path.isdir(dstDir):
        time.sleep(0.01)
        shutil.rmtree(dstDir)
        time.sleep(0.01)
    global PngMap
    # creator 生成的png映射表
    json_file = utils.flat_path(
        os.path.join(os.path.dirname(__file__), "PngMap.json"))
    print(json_file)
    try:
        f = open(json_file)
        PngMap = json.load(f)
        f.close()
    except:
        pass
    #拷贝src目录
    copySrc(srcDir, dstDir)
    shortProjectJS.start(
        utils.flat_path(os.path.join(dstDir, "../project/src/project.js")),
        'minigame', packArgs['currentChannel'])

    removeTextureJson(
        utils.flat_path(os.path.join(dstDir, "../project/internal/")))
    #拷贝res
    if packArgs['mergeJson']:
        copyResRawAssets(srcDir, dstDir)
        mergeJson(srcDir, dstDir, dstDir + '/res/MergeJson.json')
    else:
        copyRes(srcDir, dstDir)
    #压缩png
    if packArgs['compressPng']:
        pngyu.start(dstDir)

    #copy渠道相关的CfgPackage.js
    if packArgs['cfgPackagePath']:
        dstPath = utils.flat_path(os.path.join(dstDir, "../project")) + '/'
        moveFileTo(packArgs['cfgPackagePath'],
                   dstPath + 'src/assets/scripts/CfgPackage.js')

    zipDir = ''
    #生产远端资源包和更新包
    createZip(zipDir, dstDir, version)
Ejemplo n.º 18
0
def deleteMapDir():
    region = m_jsonObj[kRegion]
    if region == 'all':
        return

    region_list = []
    new_list = region.split(',')
    for r in new_list:
        if r.strip() != '':
            region_list.append(r)

    # 超过1个地区时需要带上全国地图
    if len(region_list) > 1:
        region_list.append('0')

    keep_name_list = []
    for rid in region_list:
        keep_name = 'map_%s' % rid
        keep_name_list.append(keep_name)

    map_path = utils.flat_path(os.path.join(m_appPath, 'res/hall/map'))
    if os.path.isdir(map_path):
        for f in os.listdir(map_path):
            full_path = os.path.join(map_path, f)
            if f not in keep_name_list and os.path.isdir(full_path):
                shutil.rmtree(full_path)

        # 如果不显示全国地图,则删除云动画的图片
        if len(region_list) <= 1:
            cloud1_path = os.path.join(map_path, "yun1.png")
            cloud2_path = os.path.join(map_path, "yun2.png")
            os.remove(cloud1_path)
            os.remove(cloud2_path)
Ejemplo n.º 19
0
    def build_apk_gradle(self, rollback_obj, cfg_dir, apk_cfg_info, apk_name):
        # 最终 apk 文件名格式为:GAMENAME_PKGNAME_APPID_CHANNELID_VERNAME_VERCODE.apk
        # Logging.debug_msg('修改apk文件名 game_name=%s pkg_name=%s app_id=%s channel_id=%s ver_name=%s ver_code=%s' % (game_name, pkg_name, app_id, channel_id, ver_name, ver_code))

        # 修改签名文件
        Logging.debug_msg('修改签名文件')
        keystore_path = utils.flat_path(
            os.path.join(
                cfg_dir,
                apk_cfg_info[PackAPK.CFG_SIGN][PackAPK.CFG_SIGN_FILE]))
        keystore_pass = apk_cfg_info[PackAPK.CFG_SIGN][
            PackAPK.CFG_SIGN_PASSWORD]
        alias = apk_cfg_info[PackAPK.CFG_SIGN][PackAPK.CFG_SIGN_ALIAS]
        alias_pass = apk_cfg_info[PackAPK.CFG_SIGN][
            PackAPK.CFG_SIGN_ALIAS_PASSWORD]
        self._modify_gradle_config(rollback_obj, self.output_path, apk_name,
                                   keystore_path, keystore_pass, alias,
                                   alias_pass)

        gradle_cmd = "cd %s;gradle clean;gradle aR" % self.proj_androidStudio_path
        try:
            utils.run_shell(gradle_cmd)
        except:
            Logging.warn_msg('gradle 命令行打包失败')

        Logging.debug_msg('gradle配置文件修改完成')
Ejemplo n.º 20
0
 def __init__(self, args):
     self.delete = args.do_delete
     cur_dir = os.path.dirname(__file__)
     self.res_root_path = utils.flat_path(os.path.join(
         cur_dir, '../../../'))
     print(self.res_root_path)
     self.check_files = {}
Ejemplo n.º 21
0
    def do_build(self):
        apk_rollback_obj = utils.FileRollback()
        apk_rollback_obj.record_file(
            utils.flat_path(os.path.join(self.proj_parth, 'main.js')))
        # 编译creator工程
        if self.rebuild_creator:
            self.build_creator_proj()
            # 删除和替换资源
            self.op_creator_res()

        # 清理temp目录
        self.temp_dir = os.path.join(self.root_dir, 'temp')
        if os.path.isdir(self.temp_dir):
            shutil.rmtree(self.temp_dir)
        os.makedirs(self.temp_dir)

        # 创建mainfest的结构体
        self.gen_manifest_obj()

        # 更新资源目录
        self.update_resources()

        # 生成zip包
        self.write_zip_file()

        apk_rollback_obj.do_rollback()
        shutil.rmtree(self.temp_dir)

        Logging.debug_msg('热更包打包完成!\n')
        Logging.debug_msg('------------------------------------')
Ejemplo n.º 22
0
def start(path, pf, currentChannel):
    # creator 生成的png映射表
    json_file = utils.flat_path(
        os.path.join(os.path.dirname(__file__), "channel_class.json"))
    print(json_file)
    f = open(json_file)
    jsons = json.load(f)
    f.close()

    f = open(path, 'rU')
    content = f.read()
    f.close()
    for key in jsons:
        curPf = jsons[key]
        idx = curPf.find('_base')
        if idx != -1:
            curPf = curPf.replace('_base', '')
            if curPf != pf:
                content = removeClass(content, key)
        elif curPf != pf:
            content = removeClass(content, key)
        elif currentChannel != key:
            content = removeClass(content, key)

    f = open(path, 'wb')
    f.writelines(content)
    f.close()
Ejemplo n.º 23
0
    def _modify_strings_xml(self, new_name, app_scheme):
        file_path = utils.flat_path(
            os.path.join(self.proj_android_path,
                         'launcher/src/main/res/values/strings.xml'))
        doc_node = minidom.parse(file_path)
        root_node = doc_node.getElementsByTagName('resources')[0]
        string_nodes = root_node.getElementsByTagName('string')
        for node in string_nodes:
            node_name = node.getAttribute('name')
            if node_name == 'app_name':
                node.firstChild.replaceWholeText(new_name.decode('utf-8'))

            if node_name == 'schemename':
                node.firstChild.replaceWholeText(app_scheme.decode('utf-8'))

        new_content = doc_node.toprettyxml(encoding='utf-8')
        # new_content 可能会出现空行,这里进行处理,删除空行
        lines = new_content.split('\n')
        new_lines = []
        for line in lines:
            if line.strip() != '':
                new_lines.append(line)

        f = open(file_path, 'w')
        f.write('\n'.join(new_lines))
        f.close()
Ejemplo n.º 24
0
    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")
Ejemplo n.º 25
0
 def remove_files(self, cfg):
     for item in cfg:
         full_path = utils.flat_path(os.path.join(self.proj_path, item))
         if os.path.isfile(full_path):
             os.remove(full_path)
         elif os.path.isdir(full_path):
             shutil.rmtree(full_path)
Ejemplo n.º 26
0
 def backup_files(self, cfg):
     for item in cfg:
         full_path = utils.flat_path(os.path.join(self.proj_path, item))
         if os.path.isdir(full_path):
             self.file_recorder.record_folder(full_path)
         elif os.path.isfile(full_path):
             self.file_recorder.record_file(full_path)
Ejemplo n.º 27
0
    def __init__(self, args):
        self.batch_cfg_file = utils.flat_path(args.proj_cfg)
        if not os.path.isfile(self.batch_cfg_file):
            raise_known_error("文件 %s 不存在" % self.batch_cfg_file,
                              KnownError.ERROR_PATH_NOT_FOUND)
        self.no_rollback = args.no_rollback
        self.root_dir = os.path.dirname(self.batch_cfg_file)
        cur_time_str = datetime.datetime.fromtimestamp(
            time.time()).strftime('%Y%m%d_%H%M%S')
        self.output_path = os.path.join(self.root_dir, 'output', cur_time_str)
        #配置文件数据
        self.batch_info = self._parse_json(self.batch_cfg_file)
        if not self.batch_info:
            raise_known_error('解析文件 %s 失败' % self.batch_cfg_file,
                              KnownError.ERROR_PARSE_FILE)

        # 检查 android sdk 环境变量
        self.sdk_root = utils.flat_path(
            utils.check_environment_variable('ANDROID_SDK_ROOT'))

        self.build_result = {}
        cur_dir = os.path.dirname(__file__)
        self.proj_parth = utils.flat_path(
            os.path.join(cur_dir, '../../../jsb-default'))
        self.proj_android_path = utils.flat_path(
            os.path.join(self.proj_parth, 'project_android_20'))

        if not os.path.isdir(self.proj_android_path):
            raise_known_error("未找到 Android 工程文件夹 %s" % self.proj_android_path)

        self.android_manifest = os.path.join(
            self.proj_android_path, 'launcher/src/main/AndroidManifest.xml')

        self.java_files = []
        for parent, dirs, files in os.walk(
                utils.flat_path(
                    os.path.join(self.proj_android_path,
                                 'unityLibrary/src/main/java'))):
            for f in files:
                filename, ext = os.path.splitext(f)
                if ext.lower() == '.java':
                    self.java_files.append(os.path.join(parent, f))

        Logging.debug_msg('使用配置文件 : %s' % self.batch_cfg_file)
        Logging.debug_msg('是否禁用还原 : %s' % self.no_rollback)
        Logging.debug_msg('Android 工程路径 : %s' % self.proj_android_path)
        Logging.debug_msg('----------------\n')
Ejemplo n.º 28
0
def start(src, dst):  #遍历当前目录以及递归的子目录,找到所有的js jsc图片
    json_file = utils.flat_path(
        os.path.join(os.path.dirname(__file__), "interlnal.json"))
    ExcludeDirs = {}
    try:
        f = open(json_file)
        ExcludeDirs = json.load(f)
        f.close()
    except:
        pass
    #print(ExcludeDirs)
    for key in (ExcludeDirs):
        print(key)
        f1 = utils.flat_path(os.path.join(src, key))
        f2 = utils.flat_path(os.path.join(dst, key.replace('/', '-')))
        #print(f1, f2)
        moveFileTo(f1, f2)
Ejemplo n.º 29
0
def start(path, pf, currentChannel):
    # creator 生成的png映射表
    json_file = utils.flat_path(
        os.path.join(os.path.dirname(__file__), "channel_class.json"))
    print(json_file)
    f = open(json_file)
    jsons = json.load(f)
    f.close()
Ejemplo n.º 30
0
    def setGradleConfig(self, rollback_obj, cfg_dir, apk_cfg_info, apk_name):
        print("set gradle config")

        gradle_config_path = utils.flat_path(
            os.path.join(self.proj_android_path, 'launcher/config.gradle'))
        cfg_file_path = utils.flat_path(os.path.join(cfg_dir, "package.json"))
        if sys.platform == "win32":
            cfg_file_path = cfg_file_path.replace("\\", "/")

        rollback_obj.record_file(gradle_config_path)
        # 设置 packagePath 路径
        data = []
        f = open(gradle_config_path)
        lines = f.readlines()
        f.close()
        for line in lines:
            if (line.find('def packagePath =') == 0):
                line = 'def packagePath = \"%s\"' % cfg_file_path + '\n'
            data.append(line)
        f = open(gradle_config_path, "w")
        f.writelines(data)
        f.close()

        apk_cfg_info = utils.parse_json(cfg_file_path)
        keystore_path = utils.flat_path(
            os.path.join(
                cfg_dir,
                apk_cfg_info[PackAPK.CFG_SIGN][PackAPK.CFG_SIGN_FILE]))
        if sys.platform == "win32":
            keystore_path = keystore_path.replace("\\", "/")
        apk_cfg_info['sign']['storefile'] = keystore_path
        apk_cfg_info['sign']['output_apk_dir'] = self.output_path
        apk_cfg_info['sign']['output_apk_name'] = apk_name

        # save package.json
        packageFile = open(cfg_file_path, 'w+')
        try:
            str = json.dumps(apk_cfg_info,
                             ensure_ascii=False,
                             indent=4,
                             separators=(',', ':'))
            packageFile.write(str)
        except:
            raise_known_error("write package.json error!")
        finally:
            packageFile.close()