From 5c1dc0006fdde769aa068142b5f2f81dbae85f18 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Thu, 5 Jul 2018 12:24:36 +0200 Subject: config: Stop using os.path to split pathlib.Path objects. --- poezio/config.py | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'poezio/config.py') diff --git a/poezio/config.py b/poezio/config.py index 0c7eaf96..f7d73164 100644 --- a/poezio/config.py +++ b/poezio/config.py @@ -19,7 +19,7 @@ import sys import pkg_resources from configparser import RawConfigParser, NoOptionError, NoSectionError -from os import path, remove +from os import remove from shutil import copy2 from pathlib import Path from poezio.args import parse_args @@ -338,19 +338,17 @@ class Config(RawConfigParser): before copying it to the final destination """ try: - prefix, file = path.split(self.file_name) - filename = path.join(prefix, '.%s.tmp' % file) - fd = os.fdopen( - os.open( - filename, - os.O_WRONLY | os.O_CREAT, - 0o600, - ), - 'w', - encoding='utf-8') - for line in lines: - fd.write('%s\n' % line) - fd.close() + filename = self.file_name.parent / ('.%s.tmp' % self.file_name.name) + with os.fdopen( + os.open( + filename, + os.O_WRONLY | os.O_CREAT, + 0o600, + ), + 'w', + encoding='utf-8') as fd: + for line in lines: + fd.write('%s\n' % line) copy2(filename, self.file_name) remove(filename) except: @@ -501,7 +499,7 @@ def file_ok(filepath): Returns True if the file exists and is readable and writeable, False otherwise. """ - val = path.exists(filepath) + val = filepath.exists() val &= os.access(filepath, os.R_OK | os.W_OK) return bool(val) -- cgit v1.2.3