import os,socket,subprocess,time,json,pathlib root=pathlib.Path('C:/laragon/www/sgf-tempo');os.chdir(root) php='C:/Users/macbook/.config/investmoz/php-8.5.11/php.exe';node='C:/laragon/tools/sgf-tempo/node-v24.22.1-win-arm64/node.exe';processes=[];created=False for port in [8007,8008]: s=socket.socket();s.settimeout(.3);busy=s.connect_ex(('127.0.0.1',port))==0;s.close() if busy:raise RuntimeError('Proof port occupied; no process stopped') try: subprocess.run([php,'scripts/payables-provision.php','--proof'],check=True);created=True for mode,port in [('compras',8007),('sgf',8008)]: settings=pathlib.Path(f'C:/laragon/data/sgf-tempo/secrets/payables-proof-{mode}.json');config=json.loads(settings.read_text(encoding='utf-8-sig'));env=dict(os.environ);env['PAYABLE_SETTINGS_FILE']=str(settings).replace('\\','/') executable=php if mode=='compras' else 'C:/laragon/tools/sgf-tempo/php-8.4.27/php.exe' p=subprocess.Popen([executable,'-S',f'127.0.0.1:{port}','-t','public',str(root/'scripts/payables-router.php')],cwd=config['HOST_ROOT'],env=env,stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL,creationflags=subprocess.CREATE_NO_WINDOW);processes.append(p) for attempt in range(60): s=socket.socket();s.settimeout(.2);ready=s.connect_ex(('127.0.0.1',port))==0;s.close() if ready:break time.sleep(.1) if not ready:raise RuntimeError('Disposable HTTP host failed') subprocess.run([php,'scripts/settlements-install.php',mode,'proof'],check=True) subprocess.run([node,'scripts/settlements-interface-check.mjs'],check=True) finally: for p in processes: if p.poll() is None:p.terminate();p.wait(timeout=15) if created:subprocess.run([php,'scripts/payables-provision.php','--cleanup-proof'],check=True)