import pathlib,json,subprocess,shutil,sqlite3,datetime,hashlib root=pathlib.Path('/home/ps/huobao-gpu-selection');state=json.loads((root/'state.json').read_text()) stamp=datetime.datetime.now().strftime('%Y%m%d-%H%M%S') assert (root/'routing-normalizers-deployed.json').exists(),'Deploy verified normalizer candidates first' candidate=root/'bridge-gpu.candidate.py';compile(candidate.read_text(),str(candidate),'exec') for folder,name,statefolder in [('/home/ps/huobao-model-bridge','huobao-model-bridge','state'),('/home/ps/huobao-vdn/bridge','huobao-vdn-bridge','../bridge-state')]: p=pathlib.Path(folder);backup=root/(name+'-backup-'+stamp);backup.mkdir(mode=0o700) shutil.copy2(p/'bridge.py',backup/'bridge.py');shutil.copy2(p/'config.json',backup/'config.json') with sqlite3.connect(p/statefolder/'jobs.sqlite3') as src,sqlite3.connect(backup/'jobs.sqlite3') as dest:src.backup(dest) shutil.copy2(candidate,p/'bridge.py');subprocess.run(['docker','restart',name],check=True,stdout=subprocess.DEVNULL) print('Updated Huobao bridge:',name) state['routing_deployed']=stamp;(root/'state.json').write_text(json.dumps(state,indent=2))