Use NamedTemporaryFile(delete=False) instead of mkstemp
This commit is contained in:
parent
c193cae3b9
commit
fd5901b00e
2 changed files with 4 additions and 8 deletions
|
|
@ -66,8 +66,7 @@ class WebContentEdit(ReplApplication):
|
||||||
tmpdir = os.path.join(tempfile.gettempdir(), "weboob")
|
tmpdir = os.path.join(tempfile.gettempdir(), "weboob")
|
||||||
if not os.path.isdir(tmpdir):
|
if not os.path.isdir(tmpdir):
|
||||||
os.makedirs(tmpdir)
|
os.makedirs(tmpdir)
|
||||||
fd, path = tempfile.mkstemp(prefix='%s_' % content.id.replace(os.path.sep, '_'), dir=tmpdir)
|
with tempfile.NamedTemporaryFile(prefix='%s_' % content.id.replace(os.path.sep, '_'), dir=tmpdir, delete=False) as f:
|
||||||
with os.fdopen(fd, 'w') as f:
|
|
||||||
data = content.content
|
data = content.content
|
||||||
if isinstance(data, unicode):
|
if isinstance(data, unicode):
|
||||||
data = data.encode('utf-8')
|
data = data.encode('utf-8')
|
||||||
|
|
@ -75,7 +74,7 @@ class WebContentEdit(ReplApplication):
|
||||||
content.content = u''
|
content.content = u''
|
||||||
data = ''
|
data = ''
|
||||||
f.write(data)
|
f.write(data)
|
||||||
paths[path.encode('utf-8')] = content
|
paths[f.name.encode('utf-8')] = content
|
||||||
|
|
||||||
params = ''
|
params = ''
|
||||||
editor = os.environ.get('EDITOR', 'vim')
|
editor = os.environ.get('EDITOR', 'vim')
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,6 @@
|
||||||
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
import logging
|
import logging
|
||||||
|
|
@ -60,10 +58,9 @@ class YamlConfig(IConfig):
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
# write in a temporary file to avoid corruption problems
|
# write in a temporary file to avoid corruption problems
|
||||||
fd, path = tempfile.mkstemp(dir=os.path.dirname(self.path))
|
with tempfile.NamedTemporaryFile(dir=os.path.dirname(self.path), delete=False) as f:
|
||||||
with os.fdopen(fd, 'w') as f:
|
|
||||||
yaml.dump(self.values, f, Dumper=Dumper)
|
yaml.dump(self.values, f, Dumper=Dumper)
|
||||||
os.rename(path, self.path)
|
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