Browse Source

Simplify save method

master
Burathar 3 years ago
parent
commit
c68f3b6b57
  1. 20
      biscd/biscd/models/yaml_serializable.py

20
biscd/biscd/models/yaml_serializable.py

@ -40,18 +40,14 @@ class YamlSerializable(RecursiveProperty):
if self.name is None: if self.name is None:
raise TypeError("Name cannot be None") raise TypeError("Name cannot be None")
ymlsls = self._get_all_from_file() ymlsls = self._get_all_from_file()
found_match = False ymlsl = next((ymlsl for ymlsl in ymlsls if [*ymlsl][0] == self.name), None)
for ymlsl in ymlsls: if ymlsl:
if self.name == [*ymlsl][0]: if overwrite:
found_match = True ymlsl[self.name] = self.config_dict(values_only=True)
if overwrite: else:
ymlsl[self.name] = self.config_dict(values_only=True) raise ValueError(
else: f"A {type(self).__name__} with name {self.name} already exists!")
raise ValueError( else:
f"A {type(self).__name__} with name {self.name} already exists!")
break
if not found_match:
ymlsls.append(self.config_dict()) ymlsls.append(self.config_dict())
print(ymlsls) print(ymlsls)
self._save_all_to_file(ymlsls) self._save_all_to_file(ymlsls)

Loading…
Cancel
Save