aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2019-08-01 15:26:28 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2019-08-01 15:26:28 +0200
commitc8250596fc6b50f2c92fb3952491ddfcbf0f9781 (patch)
tree19dcb4800445821fa52dad1a5b8f0e20e9a41cf7 /src
parent16ccbfdc70f9407b0bd600fe600e98ecfae7f198 (diff)
downloadee-python-c8250596fc6b50f2c92fb3952491ddfcbf0f9781.tar.gz
ee-python-c8250596fc6b50f2c92fb3952491ddfcbf0f9781.tar.bz2
ee-python-c8250596fc6b50f2c92fb3952491ddfcbf0f9781.tar.xz
ee-python-c8250596fc6b50f2c92fb3952491ddfcbf0f9781.zip
ee init: Make sure the uuid is kept when reinitializing.
Diffstat (limited to 'src')
-rw-r--r--src/ee/project/__init__.py18
-rw-r--r--src/ee/supplier/seeed.py4
-rw-r--r--src/ee/tools/init.py30
3 files changed, 26 insertions, 26 deletions
diff --git a/src/ee/project/__init__.py b/src/ee/project/__init__.py
index 395d204..c9e02f8 100644
--- a/src/ee/project/__init__.py
+++ b/src/ee/project/__init__.py
@@ -36,12 +36,8 @@ class Project(object):
self.project_dir = project_dir
self._cfg = cfg
- if "project" not in cfg:
- cfg.add_section("project")
-
- project = cfg["project"]
- if "uuid" not in project:
- project["uuid"] = str(uuid.uuid4())
+ project = self.get_or_create_section("project")
+ project["uuid"] = project.get("uuid", str(uuid.uuid4()))
# TODO: read from config
self._suppliers = []
@@ -68,13 +64,19 @@ class Project(object):
def cfg(self):
return self._cfg
+ def get_or_create_section(self, section):
+ try:
+ return self._cfg[section]
+ except KeyError:
+ self._cfg.add_section(section)
+ return self._cfg[section]
+
@property
def uuid(self):
return uuid.UUID(hex=self._cfg["project"]["uuid"])
@classmethod
- def load(cls):
- project_dir = Path(".")
+ def load(cls, project_dir=Path(".")):
cfg = load_config(project_dir)
return Project(project_dir, cfg)
diff --git a/src/ee/supplier/seeed.py b/src/ee/supplier/seeed.py
index 1982f68..573c4b5 100644
--- a/src/ee/supplier/seeed.py
+++ b/src/ee/supplier/seeed.py
@@ -149,5 +149,5 @@ def download_opl(out_path: Path, cache_dir: Path, opl_type: str):
def init_project(project):
opls = ["SEEED", "HQCHIP"]
- project.cfg.add_section("seeed-opl")
- project.cfg["seeed-opl"]["opls"] = ", ".join(opls)
+ section = project.get_or_create_section("seeed-opl")
+ section["opls"] = ", ".join(opls)
diff --git a/src/ee/tools/init.py b/src/ee/tools/init.py
index 3f8d2b1..9b3bcf4 100644
--- a/src/ee/tools/init.py
+++ b/src/ee/tools/init.py
@@ -1,5 +1,4 @@
import argparse
-import configparser
import uuid
from pathlib import Path
from typing import List
@@ -8,41 +7,41 @@ import ee.tools
from ee.project import Project
-def init_kicad_project(basedir: Path, cfg, args):
+def init_kicad_project(basedir: Path, project: Project, args):
pro_files: List[Path] = [f for f in basedir.iterdir() if f.name.endswith(".pro")]
if len(pro_files) == 0:
return
- cfg.add_section("kicad-project")
+ cfg = project.get_or_create_section("kicad-project")
if len(pro_files) == 1:
pro_file = pro_files[0]
sch_file: Path = pro_file.parent / (pro_file.name[0:-4] + ".sch")
pcb_file: Path = pro_file.parent / (pro_file.name[0:-4] + ".kicad_pcb")
- cfg["kicad-project"]["uuid"] = str(uuid.uuid4())
+ cfg["uuid"] = cfg.get("uuid", str(uuid.uuid4()))
if sch_file.is_file():
print("Found KiCAD project and schematic")
- cfg["kicad-project"]["sch"] = str(sch_file)
+ cfg["sch"] = str(sch_file)
if pcb_file.is_file():
- cfg["kicad-project"]["pcb"] = str(pcb_file)
+ cfg["pcb"] = str(pcb_file)
- cfg["kicad-project"]["functions"] = "ee.kicad.functions.default"
- cfg["kicad-project"]["function-arguments"] = ""
+ cfg["functions"] = cfg.get("functions", "ee.kicad.functions.default")
+ cfg["function-arguments"] = cfg.get("function-arguments", "ee.kicad.functions.default")
else:
print("Found more than one kicad project file.")
if args.kicad_bom_strategy:
- cfg["kicad-project"]["strategy"] = args.kicad_bom_strategy
+ cfg["strategy"] = args.kicad_bom_strategy
def init_digikey(project: Project):
- project.cfg.add_section("supplier:digikey")
+ supplier = project.get_or_create_section("supplier:digikey")
- project.cfg["supplier:digikey"]["function"] = "ee.digikey.functions.default"
+ supplier["function"] = supplier.get("function", "ee.digikey.functions.default")
def init_seeed_opl(project: Project):
@@ -51,16 +50,15 @@ def init_seeed_opl(project: Project):
def init(project_dir: Path, basedir: Path, args):
- cfg = configparser.ConfigParser()
- project = Project(project_dir, cfg)
+ project = Project.load(project_dir)
- init_kicad_project(basedir, cfg, args)
+ init_kicad_project(basedir, project, args)
init_digikey(project)
init_seeed_opl(project)
if args.create_bom_strategy:
- project.cfg.add_section("create-bom")
- project.cfg["create-bom"]["strategy"] = args.create_bom_strategy
+ create_bom = project.get_or_create_section("create-bom")
+ create_bom["strategy"] = args.create_bom_strategy
print("Saving project. Now run 'ee ninja' to generate Ninja build file")
project.save()