33 خطوط
1.7 KiB
Python
33 خطوط
1.7 KiB
Python
"""Reuse the parser's resource boundary, geometry model and SVG serializer."""
|
|
from . import parse_task # Sets the same subprocess resource limits, without running it.
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
from .documents import parse_document
|
|
from .diff import compare_documents
|
|
from .parser.record_decoder import ParseError
|
|
from .render import svg_document
|
|
|
|
|
|
def run():
|
|
source,destination,_,identifier=sys.argv[1:]
|
|
dest=Path(destination)
|
|
try:
|
|
manifest=json.loads(Path(source).read_text())
|
|
old=parse_document((dest/'old.SchDoc').read_bytes(),manifest['old_filename'],identifier+'-old',allow_empty=True)
|
|
new=parse_document((dest/'new.SchDoc').read_bytes(),manifest['new_filename'],identifier+'-new',allow_empty=True)
|
|
report=compare_documents(old,new)
|
|
(dest/'data.json').write_text(json.dumps(report,ensure_ascii=False),encoding='utf-8')
|
|
for side,doc in [('old',old),('new',new)]:
|
|
annotations={c[f'{side}_id']:{'id':c['id'],'status':c['status'],'bounds':c[f'{side}_bounds']}
|
|
for c in report['changes'] if c[f'{side}_id'] is not None}
|
|
(dest/f'{side}.svg').write_bytes(svg_document(doc,annotations,id_prefix=side+'-'))
|
|
result={'ok':True,'summary':{'summary':report['summary'],'total_changed':report['total_changed']}}
|
|
except (ParseError,ValueError) as exc:
|
|
result={'ok':False,'code':'invalid_schematic','message':str(exc)[:500]}
|
|
except Exception:
|
|
result={'ok':False,'code':'comparison_error','message':'The schematic comparison could not be completed'}
|
|
(dest/'result.json').write_text(json.dumps(result),encoding='utf-8')
|
|
|
|
if __name__=='__main__':run()
|