1 Star 0 Fork 6

Jamno/PackageApkTool

forked from 鲁棒性/PackageApkTool 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
UIBuildApkThread.py 5.88 KB
一键复制 编辑 原始数据 按行查看 历史
djv 提交于 2019-08-14 17:06 . 去掉和GUI无关的错误提示,2转3
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import sys
# reload(sys)
# sys.setdefaultencoding('utf8')
import threading
from BuildApkTask import *
from utils.ConfigUtils import *
from ui.JChannelPanelUI import *
# 打包任务线程
class PackageApkThread(threading.Thread):
def __init__(self, window, game_apk_path, channel_file_path,
sign_file_path, keystore, store_pass, alias, key_pass):
threading.Thread.__init__(self)
self.window = window
self.timeToQuit = threading.Event()
# 资源路径
self.game_apk_path = game_apk_path
self.channel_file_path = channel_file_path
# 签名信息
self.sign_file_path = sign_file_path
self.keystore = keystore
self.store_pass = store_pass
self.alias = alias
self.key_pass = key_pass
# 编译参数写入目录
self.setConfig = os.path.join(DIR_WorkSpace, DIR_UIConfig)
self.compile_file_path = ''
def stop(self):
self.timeToQuit.set()
def run(self):
try:
channel_configs = self.window.child_spWindow.GetWindow2().channel_config_text_objects
build_config_str = {}
for config_key, config_value in channel_configs.items():
build_config_str[config_key] = config_value.GetValue()
channel_icons = self.window.child_spWindow.GetWindow2().channel_current_icon_paths
game_icon = channel_icons.get(u'选择图标')
game_subs = channel_icons.get(u'选择角标')
game_splash = channel_icons.get(u'选择闪屏')
if game_icon:
build_config_str[u'game_icon'] = game_icon
if game_subs:
build_config_str[u'game_subs'] = game_subs
if game_splash:
build_config_str[u'game_splash'] = game_splash
if not os.path.exists(os.path.join(self.setConfig)):
os.makedirs(self.setConfig)
self.compile_file_path = os.path.join(self.setConfig, BUILD_COMPILE_PARAMS)
# 如果存在就删除,保证配置文件是最新的配置文件
if os.path.exists(self.compile_file_path):
os.remove(self.compile_file_path)
with open(self.compile_file_path, 'wb') as uiConfig:
uiConfig.write(json.dumps(build_config_str, ensure_ascii=False))
# 打包任务配置
taskId = '180'
gameApkName = os.path.basename(self.game_apk_path)
gameName = os.path.splitext(gameApkName)[0]
gameId = '1'
gameVersion = '1.0.0'
# 截取渠道ID 和 渠道版本
channelFileName = os.path.splitext(os.path.basename(self.channel_file_path))[0]
file_dist = channelFileName.split('_')
channelName = file_dist[0]
channelId = file_dist[1]
channelVersion = file_dist[2]
LogUtils.sharedInstance(taskId).set_ctrl_to_logging(self.window.down_panel.logText)
# 将本地资源拷贝到对应的目录中
Resources = os.path.join(DIR_WorkSpace, DIR_Resources) # 本地模拟服务器资源目录
BaseGameApkPath = os.path.join(Resources, DIR_Game, gameId, gameVersion) # 游戏母包
BaseChannelPath = os.path.join(Resources, DIR_ChannelSDK, channelId, channelVersion) # 渠道资源
BaseSignPath = os.path.join(Resources, DIR_Sign, DIR_local_signId) # 签名资源
BaseConfigPath = os.path.join(Resources, DIR_Config, gameId, channelId, channelVersion) # 打包编译配置文件
# 拷贝游戏资源
if os.path.isdir(BaseGameApkPath):
shutil.rmtree(BaseGameApkPath)
os.makedirs(BaseGameApkPath)
shutil.copy(self.game_apk_path, BaseGameApkPath)
# 解压渠道资源
if os.path.isdir(BaseChannelPath):
shutil.rmtree(BaseChannelPath)
os.makedirs(BaseChannelPath)
unzip_file = zipfile.ZipFile(self.channel_file_path, 'r')
unzip_file.extractall(BaseChannelPath)
unzip_file.close()
# 拷贝签名资源
if os.path.isdir(BaseSignPath):
shutil.rmtree(BaseSignPath)
os.makedirs(BaseSignPath)
shutil.copy(self.sign_file_path, BaseSignPath)
# 拷贝配置文件
if os.path.isdir(BaseConfigPath):
shutil.rmtree(BaseConfigPath)
os.makedirs(BaseConfigPath)
shutil.copy(self.compile_file_path, BaseConfigPath)
# 启动打包任务
task = BuildApkTask(taskId, gameName, gameId, gameVersion, gameApkName, channelName, channelId, channelVersion,
True, '1', self.keystore, self.alias, self.store_pass, self.key_pass)
status, result = task.buildApk()
if status == 0:
free_local_resource(os.path.join(Resources, DIR_Game, gameId), os.path.join(Resources, DIR_ChannelSDK, channelId),
os.path.join(Resources, DIR_Sign, DIR_local_signId), os.path.join(Resources, DIR_Config, gameId))
else:
self.window.show_message(u'打包失败:%s' % result)
# 按钮点击恢复
self.window.down_panel.packageButton.Enable()
except Exception as e:
self.window.down_panel.show_message(u'打包失败:%s' % e)
self.window.down_panel.packageButton.Enable()
# 清除本地工作目录
def free_local_resource(gameRes_path, sdkRes_path, configRes_Path, signRes_Path):
if os.path.isdir(gameRes_path):
shutil.rmtree(gameRes_path)
if os.path.isdir(sdkRes_path):
shutil.rmtree(sdkRes_path)
if os.path.isdir(configRes_Path):
shutil.rmtree(configRes_Path)
if os.path.isdir(signRes_Path):
shutil.rmtree(signRes_Path)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/jamno/PackageApkTool.git
git@gitee.com:jamno/PackageApkTool.git
jamno
PackageApkTool
PackageApkTool
master

搜索帮助