Files
Investidor-V2/outputs/investmoz-referencias-economicas-QA-20261016/make-manifest.py
T
nala 2d23157e40
tests / ci (push) Canceled after 0s
versao nrgocios
2026-10-16 13:06:58 +02:00

26 lines
5.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from pathlib import Path
import json,hashlib,uuid,shutil
root=Path(__file__).resolve().parents[2];out=Path(__file__).resolve().parent
q=json.loads((out/'QA-ISOLAMENTO.json').read_text('utf-8'));source=Path(q['source']);private=Path(q['private'])
plan=root/'outputs/investmoz-referencias-economicas-mapa-20261016'
lot=json.loads((plan/'DOC01/LOTE-PROPOSTO.json').read_text('utf-8'));refs=json.loads((plan/'ESTADO-QA-READONLY.json').read_text('utf-8'))['targets']['restored_destination']['tables']
sha=lambda p:hashlib.sha256(p.read_bytes()).hexdigest()
ident=lambda k:str(uuid.uuid5(uuid.NAMESPACE_URL,'investmoz:economic-reference:lot-01:20261016:'+k))
files=[];extraction=json.loads((plan/'FONTES-EXTRAIDAS.json').read_text('utf-8'))['selection']
names=['CAE eBAU.xlsx','upgrade do portal de investimentos v6 programacao.docx','agronegócio 1.docx','Corredores de Desenvolvimento do Agronegócio em Moçambique.docx']
for name in names:
item=next(x for x in extraction if Path(x['path']).name==name);p=Path(item['path']);assert sha(p)==item['sha256']
relative='sources/'+item['sha256']+p.suffix.lower();dest=source/'storage/app/private/investmoz-v2/economic-references/lot-01'/relative;dest.parent.mkdir(parents=True,exist_ok=True);shutil.copy2(p,dest)
files.append({'name':name,'relative_path':relative,'sha256':item['sha256'],'bytes':p.stat().st_size,'publication':'private retained source; no library publication','source_version':'retained exemplar '+item['sha256'][:12]})
sector=next(x for x in refs['sectors']['rows'] if x['id']==1);cluster=next(x for x in refs['economic_clusters']['rows'] if x['code']=='CLU-01')
meta={k:{f:r.get(f) for f in ['id','slug','code','source_system','external_id','name']} for k,r in [('sector',sector),('cluster',cluster)]}
catalog=ident('catalog');activities=[]
for r in lot['activities']:
activities.append({'id':ident('activity:'+r['code']),'catalog_version_id':catalog,'parent_id':ident('activity:'+next(x['code'] for x in lot['activities'] if x['source_id']==r['parent_source_id'])) if r['parent_source_id'] else None,'sector_id':None if r['level']=='1' else 1,'code':r['code'],'label_pt_mz':r['label'],'description_pt_mz':'Recorte do exemplar eBAU, sem certificação de conformidade normativa integral.','version_no':1,'valid_from':'2026-10-16','valid_to':None,'status':'draft','metadata':{'level':int(r['level']),'source_record_id':r['source_id'],'parent_source_record_id':r['parent_source_id'],'source_sha256':lot['source_sha256'],'sheet':'CAE','row':r['sheet_row'],'lot':'lot-01','source_version':files[0]['source_version'],'edition':'not_determined','sector_mapping':'none' if r['level']=='1' else 'explicit bounded editorial mapping for rice slice','date_semantics':'catalog availability; not legal validity'}})
chains=[{'id':ident('chain:'+r['code']),'source_system':'economic-reference-lot-01','external_id':r['code'],'version_no':1,'data_classification':'internal','cluster_id':cluster['id'],'code':r['code'],'name':r['name'],'stage':r['stage']} for r in lot['chain_stages']]
links=[{'id':ident('link:'+r['from']+':'+r['to']),'source_system':'economic-reference-lot-01','external_id':r['from']+':'+r['to'],'version_no':1,'data_classification':'internal','from_value_chain_id':ident('chain:'+r['from']),'to_value_chain_id':ident('chain:'+r['to']),'link_type':r['type']} for r in lot['chain_links']]
manifest={'lot':'lot-01','version':1,'origin_version':'eBAU-sha256-'+lot['source_sha256'][:12],'scope':'five-node rice slice and editorial CLU-01 chain; no normative edition conformity assertion','source_sha256':lot['source_sha256'],'divergence':{'exemplar_subclasses':600,'prior_instruction_subclasses':579,'status':'documentary_open_nonblocking_for_slice'},'convention':{'subsector':'01','activity':'01120','levels':5},'existing':meta,'sources':files,'disclosure':{'reference_designations_and_citations':'bounded editorial/reference slice authorised for QA; active requires explicit Tempo decision','source_originals':'private only'},'catalog':{'id':catalog,'catalog_code':'economic-activities-cae','version_no':1,'locale':'pt-MZ','source_system':'retained-ebau-exemplar','source_version':files[0]['source_version'],'source_reference':'CAE eBAU.xlsx, folha CAE; cinco nós A/01/011/0112/01120, hash '+lot['source_sha256']+'; edição normativa não determinada; 600/579 aberto.','source_sha256':lot['source_sha256'],'valid_from':'2026-10-16','valid_to':None,'status':'draft'},'activities':activities,'chains':chains,'links':links,'citations':{'activities':'CAE A1:F1; linhas 39,57,124,238,1122; SELF_ID explícito','chain_model':'Programação v6, §§534–543/631–635; modelo editorial genérico, sem operadores/capacidades/fluxos reais','context':'Agronegócio 1 §1; Corredores do Agronegócio §§4/10/23/29/39'},'new_reference_count':15}
p=source/'database/data/economic-references-lot-01.json';assert not p.exists();p.write_text(json.dumps(manifest,ensure_ascii=False,indent=2)+'\n','utf-8')
(out/'MANIFESTO-LOTE.json').write_bytes(p.read_bytes());(out/'MANIFESTO-HASH.json').write_text(json.dumps({'sha256':sha(p),'activities':{r['code']:r['id'] for r in activities},'chains':{r['code']:r['id'] for r in chains},'catalog':catalog},indent=2)+'\n','utf-8')
print(json.dumps({'manifest_sha256':sha(p),'records':15,'sources':len(files),'private_source_bytes':sum(x['bytes'] for x in files)}))