aboutsummaryrefslogtreecommitdiff
path: root/src/ee/kicad
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2019-02-26 23:08:19 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2019-02-26 23:08:19 +0100
commit97c8bb9db96e27051f8746865f657408263db0b8 (patch)
tree604cb6e9b87e79f43e54940adbc83520e89940fe /src/ee/kicad
parent80e0623913e87c6480049520590e424a831e0401 (diff)
downloadee-python-97c8bb9db96e27051f8746865f657408263db0b8.tar.gz
ee-python-97c8bb9db96e27051f8746865f657408263db0b8.tar.bz2
ee-python-97c8bb9db96e27051f8746865f657408263db0b8.tar.xz
ee-python-97c8bb9db96e27051f8746865f657408263db0b8.zip
o Creating a PartDb that manages a file system directory with one xml
file per part. o Switching xml-based code to use PartDb.
Diffstat (limited to 'src/ee/kicad')
-rw-r--r--src/ee/kicad/make_bom.py32
1 files changed, 11 insertions, 21 deletions
diff --git a/src/ee/kicad/make_bom.py b/src/ee/kicad/make_bom.py
index 2f5a2ac..00e9ae3 100644
--- a/src/ee/kicad/make_bom.py
+++ b/src/ee/kicad/make_bom.py
@@ -1,4 +1,5 @@
-import sys
+import pydoc
+from pathlib import Path
from typing import Optional, List, Callable, Mapping
from xml.dom import minidom
from xml.etree import ElementTree
@@ -7,7 +8,7 @@ from ee import EeException
from ee.kicad.model import Component
from ee.kicad.read_schematic import read_schematics
from ee.kicad.to_bom import to_bom, to_bom_xml
-from ee.tools import mk_parents
+from ee.part import PartDb, save_db
from ee.xml import bomFile, uris
__all__ = [
@@ -97,7 +98,7 @@ class MakeBomStrategy():
return apply_strategies(component, part, self.default_strategies)
-def work(sch, out_file, strategy: MakeBomStrategy, new_mode, pretty):
+def work(sch, out: Path, strategy: MakeBomStrategy, new_mode, pretty):
if not new_mode:
bom = to_bom_xml(sch)
xml = ElementTree.tostring(bom, encoding="unicode")
@@ -105,13 +106,9 @@ def work(sch, out_file, strategy: MakeBomStrategy, new_mode, pretty):
if pretty:
xml = minidom.parseString(xml).toprettyxml(indent=" ")
- print(xml, file=out_file)
+ print(xml)
else:
- file = bomFile.BomFile()
-
- parts = bomFile.PartList()
- file.partsProp = parts
-
+ parts = PartDb()
components = to_bom(sch)
for c in components:
part = bomFile.Part(id=c.ref)
@@ -124,16 +121,14 @@ def work(sch, out_file, strategy: MakeBomStrategy, new_mode, pretty):
part.part_numbersProp = None
if part is not None:
- parts.add_part(part)
+ parts.add_entry(part, True)
- file.export(out_file, 0, name_="bom-file", namespacedef_="xmlns='http://purl.org/ee/bom-file'",
- pretty_print=pretty)
+ save_db(out, parts)
-def make_bom(sch_file: str, out_file: Optional[str], strategy_name: str, new_mode: bool, pretty: bool):
- sch = read_schematics(sch_file)
+def make_bom(sch_file: Path, out_dir: Path, strategy_name: str, new_mode: bool, pretty: bool):
+ sch = read_schematics(str(sch_file))
- import pydoc
make_bom_strategy_factory = pydoc.locate(strategy_name)
if not callable(make_bom_strategy_factory):
@@ -144,9 +139,4 @@ def make_bom(sch_file: str, out_file: Optional[str], strategy_name: str, new_mod
if not isinstance(make_bom_strategy, MakeBomStrategy):
raise EeException("Not a MakeBomStrategy: {}, is a {}".format(strategy_name, type(make_bom_strategy)))
- if out_file:
- mk_parents(out_file)
- with open(out_file, "w") as f:
- work(sch, f, make_bom_strategy, new_mode, pretty)
- else:
- work(sch, sys.stdout, make_bom_strategy, new_mode, pretty)
+ work(sch, out_dir, make_bom_strategy, new_mode, pretty)