修改命令行参数

main
ZhuoZhou 2025-05-08 17:24:37 +08:00
parent 9b6247f5c5
commit 7b696ec4a8
1 changed files with 40 additions and 44 deletions

View File

@ -25,26 +25,17 @@ from optparse import OptionParser
from ipm.wechat_alert import wechat_alert
alert = wechat_alert()
input_old_hash = ''
input_new_hash = ''
modifyLevelStr = ''
if len(sys.argv) > 1:
input_old_hash = sys.argv[1]
if input_old_hash == 'none' or input_old_hash == '_':
input_old_hash = ''
if len(sys.argv) > 2:
input_new_hash = sys.argv[2]
if input_new_hash == 'none' or input_new_hash == '_':
input_new_hash = ''
if len(sys.argv) > 3:
modifyLevelStr = sys.argv[3]
# input_old_hash = ''
# input_new_hash = ''
# if len(sys.argv) > 1:
# input_old_hash = sys.argv[1]
# if input_old_hash == 'none' or input_old_hash == '_':
# input_old_hash = ''
# if len(sys.argv) > 2:
# input_new_hash = sys.argv[2]
# if input_new_hash == 'none' or input_new_hash == '_':
# input_new_hash = ''
env = config.machine_env_config.Local_Path.value
workspace_path = env['workspace_path']
unity_install_path = env['unity_install_path']
art_proj_path = config.getArtProjPath(env)
asset_build_proj_path = config.getAssetsBuildProjPath(env)
unity_proj_path = config.getUnityProjPath(env)
# 主机IP
IP = ""
@ -67,35 +58,33 @@ def check_dir(path):
if not os.path.exists(path):
os.makedirs(path)
git_commit_hash_file = os.path.join(workspace_path, 'find_object_git_commit_hash.txt')
git_hash_change_record_file = os.path.join(workspace_path, 'find_object_git_hash_change_record.txt')
def isGitCommitFileExist():
return os.path.exists(git_commit_hash_file)
return os.path.exists(opts.git_commit_hash_file)
def writeGitCommitLog(git_log_hash):
# 写入git_commit.txt文件
with open(git_commit_hash_file, 'w') as f:
with open(opts.git_commit_hash_file, 'w') as f:
f.write(git_log_hash)
def recordNewGitHash(git_log_hash):
# 文件末尾新增一行记录新的git hash
with open(git_hash_change_record_file, 'a') as f:
with open(opts.git_hash_change_record_file, 'a') as f:
f.write(git_log_hash + '\n')
def isRecordGitHashFileExist():
return os.path.exists(git_hash_change_record_file)
return os.path.exists(opts.git_hash_change_record_file)
def getCurrentGitHash():
current_commit_hash = ''
if isGitCommitFileExist():
with open(git_commit_hash_file, 'r') as f:
with open(opts.git_commit_hash_file, 'r') as f:
current_commit_hash = f.read()
print(f"current hash:{current_commit_hash}")
return current_commit_hash
def getNewGitHash():
sh1 = f"cd {art_proj_path}"
sh1 = f"cd {opts.assets}"
sh2 = f"git log -1 --pretty=format:\"%H\""
f = os.popen(f"{sh1} && {sh2}")
new_commit_hash = f.read()
@ -106,9 +95,9 @@ def getNewGitHash():
def getModifyPic(git_dir):
pass
if input_old_hash != '' and input_new_hash != '':
current_commit_hash = input_old_hash
new_commit_hash = input_new_hash
if opts.old_hash != '' and opts.new_hash != '':
current_commit_hash = opts.old_hash
new_commit_hash = opts.new_hash
else:
current_commit_hash = getCurrentGitHash()
new_commit_hash = getNewGitHash()
@ -158,14 +147,11 @@ def getModifyIdList(modify_content_lines):
def generateLevelIdListByGitLog():
pass
global _levelModifiedIdList_
modify_content_lines = getModifyPic(art_proj_path)
modify_content_lines = getModifyPic(opts.assets)
_levelModifiedIdList_ = getModifyIdList(modify_content_lines)
if len(modifyLevelStr) > 0:
manual_modify_level_list = modifyLevelStr.split('#')
if len(opts.special) > 0 and opts.special != '0':
manual_modify_level_list = opts.special.split(',')
for level_id in manual_modify_level_list:
# asset_file = os.path.join(art_proj_path, 'LevelPackages', f'{level_id}.unitypackage')
# if not os.path.exists(asset_file):
# config.notification_helper.append_msg(f'{level_id}资源文件不存在,无法打包')
if level_id not in _levelModifiedIdList_:
_levelModifiedIdList_.append(level_id)
@ -252,6 +238,9 @@ if __name__ == '__main__':
# parser.add_option("-l", "--log", dest="log", help=('美术资源最新的git log'))
# parser.add_option("-d", "--upload", dest="upload", help=('是否上传'))
parser.add_option("-s", "--special", dest="special", help=('指定构建的资源'))
parser.add_option("-n", "--new-hash", dest="new_hash", help=('最新的hash'))
parser.add_option("-o", "--old-hash", dest="old_hash", help=('老的hash'))
(opts, args) = parser.parse_args()
opts.appversion = "1.0.0"
opts.resversion = "1"
@ -261,7 +250,14 @@ if __name__ == '__main__':
opts.log = "log/build.log"
opts.assets = "/Volumes/Predator/find-object/find-object-art"
opts.resources = "/Volumes/Predator/find-it/find-object-bundle-resource"
opts.workspace_path = config.machine_env_config.CD_MAC_STUDIO.value['workspace_path']
opts.git_commit_hash_file = os.path.join(opts.workspace_path, 'find_object_git_commit_hash.txt')
opts.git_hash_change_record_file = os.path.join(opts.workspace_path, 'find_object_git_hash_change_record.txt')
if opts.new_hash is None or opts.new_hash == 'none' or opts.new_hash == '_':
opts.new_hash = ''
if opts.old_hash is None or opts.old_hash == 'none' or opts.old_hash == '_':
opts.old_hash = ''
# 本地自测适用
# opts.aab = "false"
# opts.mode = "Debug"
@ -323,9 +319,9 @@ if __name__ == '__main__':
# region 检索需要需要打包的关卡
modify_files = []
if opts.special != "0":
modify_files = opts.special.split(",")
else:
# if opts.special != "0":
# modify_files = opts.special.split(",")
# else:
# 获取最近6小时内的提交记录用于解析psd
# platform = "android" if opts.platform == "Android" else "ios"
# with open(os.path.join(opts.assets, f"git_{platform}_commit_change_files.txt"), "r") as f:
@ -340,11 +336,11 @@ if __name__ == '__main__':
# modify_files.append(asset_id)
#获取git 提交来得到修改的关卡
generateLevelIdListByGitLog()
if len(_levelModifiedIdList_) <= 0:
config.notification_helper.append_msg('没有需要构建的资源')
else:
modify_files = _levelModifiedIdList_
generateLevelIdListByGitLog()
if len(_levelModifiedIdList_) <= 0:
config.notification_helper.append_msg('没有需要构建的资源')
else:
modify_files = _levelModifiedIdList_
print(f"modify_files = {modify_files}")
# alert.alert(f"构建资源列表:{str(modify_files)}")
tmstp1 = time.time()