From 94253975caf01cfabe3176f0ea08449cbb187c57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Tue, 17 Jan 2017 17:01:37 +0100 Subject: [PATCH] Cleaner way to use os.makedirs() It's not necessary to do an os.path.exists(dst_dir) check before calling os.makedirs(), the exist_ok=True parameter is meant for this common pattern. --- bam/blend/blendfile_pack.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bam/blend/blendfile_pack.py b/bam/blend/blendfile_pack.py index 503e876..a8caa40 100755 --- a/bam/blend/blendfile_pack.py +++ b/bam/blend/blendfile_pack.py @@ -513,10 +513,8 @@ def pack( if (not os.path.exists(src)) or os.path.isdir(src): yield report(" %s: %r\n" % (colorize("source missing", color='red'), src)) else: - dst_dir = os.path.dirname(dst) - if not os.path.exists(dst_dir): - os.makedirs(dst_dir) yield report(" %s: %r -> %r\n" % (colorize("copying", color='blue'), src, dst)) + os.makedirs(os.path.dirname(dst), exist_ok=True) shutil.copy(src, dst) shutil.rmtree(base_dir_dst_temp)