Use exist_ok=True for os.path.makedirs

See #2570
This commit is contained in:
Florian Bruhin 2018-08-07 16:26:41 +02:00
parent 254b185385
commit 1cb547a8de
4 changed files with 5 additions and 15 deletions

View File

@ -79,10 +79,7 @@ def download_dir():
else:
ddir = directory
try:
os.makedirs(ddir)
except FileExistsError:
pass
os.makedirs(ddir, exist_ok=True)
return ddir
@ -692,9 +689,7 @@ class AbstractDownloadItem(QObject):
global last_used_directory
try:
os.makedirs(os.path.dirname(self._filename))
except FileExistsError:
pass
os.makedirs(os.path.dirname(self._filename), exist_ok=True)
except OSError as e:
self._die(e.strerror)

View File

@ -240,8 +240,7 @@ class BookmarkManager(UrlMarkManager):
def _init_lineparser(self):
bookmarks_directory = os.path.join(standarddir.config(), 'bookmarks')
if not os.path.isdir(bookmarks_directory):
os.makedirs(bookmarks_directory)
os.makedirs(bookmarks_directory, exist_ok=True)
bookmarks_subdir = os.path.join('bookmarks', 'urls')
self._lineparser = lineparser.LineParser(

View File

@ -72,8 +72,7 @@ class BaseLineParser(QObject):
Return:
True if the file should be saved, False otherwise.
"""
if not os.path.exists(self._configdir):
os.makedirs(self._configdir, 0o755)
os.makedirs(self._configdir, 0o755, exist_ok=True)
return True
def _after_save(self):

View File

@ -290,10 +290,7 @@ def _create(path):
0700. If the destination directory exists already the permissions
should not be changed.
"""
try:
os.makedirs(path, 0o700)
except FileExistsError:
pass
os.makedirs(path, 0o700, exist_ok=True)
def _init_dirs(args=None):