aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ee/bom/doit.py66
-rw-r--r--src/ee/doit.py11
-rw-r--r--src/ee/kicad/doit.py59
3 files changed, 46 insertions, 90 deletions
diff --git a/src/ee/bom/doit.py b/src/ee/bom/doit.py
index 7c8f63a..bf6975b 100644
--- a/src/ee/bom/doit.py
+++ b/src/ee/bom/doit.py
@@ -1,48 +1,15 @@
import logging
from pathlib import Path
-from typing import Mapping, Union
+from typing import Union
-from configclass import Config
from namedlist import namedlist
-from ee.ds import DataSetManager, DataSet, create_message
+from ee.doit import DoItConfig
+from ee.ds import DataSet, create_message
logger = logging.getLogger(__name__)
-_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):
- try:
- return _data_sets[task][0]
- except KeyError:
- raise KeyError("No such task registered in this module: {}".format(task))
-
-
-def input_data_sets_for_task(task):
- try:
- return _data_sets[task][1]
- except KeyError:
- raise KeyError("No such task registered in this module: {}".format(task))
-
-
-_config_template = Config({})
-
-_config = None # type: Mapping[str, str]
-
-
-def init(data_set_manager: DataSetManager, **kwargs):
- global _config
- _config = _config_template.make(kwargs)
-
- global _dsm
- _dsm = data_set_manager
+doit_config = DoItConfig()
class BomComponent(object):
@@ -65,13 +32,12 @@ def task_bom():
creates 'bom-component' objects.
"""
- out_data_set = _data_sets[task_bom][0]
- in_data_sets = _data_sets[task_bom][1]
+ out_data_set, in_data_sets = doit_config.data_sets_for(task_bom)
def action():
- in_ds = _dsm.load_data_sets(in_data_sets)
+ in_ds = doit_config.dsm.load_data_sets(in_data_sets)
- with _dsm.create_rw(out_data_set, clean=True) as output:
+ with doit_config.dsm.create_rw(out_data_set, clean=True) as output:
components = [o for o in in_ds.items() if o.object_type.name == "component"]
bom_components = {}
@@ -95,17 +61,17 @@ def task_bom():
[c.to_object(output) for c in bom_components.values()]
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_bom] = ["bom", ["components"]]
+doit_config.set_data_sets_for(task_bom, "bom", "components")
def order_csv(count: int, style: str, output_file: Path, out_ds: DataSet, data_sets):
- ds = _dsm.load_data_sets(data_sets)
+ ds = doit_config.dsm.load_data_sets(data_sets)
csv_ds = DataSet()
@@ -196,18 +162,18 @@ def order_csv(count: int, style: str, output_file: Path, out_ds: DataSet, data_s
fields = ["Digi-Key Part Number", refs_field, count_field, mpn_field]
include_extra_fields = False
- _dsm.store_csv(output_file, csv_ds, "row", order_by=mpn_field, fields=fields,
- include_extra_fields=include_extra_fields)
+ doit_config.dsm.store_csv(output_file, csv_ds, "row", order_by=mpn_field, fields=fields,
+ include_extra_fields=include_extra_fields)
def create_task_order_csv(*, style: str = None, output_file: Union[str, Path], out_data_set, data_sets, count: int = 1):
def action():
- with _dsm.create_rw(out_data_set, clean=True) as out:
+ with doit_config.dsm.create_rw(out_data_set, clean=True) as out:
order_csv(count, style, Path(output_file), out, data_sets)
return {
"name": "order-{}".format(count) if not style else "order-{}-{}".format(style, count),
"actions": [action],
- "file_dep": [_dsm.cookie_for_ds(ds) for ds in data_sets],
- "targets": [_dsm.cookie_for_ds(out_data_set), output_file],
+ "file_dep": [doit_config.dsm.cookie_for_ds(ds) for ds in data_sets],
+ "targets": [doit_config.dsm.cookie_for_ds(out_data_set), output_file],
}
diff --git a/src/ee/doit.py b/src/ee/doit.py
index dc89fae..c0a01ea 100644
--- a/src/ee/doit.py
+++ b/src/ee/doit.py
@@ -33,7 +33,10 @@ class DoItConfig(object):
return self._dsm
def data_sets_for(self, task):
- return self._data_sets[task]
+ try:
+ return self._data_sets[task]
+ except KeyError:
+ raise KeyError("No such task registered in this module: {}".format(task))
def out_data_set_for(self, task):
return self.data_sets_for(task)[0]
@@ -42,4 +45,8 @@ class DoItConfig(object):
return self.data_sets_for(task)[1]
def set_data_sets_for(self, task, out_dataset: str, *in_datasets: str):
- self._data_sets[task] = [out_dataset, in_datasets]
+ self._data_sets[task] = [out_dataset, list(in_datasets)]
+
+ def change_data_sets_for_task(self, task, _callable):
+ ds = self._data_sets[task]
+ ds[1] = _callable(ds[1])
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__,