aboutsummaryrefslogtreecommitdiff
path: root/src/ee/kicad/bom/io.py
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2017-09-07 21:44:16 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2017-09-07 21:44:16 +0200
commit6ea743740ff4524287e5b63a18a45bd19d2451bb (patch)
treed14ec9c5b580450b8e2db2b115be85aea48afc42 /src/ee/kicad/bom/io.py
parenta3da99e22540c026e4acf7bdc735aa221a4dd752 (diff)
downloadee-python-6ea743740ff4524287e5b63a18a45bd19d2451bb.tar.gz
ee-python-6ea743740ff4524287e5b63a18a45bd19d2451bb.tar.bz2
ee-python-6ea743740ff4524287e5b63a18a45bd19d2451bb.tar.xz
ee-python-6ea743740ff4524287e5b63a18a45bd19d2451bb.zip
o Reformat all.
Diffstat (limited to 'src/ee/kicad/bom/io.py')
-rw-r--r--src/ee/kicad/bom/io.py81
1 files changed, 41 insertions, 40 deletions
diff --git a/src/ee/kicad/bom/io.py b/src/ee/kicad/bom/io.py
index c7eef44..d7c0367 100644
--- a/src/ee/kicad/bom/io.py
+++ b/src/ee/kicad/bom/io.py
@@ -1,44 +1,45 @@
import xml.etree.ElementTree as ElementTree
from ee.kicad.bom import *
+
def read_bom(path):
- def child_text(e, child_tag):
- child = e.find(child_tag)
-
- return child.text if child is not None else None
-
- def add_comp(b, comp):
- ref = comp.get("ref")
- value = child_text(comp, "value")
- footprint = child_text(comp, "footprint")
- libsource = comp.find("libsource")
- l, p = (None, None)
- if libsource is not None:
- lib = libsource.get("lib")
- part = libsource.get("part")
- if lib is not None and part is not None:
- l = b.find_library(lib)
- p = l.add_part(part)
-
- c = Comp(ref, value, l, p, footprint)
-
- fields = comp.find("fields")
- if fields is not None:
- for f in fields.findall("field"):
- key = f.get("name")
- value = f.text
- c.add_field(key, value)
-
- b.add_component(c)
- return c
-
- with open(path) as f:
- tree = ElementTree.parse(path)
- root = tree.getroot()
-
- b = Bom()
- comp = root.find("components").findall("comp")
- for c in comp:
- add_comp(b, c)
-
- return b
+ def child_text(e, child_tag):
+ child = e.find(child_tag)
+
+ return child.text if child is not None else None
+
+ def add_comp(b, comp):
+ ref = comp.get("ref")
+ value = child_text(comp, "value")
+ footprint = child_text(comp, "footprint")
+ libsource = comp.find("libsource")
+ l, p = (None, None)
+ if libsource is not None:
+ lib = libsource.get("lib")
+ part = libsource.get("part")
+ if lib is not None and part is not None:
+ l = b.find_library(lib)
+ p = l.add_part(part)
+
+ c = Comp(ref, value, l, p, footprint)
+
+ fields = comp.find("fields")
+ if fields is not None:
+ for f in fields.findall("field"):
+ key = f.get("name")
+ value = f.text
+ c.add_field(key, value)
+
+ b.add_component(c)
+ return c
+
+ with open(path) as f:
+ tree = ElementTree.parse(path)
+ root = tree.getroot()
+
+ b = Bom()
+ comp = root.find("components").findall("comp")
+ for c in comp:
+ add_comp(b, c)
+
+ return b