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: else:
ddir = directory ddir = directory
try: os.makedirs(ddir, exist_ok=True)
os.makedirs(ddir)
except FileExistsError:
pass
return ddir return ddir
@ -692,9 +689,7 @@ class AbstractDownloadItem(QObject):
global last_used_directory global last_used_directory
try: try:
os.makedirs(os.path.dirname(self._filename)) os.makedirs(os.path.dirname(self._filename), exist_ok=True)
except FileExistsError:
pass
except OSError as e: except OSError as e:
self._die(e.strerror) self._die(e.strerror)

View File

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

View File

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

View File

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