summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorspisarski <s.pisarski@cablelabs.com>2017-06-13 09:16:18 +0800
committerspisarski <s.pisarski@cablelabs.com>2017-06-13 09:16:18 +0800
commit8f681f8dcf0526e2db3d648234f89bf03bcc23df (patch)
tree7f7738772b27adfe079bfd6bacf014672590d1ca
parent0f407db1cc01d8d58e4e0b0f4ecafc69ef1a17a4 (diff)
Create download directory if not exists before downloading image file.
Change-Id: I6d51681d4e0d58b96a00bfeb144d6bfcb8ae04e6 Signed-off-by: spisarski <s.pisarski@cablelabs.com>
-rw-r--r--snaps/file_utils.py8
1 files changed, 7 insertions, 1 deletions
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