Skip to content

Commit

Permalink
perf: use os.makedirs param, exist_ok instead of manually checking …
Browse files Browse the repository at this point in the history
…if the resultant directory exists

Starting from Python 3.2, exist_ok param was added to os.makedirs
this would optimize some code
  • Loading branch information
srevinsaju authored and quozl committed Dec 5, 2020
1 parent f9b2b6c commit 8250c17
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/sugar3/activity/bundlebuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ def build_locale(self):

localedir = os.path.join(self.config.build_dir, 'locale', lang)
mo_path = os.path.join(localedir, 'LC_MESSAGES')
if not os.path.isdir(mo_path):
os.makedirs(mo_path)
os.makedirs(mo_path, exist_ok=True)

mo_file = os.path.join(mo_path, '%s.mo' % self.config.bundle_id)
args = ['msgfmt', '--output-file=%s' % mo_file, file_name]
Expand Down Expand Up @@ -313,8 +312,7 @@ def install(self, destdir, prefix,
print('Install %s' % (dest))

path = os.path.dirname(dest)
if not os.path.exists(path):
os.makedirs(path)
os.makedirs(path, exist_ok=True)

shutil.copy(source, dest)

Expand Down Expand Up @@ -363,8 +361,7 @@ def _install_desktop_file(self, destdir, prefix, activity_path):
name = '{}.activity.desktop'.format(self.config.bundle_id)
path = os.path.join(destdir, os.path.relpath(prefix, '/'),
'share', 'applications', name)
if not os.path.isdir(os.path.dirname(path)):
os.makedirs(os.path.dirname(path))
os.makedirs(os.path.dirname(path), exist_ok=True)
with open(path, 'w') as f:
cp.write(f)
print('Install %s' % (path))
Expand Down Expand Up @@ -423,8 +420,7 @@ def _generate_appdata(self, destdir, prefix, activity_path):
path = os.path.join(destdir, os.path.relpath(prefix, '/'),
'share', 'metainfo',
self.config.bundle_id + '.appdata.xml')
if not os.path.isdir(os.path.dirname(path)):
os.makedirs(os.path.dirname(path))
os.makedirs(os.path.dirname(path), exist_ok=True)
tree = ET.ElementTree(root)
tree.write(path, encoding='UTF-8')
print('Install %s' % (path))
Expand Down

0 comments on commit 8250c17

Please sign in to comment.