diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2018-07-30 21:21:59 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2018-07-30 21:21:59 +0200 |
commit | a25bba9dd40b5dd6b0d85fd415634e2e768fe40b (patch) | |
tree | ad39d13f9580a5c45ce718e3cee1ba8a6f03ef08 /src/ee/ds | |
parent | 661332c3ce7562b30545ae1773d30a784bcbc0db (diff) | |
download | ee-python-a25bba9dd40b5dd6b0d85fd415634e2e768fe40b.tar.gz ee-python-a25bba9dd40b5dd6b0d85fd415634e2e768fe40b.tar.bz2 ee-python-a25bba9dd40b5dd6b0d85fd415634e2e768fe40b.tar.xz ee-python-a25bba9dd40b5dd6b0d85fd415634e2e768fe40b.zip |
o Changing resolve-schematic-components to create generic
'component-to-part-mapping' objects with seller=digikey
o Implementing 'task_digikey_fetch_full_part_facts' that downloads info
about each mapped parts with seller=digikey.
Diffstat (limited to 'src/ee/ds')
-rw-r--r-- | src/ee/ds/__init__.py | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/src/ee/ds/__init__.py b/src/ee/ds/__init__.py index 14bbb91..e48cab6 100644 --- a/src/ee/ds/__init__.py +++ b/src/ee/ds/__init__.py @@ -49,6 +49,9 @@ class ObjectType(object): self._fields.append(field) return len(self._fields) - 1 + def has(self, *keys: str): + return all([key in self._fields for key in keys]) + class Object(object): def __init__(self, ds: "DataSet", ot: ObjectType, key: str): @@ -77,6 +80,9 @@ class Object(object): for k in other._ot.fields: self.set(k, other.get(k)) + def has(self, *keys: str): + return self.object_type.has(*keys) + def get(self, key: str) -> Optional[str]: idx = self._ot.index_of(key) return self._data[idx] if idx is not None and idx < len(self._data) else None @@ -293,7 +299,7 @@ class DataSetManager(object): ds_dir = Path(_path) if Path(_path).is_absolute() else self._basedir / _path ds_dir = ds_dir if ds_dir.is_dir() else ds_dir.parent - logger.debug("Loading DS from '{}'".format(ds_dir)) + # logger.debug("Loading DS from '{}'".format(ds_dir)) self._load_ini(ds_dir / "data-set.ini") @@ -304,12 +310,12 @@ class DataSetManager(object): continue ot = ot_path.name - logger.debug(" Loading type '{}'".format(ot)) + # logger.debug(" Loading type '{}'".format(ot)) for o_path in ot_path.glob("*.ini"): count += 1 key = o_path.name[:-4] - logger.debug(" Loading key '{}'".format(key)) + # logger.debug(" Loading key '{}'".format(key)) ini = self._load_ini(o_path) o = ds.create_object(ot, key) for k, v in ini.items("values"): @@ -318,13 +324,13 @@ class DataSetManager(object): if freeze: ds.freeze() - logger.debug("Loaded {} items".format(count)) + # logger.debug("Loaded {} items".format(count)) return ds def store(self, ds: DataSet, ds_name: str): ds_dir = self._basedir / ds_name items = list(ds.items()) - logger.info("Storing DS '{}' with {} objects to {}".format(ds_name, len(items), ds_dir)) + # logger.info("Storing DS '{}' with {} objects to {}".format(ds_name, len(items), ds_dir)) os.makedirs(ds_dir, exist_ok=True) ini = self._blank_ini() @@ -428,3 +434,9 @@ class LazyRwDataSet(object): def __exit__(self, *args): self._dsm.store(self._ds, self._name) return False + + +def create_message(data_set: DataSet, message: str, level: str): + return data_set.create_object("message", "message-{}".format(str(hash(message)))). \ + set("message", message). \ + set("level", level) |