firstly write config in a temporary file to avoid corruption
This commit is contained in:
parent
0b71ddfdcf
commit
907973a041
1 changed files with 11 additions and 2 deletions
|
|
@ -18,6 +18,9 @@
|
||||||
|
|
||||||
from __future__ import with_statement
|
from __future__ import with_statement
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import tempfile
|
||||||
import logging
|
import logging
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
|
@ -47,8 +50,14 @@ class YamlConfig(IConfig):
|
||||||
self.values = {}
|
self.values = {}
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
with open(self.path, 'w') as f:
|
if sys.version_info[:2] <= (2, 5):
|
||||||
yaml.dump(self.values, f)
|
with open(self.path, 'w') as f:
|
||||||
|
yaml.dump(self.values, f)
|
||||||
|
else:
|
||||||
|
# write in a temporary file to avoid corruption problems
|
||||||
|
with tempfile.NamedTemporaryFile(delete=False) as f:
|
||||||
|
yaml.dump(self.values, f)
|
||||||
|
os.rename(f.name, self.path)
|
||||||
|
|
||||||
def get(self, *args, **kwargs):
|
def get(self, *args, **kwargs):
|
||||||
default = None
|
default = None
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue