From c8250596fc6b50f2c92fb3952491ddfcbf0f9781 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Thu, 1 Aug 2019 15:26:28 +0200 Subject: ee init: Make sure the uuid is kept when reinitializing. --- src/ee/project/__init__.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'src/ee/project') 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) -- cgit v1.2.3