From 4afac7dc4c743284e5243428f00928aa7eaacfdc Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Wed, 15 May 2019 22:08:37 +0200 Subject: ee.project: Making sure all projects have an UUID. kicad-make-bom: Using the project's UUID to generate an URL for all parts. --- src/ee/kicad/make_bom.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src/ee/kicad') diff --git a/src/ee/kicad/make_bom.py b/src/ee/kicad/make_bom.py index 5242832..2faae31 100644 --- a/src/ee/kicad/make_bom.py +++ b/src/ee/kicad/make_bom.py @@ -1,4 +1,6 @@ +import uuid from pathlib import Path +from uuid import UUID from xml.dom import minidom from xml.etree import ElementTree @@ -13,7 +15,7 @@ __all__ = [ ] -def work(sch, out: Path, new_mode, pretty): +def work(sch, out: Path, project_uuid: UUID, new_mode, pretty): def strip(s): s = (s or "").strip() @@ -30,8 +32,16 @@ def work(sch, out: Path, new_mode, pretty): else: parts = PartDb() components = to_bom(sch, require_ref=False) + count = 0 for c in components: - xml = types.Part() + count = count + 1 + + if c.has_ref_num: + uri_ref = c.ref + else: + uri_ref = str(uuid.uuid5(uuid.NAMESPACE_DNS, str(count))) + + xml = types.Part(uri=uris.make_schematic_part_uri(project_uuid, uri_ref)) part = Part(xml) if c.has_ref_num: @@ -64,7 +74,7 @@ def work(sch, out: Path, new_mode, pretty): save_db(out, parts) -def make_bom(sch_file: Path, out_dir: Path, new_mode: bool, pretty: bool): +def make_bom(sch_file: Path, out_dir: Path, project_uuid: UUID, new_mode: bool, pretty: bool): sch = read_schematics(str(sch_file)) - work(sch, out_dir, new_mode, pretty) + work(sch, out_dir, project_uuid, new_mode, pretty) -- cgit v1.2.3