From 73c63d8c307bdbeb534c24fb51d4093c2fcbb86d Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Fri, 29 Mar 2019 16:41:25 +0100 Subject: Project: o adding cache_dir field, useful for controlling where cached data is placed from a central place. o Updating tools to use this new variable. --- src/ee/digikey/search_parts.py | 1 + src/ee/project/__init__.py | 3 ++- src/ee/tools/digikey_search_parts.py | 6 ++++-- src/ee/tools/element14_search_parts.py | 12 ++++++------ src/ee/tools/seeed_download_opl.py | 6 ++++-- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/ee/digikey/search_parts.py b/src/ee/digikey/search_parts.py index 7d19c5b..fec5615 100644 --- a/src/ee/digikey/search_parts.py +++ b/src/ee/digikey/search_parts.py @@ -3,6 +3,7 @@ from typing import List from ee.digikey import Digikey, DigikeyParser, DigikeyClient, SearchResponseTypes, DigikeyProduct from ee.part import PartDb, load_db, save_db, Part +from ee.project import Project from ee.xml import types from ee.xml.uris import DIGIKEY_URI, make_digikey_fact_key diff --git a/src/ee/project/__init__.py b/src/ee/project/__init__.py index bca9984..1adbbde 100644 --- a/src/ee/project/__init__.py +++ b/src/ee/project/__init__.py @@ -9,7 +9,7 @@ from ee.xml.uris import DIGIKEY_URI def load_config(project_dir: Path) -> configparser.ConfigParser: config = configparser.ConfigParser() - config_path = project_dir / ".ee" / "config" + config_path = project_dir / "eeconfig" try: with config_path.open("r") as f: config.read_file(f, source=str(config_path)) @@ -29,6 +29,7 @@ class Project(object): def __init__(self, project_dir: Path, cfg: configparser.ConfigParser): self.report_dir = project_dir / "ee" / "reports" self.public_dir = project_dir / "ee" + self.cache_dir = project_dir / "ee" / "cache" self.project_dir = project_dir self._cfg = cfg diff --git a/src/ee/tools/digikey_search_parts.py b/src/ee/tools/digikey_search_parts.py index 9f35e33..6cf104d 100644 --- a/src/ee/tools/digikey_search_parts.py +++ b/src/ee/tools/digikey_search_parts.py @@ -2,6 +2,7 @@ import argparse from pathlib import Path from ee.digikey.search_parts import search_parts +from ee.project import Project parser = argparse.ArgumentParser() @@ -16,6 +17,7 @@ parser.add_argument("--out", args = parser.parse_args() -cache_dir = ".ee/cache/digikey" +project = Project.load() +cache_dir = project.cache_dir / "digikey" -search_parts(Path(args.in_path), Path(args.out), Path(cache_dir)) +search_parts(Path(args.in_path), Path(args.out), cache_dir) diff --git a/src/ee/tools/element14_search_parts.py b/src/ee/tools/element14_search_parts.py index 11fd3e1..e2ef414 100644 --- a/src/ee/tools/element14_search_parts.py +++ b/src/ee/tools/element14_search_parts.py @@ -1,9 +1,9 @@ import argparse from pathlib import Path -from ee import project from ee.element14 import Element14Config from ee.element14.search_parts import search_parts +from ee.project import Project parser = argparse.ArgumentParser() @@ -18,13 +18,13 @@ parser.add_argument("--out", args = parser.parse_args() -cache_dir = ".ee/cache/element14" +project = Project.load() -config = project.load_config(Path(".")) +cache_dir = project.cache_dir / "element14" e14_config = Element14Config( - store=config.get("element14", "store", fallback=None), - api_key=config.get("element14", "api-key", fallback=None) + store=project.cfg.get("element14", "store", fallback=None), + api_key=project.cfg.get("element14", "api-key", fallback=None) ) -search_parts(Path(args.in_path), Path(args.out), Path(cache_dir), e14_config) +search_parts(Path(args.in_path), Path(args.out), cache_dir, e14_config) diff --git a/src/ee/tools/seeed_download_opl.py b/src/ee/tools/seeed_download_opl.py index 3f8b07b..efbdfb3 100644 --- a/src/ee/tools/seeed_download_opl.py +++ b/src/ee/tools/seeed_download_opl.py @@ -1,6 +1,7 @@ import argparse from pathlib import Path +from ee.project import Project from ee.supplier import seeed parser = argparse.ArgumentParser() @@ -15,6 +16,7 @@ parser.add_argument("--opl", args = parser.parse_args() -cache_dir = ".ee/cache/seeed" +project = Project.load() +cache_dir = project.cache_dir / "seeed" -seeed.download_opl(Path(args.out), Path(cache_dir), args.opl) +seeed.download_opl(Path(args.out), cache_dir, args.opl) -- cgit v1.2.3