From 8f681f8dcf0526e2db3d648234f89bf03bcc23df Mon Sep 17 00:00:00 2001 From: spisarski Date: Tue, 13 Jun 2017 09:16:18 +0800 Subject: Create download directory if not exists before downloading image file. Change-Id: I6d51681d4e0d58b96a00bfeb144d6bfcb8ae04e6 Signed-off-by: spisarski --- snaps/file_utils.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/snaps/file_utils.py b/snaps/file_utils.py index f7c9af4..a7ed13c 100644 --- a/snaps/file_utils.py +++ b/snaps/file_utils.py @@ -56,9 +56,15 @@ def download(url, dest_path, name=None): logger.debug('Downloading file from - ' + url) # Override proxy settings to use localhost to download file f = None + + if not os.path.isdir(dest_path): + try: + os.mkdir(dest_path) + except: + raise try: with open(dest, 'wb') as f: - logger.debug('Saving file to - ' + dest) + logger.debug('Saving file to - ' + os.path.abspath(f.name)) response = __get_url_response(url) f.write(response.read()) return f -- cgit 1.2.3-korg