From 37e4be24129b6980e3e9fced7345d4a596af3d58 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 14 Apr 2019 19:41:30 +0200 Subject: digikey: o More flexibility, making room for the multiple digikey stores. o Removing URLs from core code. new tools: split_parts_by_supplier. --- src/ee/project/__init__.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/ee/project') diff --git a/src/ee/project/__init__.py b/src/ee/project/__init__.py index 24635ee..0857e7c 100644 --- a/src/ee/project/__init__.py +++ b/src/ee/project/__init__.py @@ -2,8 +2,8 @@ import configparser from pathlib import Path from ee import EeException +from ee.digikey import DigikeyStore from ee.tools import mk_parents -from ee.xml.uris import DIGIKEY_URI def load_config(project_dir: Path) -> configparser.ConfigParser: @@ -20,9 +20,10 @@ def load_config(project_dir: Path) -> configparser.ConfigParser: class SupplierDescriptor(object): - def __init__(self, key: str, uri: str): + def __init__(self, key: str, uri: str, name: str): self.key = key self.uri = uri + self.name = name class Project(object): @@ -34,7 +35,9 @@ class Project(object): self._cfg = cfg # TODO: read from config - self._suppliers = [SupplierDescriptor("digikey", DIGIKEY_URI)] + self._suppliers = [] + digikey_store = DigikeyStore.from_store_code("us") + self._suppliers.append(SupplierDescriptor("digikey", digikey_store.url, "Digikey")) def get_supplier_by_key(self, key) -> SupplierDescriptor: sd = next((s for s in self._suppliers if s.key == key), None) @@ -42,6 +45,12 @@ class Project(object): return sd raise EeException("No such supplier configured: {}".format(key)) + def get_supplier_by_uri(self, uri) -> SupplierDescriptor: + sd = next((s for s in self._suppliers if s.uri == uri), None) + if sd: + return sd + raise EeException("No such supplier configured: {}".format(uri)) + @property def cfg(self): return self._cfg -- cgit v1.2.3