import os import sys import subprocess import hvac if len(sys.argv) < 3: exit() if '123!@#' != sys.argv[2]: exit() ProjDir = sys.argv[1] BuildDir = ProjDir + '\\build\\web-mobile\\' SubgamePath = 's3://web-h5game-prod/internal/' # Vault 地址和 Token VAULT_ADDR = 'https://keys.wehavefun.email' VAULT_TOKEN = 'hvs.CAESIJNR6tvdIBSvRuI8r_O_82yjqu6eztxKQtk2oEGmOrFSGh4KHGh2cy5KSmlmS2xIbHprcDUwOUlIOVJ3TzdjUWQ' # 创建客户端 client = hvac.Client(url=VAULT_ADDR, token=VAULT_TOKEN) if client.is_authenticated(): secret = client.secrets.kv.v2.read_secret_version( path='default', mount_point='aws', raise_on_deleted_version=True ) SwitchBundle = secret['data']['data']['switchBundle'] if "1" != SwitchBundle: print("script exit, switchBundle status is " + SwitchBundle) exit() else: print("running script failed!") exit() print("start running script...") BundleConfig = { '6001': 'whot', '6002': 'whot', '6003': 'whot', '6005': 'BRWhot', '2001': 'roulette', '2002': 'wajeSpin', '2003': 'bottleSpin', '2004': 'blackjack', '2006': 'betterjack', '6007': 'BRWhot', '2008': 'slots', '2005': 'christmas', } unlinkArray = [ 'cocos2d-js.109f3.js', 'cocos2d-js-min.13181.js', 'physics.9d2de.js', 'physics-min.ce5ee.js', 'style-desktop.dfd76.css', 'style-mobile.6e9cd.css', 'splash.85cfd.png' ] def remove_folder(path): print('remove path: ', path) if os.path.exists(path): if os.path.isfile(path) or os.path.islink(path): os.remove(path) else: for filename in os.listdir(path): remove_folder(os.path.join(path, filename)) os.rmdir(path) SrcDir = BuildDir + '\\src\\' SrcDst = SubgamePath + 'lib/src/' rmResult = subprocess.run(['cmd', '/c', 'aws s3 rm ' + SrcDst + ' --recursive'], capture_output=True, text=True) print('remove dir src result: ', rmResult) cmd = 'call aws s3 cp '+ SrcDir +' '+SrcDst + ' --recursive --region eu-west-3' result = subprocess.run(['cmd', '/c', cmd], capture_output=True, text=True) print('upload dir src result: ', result) remove_folder(SrcDir) for filename in os.listdir(BuildDir): file_path = os.path.join(BuildDir, filename) if filename in unlinkArray: os.remove(file_path) for gameid in BundleConfig: awsPath = SubgamePath + gameid + '/assets/' + BundleConfig[gameid] +'/' rmResult = subprocess.run(['cmd', '/c', 'aws s3 rm ' + awsPath + ' --recursive'], capture_output=True, text=True) print('remove game gameid: ', gameid, ' result: ', rmResult) subgameDir = BuildDir + 'assets\\' + BundleConfig[gameid] +'\\' cmd = 'call aws s3 cp '+ subgameDir +' '+awsPath + ' --recursive --region eu-west-3' result = subprocess.run(['cmd', '/c', cmd], capture_output=True, text=True) print(result) for gameid in BundleConfig: awsPath = SubgamePath + gameid + '/assets/' + BundleConfig[gameid] +'/' subgameDir = BuildDir + 'assets\\' + BundleConfig[gameid] remove_folder(subgameDir) for gameid in BundleConfig: awsPath = SubgamePath + gameid + '/' cmd = 'call aws s3 cp '+ BuildDir +' '+awsPath + ' --recursive --region eu-west-3' result = subprocess.run(['cmd', '/c', cmd], capture_output=True, text=True) print('upload game gameid: ', gameid, ' result: ', result)