mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
utils: Handle exceptions in context management for YAMLFile
When an exception is raised within the context, the YAML file should not written. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
1 parent
df76e6afa4
commit
d3bdaf0729
2 files changed
+14
-3
No files matched your search
+4
-3
@@ -108,9 +108,10 @@ class YAMLFile(object):
|
||||
|
||||
return self.conf
|
||||
|
||||
def __exit__(self, typ, value, traceback):
|
||||
with open(self.yaml_file, 'w') as intro_conf:
|
||||
ruamel.yaml.round_trip_dump(self.conf, intro_conf)
|
||||
def __exit__(self, type_, value, traceback):
|
||||
if not traceback:
|
||||
with open(self.yaml_file, 'w') as intro_conf:
|
||||
ruamel.yaml.round_trip_dump(self.conf, intro_conf)
|
||||
|
||||
def is_file_empty(self):
|
||||
return os.stat(self.yaml_file).st_size == 0
|
||||
|
||||
Reference in new issue
Block a user