aboutsummaryrefslogtreecommitdiff
path: root/src/ee/project
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/ee/project
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/ee/project')
-rw-r--r--src/ee/project/__init__.py18
1 files changed, 10 insertions, 8 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)