From 18e3eda1746de94aa89623e05eeec8c6b1aef9fd Mon Sep 17 00:00:00 2001 From: Burathar Date: Sat, 25 Sep 2021 12:26:23 +0200 Subject: [PATCH] Fix attr checks, and dont create production path before deleting it --- biscd/biscd/models/project.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/biscd/biscd/models/project.py b/biscd/biscd/models/project.py index a4e94e3..0aeefdd 100644 --- a/biscd/biscd/models/project.py +++ b/biscd/biscd/models/project.py @@ -42,11 +42,12 @@ class Project(YamlSerializable): @property def absulute_path(self): - if not hasattr(self, 'production_path') or not self.relative_production_path: + if not hasattr(self, 'relative_production_path') or not self.relative_production_path: return None return Path(config['production_path'].get()) / self.relative_production_path def update(self): + """Update project's local repoistory""" # pylint: disable=no-member self._make_sure_production_path_exists() path = self.absulute_path @@ -77,16 +78,24 @@ class Project(YamlSerializable): return None def delete_files(self): - self._make_sure_production_path_exists() - path = self.absulute_path - app.logger.info(f"Deleting {path}") - rmtree(path) + if self._production_path_exists(): + path = self.absulute_path + app.logger.info(f"Deleting {path}") + rmtree(path) self.relative_production_path = None self.save() + def _production_path_exists(self): + """Return True if project's the production directory path exists""" + prod_path_dir = Path(config['production_path'].get()) + if hasattr(self, 'relative_production_path') and self.relative_production_path: + full_path = prod_path_dir / self.relative_production_path + return full_path.is_dir() + return False + def _make_sure_production_path_exists(self): prod_path_dir = Path(config['production_path'].get()) - if hasattr(self, 'production_path') and self.relative_production_path: + if hasattr(self, 'relative_production_path') and self.relative_production_path: full_path = prod_path_dir / self.relative_production_path if not full_path.is_dir(): full_path.mkdir(parents=True)