aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2018-07-22 19:09:22 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2018-07-22 19:09:22 +0200
commit73fe63ceb6d10e5bed0664100de8709843661d8d (patch)
tree414f7cd31f3ca9888b366630261e33231e6cc87c /src
parenteadf780f736702d2c08825cb340a61237b4faa3f (diff)
downloadee-python-73fe63ceb6d10e5bed0664100de8709843661d8d.tar.gz
ee-python-73fe63ceb6d10e5bed0664100de8709843661d8d.tar.bz2
ee-python-73fe63ceb6d10e5bed0664100de8709843661d8d.tar.xz
ee-python-73fe63ceb6d10e5bed0664100de8709843661d8d.zip
wip.
o Moving to more standard doit task_xxx methods.
Diffstat (limited to 'src')
-rw-r--r--src/ee/kicad/doit.py112
-rwxr-xr-xsrc/ee/kicad/export_gerber.py2
2 files changed, 51 insertions, 63 deletions
diff --git a/src/ee/kicad/doit.py b/src/ee/kicad/doit.py
index 29438ad..577eb21 100644
--- a/src/ee/kicad/doit.py
+++ b/src/ee/kicad/doit.py
@@ -3,59 +3,47 @@ import os.path
from configclass import Config
+import ee.kicad
+import ee.kicad.pcb
from ee.fact import DataSetManager
logger = logging.getLogger(__name__)
+_config_template = Config({
+ "sch": None,
+ "kicad_pcb": None,
+ "gerber_dir": None,
+ "gerber_zip": None,
+ "data_set_dir": None,
+})
-class KicadDoitTasks(object):
- config = Config({
- "sch": None,
- "kicad_pcb": None,
- "gerber_dir": None,
- "gerber_zip": None,
- "data_set_dir": None,
- })
+_config = None
- def __init__(self, *args, **kwargs):
- self.config = self.config.make(kwargs)
+_dsm = None # type: DataSetManager
- formatter = logging.Formatter("%(levelname)s: %(message)s")
- ch = logging.StreamHandler()
- ch.setFormatter(formatter)
- logger.addHandler(ch)
- logger.setLevel(logging.DEBUG)
+def init(**kwargs):
+ global _config
+ _config = _config_template.make(kwargs)
- def tasks(self, *args, **kwargs):
- kicad_pcb = self.config["kicad_pcb"]
- sch = self.config["sch"]
- tasks = []
+ formatter = logging.Formatter("%(levelname)s: %(message)s")
+ ch = logging.StreamHandler()
+ ch.setFormatter(formatter)
+ logger.addHandler(ch)
- dsm = DataSetManager(self.config["data_set_dir"])
+ logger.setLevel(logging.DEBUG)
- gerber_dir = self.config["gerber_dir"]
- gerber_zip = self.config["gerber_zip"]
- if kicad_pcb and gerber_dir:
- tasks.append(task_kicad_gerber(kicad_pcb, gerber_dir, gerber_zip))
+ global _dsm
+ _dsm = DataSetManager(_config["data_set_dir"])
- sch_ds = task_kicad_sch_to_data_set(dsm, sch) \
- if sch else None
- pcb_ds = task_kicad_pcb_to_data_set(dsm, kicad_pcb) \
- if kicad_pcb else None
-
- component_ds = task_kicad_create_component_data_set(dsm) \
- if sch_ds else None
-
- tasks = [component_ds, sch_ds, pcb_ds,]
- return tasks
-
-
-def task_kicad_gerber(kicad_pcb: str, gerber_dir: str, gerber_zip: str, name="kicad-gerber"):
- import ee.kicad
+def task_kicad_gerber():
+ kicad_pcb = _config["kicad_pcb"]
+ gerber_dir = _config["gerber_dir"]
+ gerber_zip = _config["gerber_zip"]
gerber_zip = gerber_zip or "{}.zip".format(gerber_dir)
+
# logger.info("gerber_zip={}".format(gerber_zip))
eg = next((p for p in (os.path.join(p, "export_gerber.py") for p in ee.kicad.__path__) if os.path.isfile(p)), None)
@@ -81,22 +69,23 @@ def task_kicad_gerber(kicad_pcb: str, gerber_dir: str, gerber_zip: str, name="ki
z.write(p, arcname=p.relative_to(gerber_dir))
return {
- "name": name,
+ "basename": "kicad-gerber",
"targets": [gerber_zip],
"actions": [mkdir, export_gerber, make_zip],
"file_dep": [kicad_pcb],
}
-def task_kicad_sch_to_data_set(dsm: DataSetManager, sch, name="kicad-sch-to-data-set"):
+def task_kicad_sch_to_data_set():
out_data_set = "kicad-sch"
in_data_sets = []
+ sch = _config["sch"]
+
def action():
- import ee.kicad
from ee.kicad.model import ComponentField
- with dsm.create_rw(out_data_set, inputs=in_data_sets) as ds:
+ with _dsm.create_rw(out_data_set, inputs=in_data_sets) as ds:
schematics = ee.kicad.read_schematics(sch)
for c in [c for c in schematics.components]:
o = ds.get_object("kicad-schematic-component", c.timestamp)
@@ -113,33 +102,32 @@ def task_kicad_sch_to_data_set(dsm: DataSetManager, sch, name="kicad-sch-to-data
o.set(f.name, str(f.value))
return {
- "name": name,
- "file_dep": [sch] + [dsm.metafile_for_ds(ds) for ds in in_data_sets],
+ "basename": "kicad-sch-to-data-set",
+ "file_dep": [sch] + [_dsm.metafile_for_ds(ds) for ds in in_data_sets],
"actions": [action],
- "targets": [dsm.metafile_for_ds(out_data_set)],
+ "targets": [_dsm.metafile_for_ds(out_data_set)],
}
-def task_kicad_pcb_to_data_set(dsm: DataSetManager, pcb_path, name="kicad-pcb-to-data-set"):
+def task_kicad_pcb_to_data_set():
+ kicad_pcb = _config["kicad_pcb"]
+
out_data_set = "kicad-pcb"
in_data_sets = []
def action():
- import ee.kicad.pcb
- from ee.kicad.pcb import FpText
-
- logger.debug("Parsing PCB {}".format(pcb_path))
+ logger.debug("Parsing PCB {}".format(kicad_pcb))
- with dsm.create_rw(out_data_set, inputs=in_data_sets) as ds:
+ with _dsm.create_rw(out_data_set, inputs=in_data_sets) as ds:
# [ds.delete(o) for o in ds.items(object_type="kicad-pcb-component")]
- pcb: ee.kicad.pcb.KicadPcb = ee.kicad.pcb.parse(pcb_path)
+ pcb = ee.kicad.pcb.parse(kicad_pcb) # type: ee.kicad.pcb.KicadPcb
for _m in pcb.modules:
- m: ee.kicad.pcb.Module = _m
+ m = _m # type: ee.kicad.pcb.Module
o = ds.get_object("kicad-pcb-component", m.tstamp)
- ref_text: FpText = next((t for t in m.fp_texts if t.kind == "reference"), None)
+ ref_text = next((t for t in m.fp_texts if t.kind == "reference"), None)
o.set("reference", ref_text.value)
x, y, rot = m.at
@@ -149,29 +137,29 @@ def task_kicad_pcb_to_data_set(dsm: DataSetManager, pcb_path, name="kicad-pcb-to
o.set("layer", m.layer)
return {
- "name": name,
- "file_dep": [pcb_path] + [dsm.metafile_for_ds(ds) for ds in in_data_sets],
+ "basename": "kicad-pcb-to-data-set",
+ "file_dep": [kicad_pcb] + [_dsm.metafile_for_ds(ds) for ds in in_data_sets],
"actions": [action],
- "targets": [dsm.metafile_for_ds(out_data_set)],
+ "targets": [_dsm.metafile_for_ds(out_data_set)],
}
-def task_kicad_create_component_data_set(dsm: DataSetManager, name="kicad-create-component-data-set"):
+def task_kicad_create_component_data_set():
out_data_set = "components"
in_data_sets = ["kicad-sch", "kicad-pcb"]
def action(targets, *args, **kwargs):
logger.info("targets={}, args={}, kwargs={}".format(targets, args, kwargs))
- with dsm.create_rw(out_data_set, inputs=in_data_sets) as ds:
+ with _dsm.create_rw(out_data_set, inputs=in_data_sets) as ds:
items = ds.items()
logger.info("Got {} objects".format(len(items)))
for o in items:
logger.info("processing {}".format(o.key))
return {
- "name": name,
- "file_dep": [dsm.metafile_for_ds(ds) for ds in in_data_sets],
+ "basename": "kicad-create-component-data-set",
+ "file_dep": [_dsm.metafile_for_ds(ds) for ds in in_data_sets],
"actions": [action],
- "targets": [dsm.metafile_for_ds(out_data_set)],
+ "targets": [_dsm.metafile_for_ds(out_data_set)],
}
diff --git a/src/ee/kicad/export_gerber.py b/src/ee/kicad/export_gerber.py
index 511f9ee..c4c72fd 100755
--- a/src/ee/kicad/export_gerber.py
+++ b/src/ee/kicad/export_gerber.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python2
from __future__ import print_function
import sys
import os