aboutsummaryrefslogtreecommitdiff
path: root/src/ee/kicad
diff options
context:
space:
mode:
Diffstat (limited to 'src/ee/kicad')
-rw-r--r--src/ee/kicad/doit.py59
1 files changed, 21 insertions, 38 deletions
diff --git a/src/ee/kicad/doit.py b/src/ee/kicad/doit.py
index bf0ee3a..c881c70 100644
--- a/src/ee/kicad/doit.py
+++ b/src/ee/kicad/doit.py
@@ -7,7 +7,7 @@ from configclass import Config
import ee.kicad
import ee.kicad.pcb
-from ee.ds import DataSetManager
+from ee.doit import DoItConfig
logger = logging.getLogger(__name__)
@@ -18,29 +18,12 @@ _config_template = Config({
"gerber_zip": None,
})
-_config = None # type: Mapping[str, str]
-
-_dsm = None # type: DataSetManager
-
-_data_sets = {}
-
-
-def change_data_sets_for_task(task, _callable):
- _data_sets[task][1] = _callable(_data_sets[task][1])
-
-
-def output_data_set_for_task(task):
- return _data_sets[task][0]
-
-
-def input_data_sets_for_task(task):
- return _data_sets[task][1]
+doit_config = DoItConfig()
+_config = None # type: Mapping[str, str]
-def init(data_set_manager: DataSetManager, **kwargs):
- global _dsm
- _dsm = data_set_manager
+def init(**kwargs):
global _config
_config = _config_template.make(kwargs)
@@ -84,14 +67,14 @@ def task_kicad_gerber():
def task_kicad_sch_to_data_set():
- out_data_set, in_data_sets = _data_sets[task_kicad_sch_to_data_set]
+ out_data_set, in_data_sets = doit_config.data_sets_for(task_kicad_sch_to_data_set)
sch = _config["sch"]
def action():
from ee.kicad.model import ComponentField
- with _dsm.create_rw(out_data_set, clean=True) as ds:
+ with doit_config.dsm.create_rw(out_data_set, clean=True) as ds:
schematics = ee.kicad.read_schematics(sch)
for c in [c for c in schematics.components]:
o = ds.create_object("kicad-schematic-component", c.timestamp)
@@ -108,26 +91,26 @@ def task_kicad_sch_to_data_set():
o.set("field-{}".format(f.name), str(f.value))
return {
- "file_dep": [Path(sch)] + [_dsm.cookie_for_ds(ds) for ds in in_data_sets],
+ "file_dep": [Path(sch)] + [doit_config.dsm.cookie_for_ds(ds) for ds in in_data_sets],
"actions": [action],
- "targets": [_dsm.cookie_for_ds(out_data_set)],
+ "targets": [doit_config.dsm.cookie_for_ds(out_data_set)],
}
-_data_sets[task_kicad_sch_to_data_set] = ["kicad-sch", []]
+doit_config.set_data_sets_for(task_kicad_sch_to_data_set, "kicad-sch")
def task_kicad_pcb_to_data_set():
kicad_pcb = _config["kicad_pcb"]
- out_data_set, in_data_sets = _data_sets[task_kicad_pcb_to_data_set]
+ out_data_set, in_data_sets = doit_config.data_sets_for(task_kicad_pcb_to_data_set)
def action():
from ee.kicad.pcb import KicadPcb, Module
logger.debug("Parsing PCB {}".format(kicad_pcb))
- with _dsm.create_rw(out_data_set, clean=True) as ds:
+ with doit_config.dsm.create_rw(out_data_set, clean=True) as ds:
# [ds.delete(o) for o in ds.items(object_type="kicad-pcb-component")]
pcb = ee.kicad.pcb.parse(kicad_pcb) # type: KicadPcb
@@ -146,20 +129,21 @@ def task_kicad_pcb_to_data_set():
o.set("layer", m.layer)
return {
- "file_dep": [Path(kicad_pcb)] + [_dsm.cookie_for_ds(ds) for ds in in_data_sets],
+ "file_dep": [Path(kicad_pcb)] + [doit_config.dsm.cookie_for_ds(ds) for ds in in_data_sets],
"actions": [action],
- "targets": [_dsm.cookie_for_ds(out_data_set)],
+ "targets": [doit_config.dsm.cookie_for_ds(out_data_set)],
}
-_data_sets[task_kicad_pcb_to_data_set] = ["kicad-pcb", []]
+doit_config.set_data_sets_for(task_kicad_pcb_to_data_set, "kicad-pcb")
def task_kicad_create_component_data_set():
- out_data_set, in_data_sets = _data_sets[task_kicad_create_component_data_set]
+ out_data_set, in_data_sets = doit_config.data_sets_for(task_kicad_create_component_data_set)
def action():
- in_ds = _dsm.load_data_sets(in_data_sets)
+ in_ds = doit_config.dsm.load_data_sets(in_data_sets)
+
# for o in in_ds.items():
# logger.info("item: {}/{}".format(o.object_type.name, o.key))
@@ -174,7 +158,7 @@ def task_kicad_create_component_data_set():
return footprint
- with _dsm.create_rw(out_data_set, clean=True) as output:
+ with doit_config.dsm.create_rw(out_data_set, clean=True) as output:
kicad_sch = [o for o in in_ds.items() if o.object_type.name == "kicad-schematic-component"]
logger.info("processing {} kicad-sch".format(len(kicad_sch)))
@@ -222,17 +206,16 @@ def task_kicad_create_component_data_set():
# c.set("footprint", pcb.)
return {
- "file_dep": [_dsm.cookie_for_ds(ds) for ds in in_data_sets],
+ "file_dep": [doit_config.dsm.cookie_for_ds(ds) for ds in in_data_sets],
"actions": [action],
- "targets": [_dsm.cookie_for_ds(out_data_set)],
+ "targets": [doit_config.dsm.cookie_for_ds(out_data_set)],
}
-_data_sets[task_kicad_create_component_data_set] = ["components", ["kicad-sch", "kicad-pcb"]]
+doit_config.set_data_sets_for(task_kicad_create_component_data_set, "components", "kicad-sch", "kicad-pcb")
__all__ = [
init.__name__,
- change_data_sets_for_task.__name__,
task_kicad_create_component_data_set.__name__,
task_kicad_gerber.__name__,