aboutsummaryrefslogtreecommitdiff
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
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.
-rw-r--r--demo/doit/dodo.py19
-rw-r--r--src/ee/kicad/doit.py112
-rwxr-xr-xsrc/ee/kicad/export_gerber.py2
-rw-r--r--test/doit/test_doit.py35
4 files changed, 73 insertions, 95 deletions
diff --git a/demo/doit/dodo.py b/demo/doit/dodo.py
index a050596..27ceb67 100644
--- a/demo/doit/dodo.py
+++ b/demo/doit/dodo.py
@@ -1,4 +1,4 @@
-from ee.kicad.doit import KicadDoitTasks
+import ee.kicad.doit
prj = "demo"
sch = "{}.sch".format(prj)
@@ -6,13 +6,12 @@ kicad_pcb = "{}.kicad_pcb".format(prj)
DOIT_CONFIG = {'check_file_uptodate': 'timestamp'}
+ee.kicad.doit.init(
+ sch=sch,
+ kicad_pcb=kicad_pcb,
+ gerber_dir="gerber",
+ data_set_dir="ee",
+)
-def task_kicad():
- args = {
- "sch": sch,
- "kicad_pcb": kicad_pcb,
- "gerber_dir": "gerber",
- "data_set_dir": "ee",
- }
- for t in KicadDoitTasks(**args).tasks():
- yield t
+# noinspection PyUnresolvedReferences
+from ee.kicad.doit import *
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
diff --git a/test/doit/test_doit.py b/test/doit/test_doit.py
index 3a0c7ec..4076af8 100644
--- a/test/doit/test_doit.py
+++ b/test/doit/test_doit.py
@@ -4,16 +4,13 @@ import os
import os.path
from inspect import Parameter
-logger = logging.getLogger(__name__)
-
-filedir = os.path.dirname(os.path.abspath(__file__))
-schematics_dir = os.path.join(filedir, "schematics")
+import ee.kicad.doit
+from ee.kicad.doit import task_kicad_sch_to_data_set, task_kicad_pcb_to_data_set, task_kicad_create_component_data_set
+logger = logging.getLogger(__name__)
-def find_task(tasks, name: str):
- t = next((t for t in tasks if t["name"] == name), None)
- assert t is not None, "Could not find task named {}".format(name)
- return t
+file_dir = os.path.dirname(os.path.abspath(__file__))
+schematics_dir = os.path.join(file_dir, "schematics")
def exec_task(task):
@@ -32,18 +29,12 @@ def exec_task(task):
a(**parameters)
+# noinspection SpellCheckingInspection
def test_doit(tmpdir, caplog):
- from ee.kicad.doit import KicadDoitTasks
-
- args = dict(
- sch=os.path.join(schematics_dir, "schematic-1.sch"),
- kicad_pcb=os.path.join(schematics_dir, "schematic-1.kicad_pcb"),
- data_set_dir=os.path.join(tmpdir, "ee"),
- )
- tasks = list(KicadDoitTasks(**args).tasks())
- assert (len(tasks) > 1)
- exec_task(find_task(tasks, "kicad-sch-to-data-set"))
- exec_task(find_task(tasks, "kicad-pcb-to-data-set"))
- exec_task(find_task(tasks, "kicad-create-component-data-set"))
-
-# thirdparty/olinuxino/HARDWARE/A64-OLinuXino/A64-OLinuXino_Rev_C/A64-OlinuXino_Rev_C.sch
+ ee.kicad.doit.init(sch=os.path.join(schematics_dir, "schematic-1.sch"),
+ kicad_pcb=os.path.join(schematics_dir, "schematic-1.kicad_pcb"),
+ data_set_dir=os.path.join(tmpdir, "ee"), )
+
+ exec_task(task_kicad_sch_to_data_set())
+ exec_task(task_kicad_pcb_to_data_set())
+ exec_task(task_kicad_create_component_data_set())