22 lines
3.0 KiB
Python
22 lines
3.0 KiB
Python
from pathlib import Path
|
|
import shutil,subprocess,json,hashlib
|
|
out=Path(__file__).resolve().parent;root=out.parents[1];private=Path('C:/Users/macbook/.config/investmoz/navegacao-consolidacao-QA-20261016');source=private/'source';original=Path('C:/Users/macbook/.config/investmoz/navegacao-QA-20261016/source');assert not private.exists()
|
|
sha=lambda p:hashlib.sha256(p.read_bytes()).hexdigest()
|
|
(out/'ATIVO-ANTES.json').write_text(json.dumps({'files':{p.relative_to(root).as_posix():sha(p)for f in ['app','config','routes','database','resources','public/build']for p in(root/f).rglob('*')if p.is_file()},'protected':{n:sha(root/n)for n in ['.env','composer.lock','package-lock.json']}},indent=2),'utf-8')
|
|
private.mkdir(parents=True)
|
|
pg=Path('C:/Program Files/PostgreSQL/17/bin');db='navigation_consolidation_20261016_test';assert db.endswith('_test')
|
|
subprocess.run([str(pg/'pg_dump.exe'),'-h','127.0.0.1','-p','55441','-U','postgres','-Fc','--no-owner','--no-acl','-f',str(private/'baseline-QA.dump'),'navigation_20261016_test'],check=True,capture_output=True)
|
|
subprocess.run([str(pg/'createdb.exe'),'-h','127.0.0.1','-p','55441','-U','postgres',db],check=True,capture_output=True)
|
|
subprocess.run([str(pg/'pg_restore.exe'),'-h','127.0.0.1','-p','55441','-U','postgres','--no-owner','--no-acl','-d',db,str(private/'baseline-QA.dump')],check=True,capture_output=True)
|
|
shutil.copytree(original,source,ignore=shutil.ignore_patterns('vendor','node_modules','storage','.git','cache'))
|
|
for name in ['vendor','node_modules']:subprocess.run(['cmd.exe','/d','/c','mklink','/J',str(source/name),str(root/name)],check=True,capture_output=True)
|
|
for name in ['bootstrap/cache','storage/app/private','storage/app/public','storage/framework/cache/data','storage/framework/views','storage/framework/sessions','storage/logs']:(source/name).mkdir(parents=True,exist_ok=True)
|
|
shutil.copytree(original/'storage/app/private',source/'storage/app/private',dirs_exist_ok=True)
|
|
env=(source/'.env').read_text('utf-8').replace('navigation_20261016_test',db).replace('18534','18536').replace('navigation_qa','navigation_consolidation_qa');(source/'.env').write_text(env,'utf-8')
|
|
previous=root/'outputs/investmoz-navegacao-QA-20261016'
|
|
for name in ['boot-QA.php','router-QA.php','http_common.py']:
|
|
text=(previous/name).read_text('utf-8').replace('navegacao-QA-20261016','navegacao-consolidacao-QA-20261016').replace('navigation_20261016_test',db).replace('18534','18536');(out/name).write_text(text,'utf-8')
|
|
fixture=json.loads((original.parent/'fixture-private.json').read_text('utf-8'));fixture.update(database=db,url='http://127.0.0.1:18536');(private/'fixture-private.json').write_text(json.dumps(fixture),'utf-8')
|
|
(out/'ISOLAMENTO.json').write_text(json.dumps({'source':str(source),'database':db,'port':55441,'url':'http://127.0.0.1:18536','base_candidate':'navegacao-prototipo-QA-9c26084141c2','previous_acceptances_reused':True,'pending_parks_L1_included':False,'active_changes_authorized':False},indent=2),'utf-8')
|
|
print(json.dumps({'prepared':True,'database':db,'source':str(source),'active_unchanged':True}))
|