def _updater_package_action(paths, project_path, package_dir, package_name, main_version, is_need_restart, is_need_back_update, action=['check', 'pack']): # 需要打包目录 """生成新包""" command = ['python', RESOURCES_PACKER_PATH, '-paths'] if isinstance(paths, list): for path in paths: command.append(path) else: command.append(paths) command = command + [ '-project-path', project_path, '-package-name', package_name, '-artifact-dir', package_dir, '-main-version', main_version, '-action', action, '-ignores-ext', '.meta', '.svn', '.git',] need_restart = "-need-restart" need_back = "-need-back" # 是否需要重启 if is_need_restart == "True": command.append(need_restart) if is_need_back_update == "True": command.append(need_back) print "run command = {}".format(command) common.run_command(command)
def svn_cleanup(local_path): """ svn cleanup :param local_path: :return: """ cmd = ['svn', 'cleanup', local_path] common.run_command(cmd)
def svn_commit(local_path, message): if type(local_path) == str: paths = [local_path] else: paths = local_path cmd = ['svn', 'commit'] + paths + ['-m', message] common.run_command(cmd)
def set_file_permission(file_path): """ 设置文件权限 :param file_path: :return: """ cmd = ['chmod', '755', file_path] common.run_command(cmd)
def svn_add(local_path): """ svn add :param local_path: :return: """ os.chdir(local_path) cmd = ['svn', 'add', local_path, '--force'] common.run_command(cmd)
def git_clone(git_url, local_path): """ git clone :param git_url: :param local_path: :return: """ cmd = ['git', 'clone', git_url, local_path] common.run_command(cmd)
def svn_checkout(svn_url, local_path): """ svn checkout :param svn_url: :param local_path: :return: """ cmd = ['svn', 'co', svn_url, local_path] common.run_command(cmd)
def git_switch(local_path, branch_name): """ git switch :param local_path: :param branch_name: :return: """ os.chdir(local_path) cmd = ['git', 'checkout', branch_name] common.run_command(cmd)
def BuildAndroidPrj(): gradle_dir = os.path.join( workspace.unity_project_path, 'AndroidPrj/Version_{}/{}'.format(LANGUAGE, PRODUCT_NAME)) os.chdir(gradle_dir) # 删除Build目录 build_dir = os.path.join(gradle_dir, 'build') if os.path.isdir(build_dir): shutil.rmtree(build_dir, ignore_errors=True) if VERSION_TYPE == 'Alpha': compile_parm = 'assembleDebug' dir_name = 'debug' elif VERSION_TYPE == 'Preview' or VERSION_TYPE == 'Release': compile_parm = 'assembleRelease' dir_name = 'release' else: compile_parm = None exit(1) if common.is_windows(): cmd = ['gradlew', compile_parm] os.system(' '.join(cmd)) else: chmod = ['chmod', '755', 'gradlew'] common.run_command(chmod) cmd = ['./gradlew', compile_parm] common.run_command(cmd) apk_src_path = os.path.join( build_dir, 'outputs/apk/{}/{}-{}.apk'.format(dir_name, PRODUCT_NAME, dir_name)) # 检测Apk是否Build成功 if not os.path.isfile(apk_src_path): log_tool.show_error( "Build Android Apk Failed! Can't Find the file: {}".format( apk_src_path)) exit(1) # Apk改名 build_date = time.strftime("%Y.%m.%d.%H.%M.%S", time.localtime()) apk_dst_path = os.path.join( build_dir, 'outputs/apk/{}/{}_{}_{}.{}.{}.{}_{}_{}.apk'.format( dir_name, PRODUCT_NAME, BRANCH_NAME, MAJOR_NUMBER, MINOR_NUMBER, PATCH_NUMBER, BUILD_NUMBER, VERSION_TYPE, build_date)) os.rename(apk_src_path, apk_dst_path) # 拷贝到Apk目录去 apk_dir = GetApkDir() shutil.copy(apk_dst_path, apk_dir)
def git_up(local_path, version_number=None): """ git up :param local_path: :param version_number: :return: """ os.chdir(local_path) if version_number: cmd = ['git', 'reset', '--hard', version_number] common.run_command(cmd) else: cmd = ['git', 'pull'] common.run_command(cmd)
def svn_switch(svn_url, local_path, revision=None): """ svn switch :param svn_url: :param local_path: :param revision: :return: """ cmd = ['svn', 'switch', svn_url, local_path, '--accept', 'theirs-full', '--force'] if revision: cmd.append('-r') cmd.append(revision) common.run_command(cmd)
def git_delete(local_path, remove_list): """ git delete :param local_path: :param remove_list: :return: """ os.chdir(local_path) if type(remove_list) == str: removelist = [remove_list] else: removelist = remove_list cmd = ['git', 'rm', '-r'] + removelist common.run_command(cmd)
def git_add(local_path, add_list): """ git add :param local_path: :param add_list: :return: """ os.chdir(local_path) if type(add_list) == str: addlist = [add_list] else: addlist = add_list cmd = ['git', 'add'] + addlist common.run_command(cmd)
def git_commit(local_path, message): """ git commit :param local_path: :param message: :return: """ os.chdir(local_path) # 先Commit cmd = ['git', 'commit', '--allow-empty', '-m', message] common.run_command(cmd) # 再Push cmd = ['git', 'push'] common.run_command(cmd)
def git_revert(local_path, revert_list): """ git revert :param local_path: :param revert_list: :return: """ os.chdir(local_path) if type(revert_list) == str: revertlist = [revert_list] else: revertlist = revert_list cmd = ['git', 'reset', 'HEAD'] + revertlist common.run_command(cmd) cmd = ['git', 'checkout'] + revertlist common.run_command(cmd)
def BuildIosPrj(): scheme = 'Unity-iPhone' info_plist_path = 'Info.plist' package_name = 'Unity-iPhone.ipa' if (VERSION_TYPE == 'Alpha'): configuration = 'Debug' else: configuration = 'Release' # 切换到工程目录 os.chdir(IOS_PRJ_DIR) # Archive archive_cmd = [ XCODE_BUILD_PATH, '-archivePath', 'Unity-iPhone', '-project', 'Unity-iPhone.xcodeproj', '-configuration', configuration, '-scheme', scheme, 'archive', '-verbose', 'CODE_SIGN_IDENTITY={}'.format(code_sign_identity), 'PROVISIONING_PROFILE_SPECIFIER={}'.format(provisioning_profile_specifier), '-sdk', 'iphoneos' ] common.run_command(archive_cmd) # Export export_cmd = [ XCODE_BUILD_PATH, '-exportArchive', '-archivePath', 'Unity-iPhone.xcarchive', '-exportPath', 'Unity-iPhone-resigned-dist', '-exportOptionsPlist', info_plist_path ] common.run_command(export_cmd) # Copy ipa build_date = time.strftime("%Y.%m.%d.%H.%M.%S", time.localtime()) ipa_dir = GetIpaDir() source_ipa_path = os.path.join(IOS_PRJ_DIR, os.path.join('Unity-iPhone-resigned-dist', package_name)) target_ipa_path = os.path.join(ipa_dir, '{}_{}_{}.{}.{}.{}_{}_{}.ipa'.format( PRODUCT_NAME, BRANCH_NAME, MAJOR_NUMBER, MINOR_NUMBER, PATCH_NUMBER, BUILD_NUMBER, VERSION_TYPE, build_date)) shutil.copyfile(source_ipa_path, target_ipa_path) log_tool.show_info('Build Ios Ipa is done!')
def svn_up(local_path, version_number=None): """ svn up :param local_path: :param version_number: :return: """ if type(local_path) == str: paths = [local_path] else: paths = local_path if version_number: cmd = ['svn', 'up', '-r', version_number] + paths else: cmd = ['svn', 'up'] + paths common.run_command(cmd)
def svn_revert(local_path): """ svn revert :param local_path: :return: """ cmd = ['svn', 'revert', local_path, '--depth', 'infinity'] result = common.run_command(cmd) log_tool.show_info("The local path is {}.Revert status: {}".format(local_path, result))
def git_cleanup(local_path): """ git cleanup :param local_path: :return: """ os.chdir(local_path) cmd = ['git', 'add', '.'] common.run_command(cmd) cmd = ['git', 'stash', 'save', 'remove'] common.run_command(cmd) cmd = ['git', 'stash', 'clear'] common.run_command(cmd)
def Pack(package_setting, is_packbase): # FilePacker path if common.is_windows(): filepackerpath = os.path.join(workspace.unity_project_path, 'FilePacker.exe') else: filepackerpath = os.path.join(workspace.unity_project_path, 'FilePacker') # 获取执行权限 os.chdir(workspace.unity_project_path) chmod = ['chmod', '755', 'FilePacker'] common.run_command(chmod) UPDATER_PACK_PATH = os.path.join(CURRENT_PATH, 'updater_pack.py') UPDATER_CMD = ['python', UPDATER_PACK_PATH, BRANCH_NAME, VERSION_NUMBER, MAIN_VERSION, PLATFORM, workspace.unity_project_path, PROJECT_NAME, package_setting.package_dir_name, '{}'.format(is_packbase), IS_REBOOT, IS_BACKGROUND_UPDATE] # 生成Patch包 for pack_dir in package_setting.pack_dirs: pack_idx_path = os.path.join(workspace.unity_project_path, 'Assets/StreamingAssets/Res/{}/pack.idx'.format(pack_dir)) pack_dat_path = os.path.join(workspace.unity_project_path, 'Assets/StreamingAssets/Res/{}/pack0.dat'.format(pack_dir)) if not os.path.isfile(pack_idx_path) or not os.path.isfile(pack_dat_path): log_tool.show_error("Can't find {} and {}".format(pack_idx_path, pack_dat_path)) exit(1) if not is_packbase: pack_settings = workspace.get_pack_setting() if not pack_settings: log_tool.show_error("GetPackSetting Failed") exit(1) if not pack_settings.has_key(pack_dir): log_tool.show_error('{} not in PackSetting'.format(pack_dir)) exit(1) patch_srcfile_path = os.path.join(workspace.unity_project_path, 'Assets/StreamingAssets/Res/{}/pack.patch'.format(pack_dir)) patch_path = os.path.join(workspace.unity_project_path, 'Patch/{}'.format(pack_dir)) patch_idx_path = os.path.join(patch_path, 'pack.idx') patch_dstfile_path = os.path.join(patch_path, 'pack.patch') if os.path.isdir(patch_path): shutil.rmtree(patch_path) os.makedirs(patch_path) # 修改pack配置文件 pack_ini_file = os.path.join(workspace.unity_project_path, 'FilePacker.ini') pack_setting = pack_settings[pack_dir] # outdir config_content = '[FilePacker]\n' config_content = '{}DstPath=Assets/StreamingAssets/Res/{}\n'.format(config_content, pack_dir) # folders folder_index = 1 for folder in pack_setting.folders: config_content = '{}Folder{}={}\n'.format(config_content, folder_index, folder) folder_index = folder_index + 1 # files file_index = 1 for file in pack_setting.files: config_content = '{}File{}={}\n'.format(config_content, file_index, file) file_index = file_index + 1 file = open(pack_ini_file, 'w') file.write(config_content) file.close() log_tool.show_info('Run FilePacker --patch') common.run_command([filepackerpath, '--patch']) log_tool.show_info('Run FilePacker --patch is done!') if os.path.isfile(pack_idx_path) and os.path.isfile(patch_srcfile_path): log_tool.show_info('Copy {} --> {}'.format(pack_idx_path, patch_idx_path)) shutil.copyfile(pack_idx_path, patch_idx_path) log_tool.show_info('Copy {} --> {}'.format(patch_srcfile_path, patch_dstfile_path)) shutil.copyfile(patch_srcfile_path, patch_dstfile_path) else: log_tool.show_info("Can't find {}! No Change!".format(patch_srcfile_path)) # 生成热更包 log_tool.show_info("========== Run updater_pack.py ==========") common.run_command(UPDATER_CMD)
def ProduceUploadPackage(pack_dir): temp_dir = _GetTempDir() if os.path.isdir(temp_dir): shutil.rmtree(temp_dir) hot_package_dir = _GetHotPackageDir() hot_package_dir = os.path.join(hot_package_dir, pack_dir) if not os.path.isdir(hot_package_dir): log_tool.show_error('HotPackageDir {} not Exist!'.format(hot_package_dir)) return upload_package_list = Queue.Queue() # 拷贝resource_version resource_version_path = os.path.join(hot_package_dir, '{}.{}.resource_version.txt'.format(PACKAGE_NAME_PREFIX, MAIN_VERSION)) upload_package_list.put(resource_version_path) global UPDATE_VERSION_NUMBER if UPDATE_VERSION_NUMBER == -1: UPDATE_VERSION_NUMBER = _GetLastVersionNumber(resource_version_path) for i in range(0, UPDATE_VERSION_NUMBER): if i == 0 or UPDATE_VERSION_NUMBER - i <= MAX_VERSION_SPAN: zipfile_name = '{}.{}.{}-{}.zip'.format(PACKAGE_NAME_PREFIX, MAIN_VERSION, i, UPDATE_VERSION_NUMBER) zipfile_path = os.path.join(hot_package_dir, zipfile_name) zipfile_md5_path = '{}.md5'.format(zipfile_path) zipfile_info_path = '{}.info'.format(zipfile_path) upload_package_list.put(zipfile_path) upload_package_list.put(zipfile_md5_path) upload_package_list.put(zipfile_info_path) temp_dir = _GetTempDir() branch_name = BRANCH_NAME if '/' not in BRANCH_NAME else BRANCH_NAME.replace('/', '_') copy_dir = os.path.join(temp_dir, '{}/{}/{}/{}'.format(branch_name, MAIN_VERSION, PLATFORM, pack_dir)) if not os.path.isdir(copy_dir): os.makedirs(copy_dir) while not upload_package_list.empty(): source_file_path = upload_package_list.get() target_file_path = os.path.join(copy_dir, os.path.basename(source_file_path)) if os.path.isfile(source_file_path): log_tool.show_info('=================== Copy {} to {} ======================'.format(source_file_path, target_file_path)) shutil.copyfile(source_file_path, target_file_path) else: log_tool.show_error("Can't find the file {}".format(source_file_path)) return # zip file os.chdir(temp_dir) upload_package_zipfile = '{}.{}.{}-{}.zip'.format(PACKAGE_NAME_PREFIX, PLATFORM, MAIN_VERSION, UPDATE_VERSION_NUMBER) zip_cmd = ['zip', '-r', upload_package_zipfile, branch_name] common.run_command(zip_cmd) # 拷贝到热更包目录 upload_dir = _GetUploadDir() upload_dir = os.path.join(upload_dir, pack_dir) if not os.path.isdir(upload_dir): os.makedirs(upload_dir) target_file_path = os.path.join(upload_dir, os.path.basename(upload_package_zipfile)) shutil.copyfile(upload_package_zipfile, target_file_path) # 删除临时目录 shutil.rmtree(temp_dir) log_tool.show_info('auto_build_upload_hotpackage Done!')
def svn_delete(delete_path): cmd = ['svn', 'delete', delete_path] common.run_command(cmd)
def svn_version(): cmd = ['svn', '--version'] common.run_command(cmd)
def BuildPack(): # 先更新到最新 if LOCAL_OP is False: UpdateProduct() # 生成所有脚本路径的配置表 # 现在不需要生成,可以通过加载目录的方式 #CreateAllLuaFilePath() sleep(1) # 获取所有需要Pack的目录 pack_settings = workspace.get_pack_setting() if not pack_settings: exit(1) # FilePacker path if common.is_windows(): filepackercpath = os.path.join(workspace.unity_project_path, 'FilePacker.exe') elif common.is_macos(): filepackercpath = os.path.join(workspace.unity_project_path, 'FilePacker') # 获取执行权限 os.chdir(workspace.unity_project_path) chmod = ['chmod', '755', 'FilePacker'] common.run_command(chmod) if not os.path.isfile(filepackercpath): log_tool.show_error("Can't find the FilePacker.exe: {}".format(filepackercpath)) exit(1) # 需要打包的目录 pack_dirs = [] if not PACK_DIRS or PACK_DIRS == '': for setting in pack_settings.values(): pack_dirs.append(setting.pack_dir_name) else: dirs = PACK_DIRS.split(',') for dir_name in dirs: pack_dirs.append(dir_name.strip()) # 删除需要打包的目录 root_dir = os.path.join(workspace.unity_project_path, 'Assets/StreamingAssets/Res') for pack_dir in pack_dirs: pack_forlder = os.path.join(root_dir, pack_dir) if os.path.isdir(pack_forlder): shutil.rmtree(pack_forlder) # 生成Pack文件 pack_ini_file = os.path.join(workspace.unity_project_path, 'FilePacker.ini') for pack_dir in pack_dirs: # 修改pack配置文件 if not pack_settings.has_key(pack_dir): log_tool.show_error('{} not in PackSetting'.format(pack_dir)) exit(1) pack_setting = pack_settings[pack_dir] # outdir config_content = '[FilePacker]\n' config_content = '{}DstPath=Assets/StreamingAssets/Res/{}\n'.format(config_content, pack_dir) # folders folder_index = 1 for folder in pack_setting.folders: config_content = '{}Folder{}={}\n'.format(config_content, folder_index, folder) folder_index = folder_index + 1 # files file_index = 1 for file in pack_setting.files: config_content = '{}File{}={}\n'.format(config_content, file_index, file) file_index = file_index + 1 file = open(pack_ini_file, 'w') file.write(config_content) file.close() # 生成Pack目录 dir_path = os.path.join(workspace.unity_project_path, 'Assets/StreamingAssets/Res/{}'.format(pack_dir)) if not os.path.isdir(dir_path): os.makedirs(dir_path) common.run_command(filepackercpath) # 打开一下Unity,自动生成一下pack的meta文件 if LOCAL_OP is False: log_tool.show_info('Wait For Generator MetaFiles') build_function = 'KGame.KAutoBuilderPack.GenerMetaFiles' log_path = os.path.join(workspace.unity_project_path, 'generator_pack_metafiles_log.txt') unity_tool.build(build_function, UNITY_PATH, workspace.unity_project_path, log_path) log_tool.show_info('Generator MetaFiles Finished')