aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2018-07-22 19:07:41 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2018-07-22 19:07:41 +0200
commiteadf780f736702d2c08825cb340a61237b4faa3f (patch)
tree4bbea24e65c191b446d5a37d3c2e44d036265f1b
parent067cd0ef6a7e031ea839c7d118da002267df95b3 (diff)
downloadee-python-eadf780f736702d2c08825cb340a61237b4faa3f.tar.gz
ee-python-eadf780f736702d2c08825cb340a61237b4faa3f.tar.bz2
ee-python-eadf780f736702d2c08825cb340a61237b4faa3f.tar.xz
ee-python-eadf780f736702d2c08825cb340a61237b4faa3f.zip
Formatting.
-rw-r--r--src/ee/kicad/pcb/__init__.py36
1 files changed, 22 insertions, 14 deletions
diff --git a/src/ee/kicad/pcb/__init__.py b/src/ee/kicad/pcb/__init__.py
index 25689ef..a4ad8ba 100644
--- a/src/ee/kicad/pcb/__init__.py
+++ b/src/ee/kicad/pcb/__init__.py
@@ -1,6 +1,7 @@
from .. import sexpr
from ..._utils import run_filters
+
def auto_str(cls):
def __str__(self):
return str({k: [str(x) for x in v] if isinstance(v, list) else str(v) for k, v in vars(self).items()})
@@ -8,18 +9,21 @@ def auto_str(cls):
cls.__str__ = __str__
return cls
+
@auto_str
class KicadPcb(object):
def __init__(self, **kwargs):
for k, v in kwargs.items():
setattr(self, k, v)
+
@auto_str
class General(object):
def __init__(self, **kwargs):
for k, v in kwargs.items():
setattr(self, k, v)
+
@auto_str
class Module(object):
def __init__(self, **kwargs):
@@ -29,7 +33,7 @@ class Module(object):
self.fp_texts = self.fp_texts if hasattr(self, "fp_texts") else []
self.attr = self.attr if hasattr(self, "attr") else []
- def filter_fp_text(self, kind = None):
+ def filter_fp_text(self, kind=None):
filters = []
if kind:
@@ -40,12 +44,14 @@ class Module(object):
def has_attr(self, name):
return next((True for a in self.attr if a == name), False)
+
@auto_str
class Pad(object):
def __init__(self, **kwargs):
for k, v in kwargs.items():
setattr(self, k, v)
+
@auto_str
class FpText(object):
def __init__(self, **kwargs):
@@ -56,9 +62,7 @@ class FpText(object):
def parse(path) -> KicadPcb:
- count = 0
p = sexpr.parse(path)
- #p = sexpr.logging_parser(p)
(e, t) = next(p)
assert e == sexpr.EVENT_LPAREN
@@ -66,20 +70,21 @@ def parse(path) -> KicadPcb:
assert e == sexpr.EVENT_TEXT and t == "kicad_pcb"
idx = 0
+
def _consume():
nonlocal idx
idx = idx + 1
-# print("consume: idx={}".format(idx))
+ # print("consume: idx={}".format(idx))
(event, token) = next(p)
-# print("consume: event={}".format(event))
+ # print("consume: event={}".format(event))
while event != sexpr.EVENT_RPAREN:
if event == sexpr.EVENT_LPAREN:
_consume()
elif event == sexpr.EVENT_TEXT:
pass
(event, token) = next(p)
-# print("consume: event={}".format(event))
-# print("consume: done".format())
+ # print("consume: event={}".format(event))
+ # print("consume: done".format())
idx = idx - 1
def _parse_kicad_pcb():
@@ -90,7 +95,7 @@ def parse(path) -> KicadPcb:
while event == sexpr.EVENT_LPAREN:
(event, token) = next(p)
if token == "version":
- args[token] = _parse_text(rparen = True)
+ args[token] = _parse_text(rparen=True)
elif token == "general":
args[token] = _parse_general()
elif token == "module":
@@ -101,7 +106,7 @@ def parse(path) -> KicadPcb:
return KicadPcb(**args)
- def _parse_text(optional = False, rparen = False, to = None):
+ def _parse_text(optional=False, rparen=False, to=None):
(event, token) = next(p)
if not optional:
assert event == sexpr.EVENT_TEXT
@@ -123,11 +128,14 @@ def parse(path) -> KicadPcb:
while event == sexpr.EVENT_LPAREN:
(event, token) = next(p)
if token == "no_connects":
- args[token] =_parse_text(to=int, rparen = True)
+ args[token] = _parse_text(to=int, rparen=True)
elif token == "area":
- args[token] = (_parse_text(to=float), _parse_text(to=float), _parse_text(to=float), _parse_text(to=float, rparen = True))
+ args[token] = (_parse_text(to=float),
+ _parse_text(to=float),
+ _parse_text(to=float),
+ _parse_text(to=float, rparen=True))
elif token == "thickness":
- args[token] = _parse_text(rparen = True)
+ args[token] = _parse_text(rparen=True)
else:
_consume()
(event, token) = next(p)
@@ -209,9 +217,9 @@ def parse(path) -> KicadPcb:
def _parse_at():
x = _parse_text(to=float)
y = _parse_text(to=float)
- rot = _parse_text(to=float, optional = True, rparen = True)
+ rot = _parse_text(to=float, optional=True, rparen=True)
return x, y, rot or 0
kicad_pcb = _parse_kicad_pcb()
- assert next(p, None) == None
+ assert next(p, None) is None
return kicad_pcb