From 09a546891f49b17bf4a0129b0836107b165a83d3 Mon Sep 17 00:00:00 2001 From: Steve Martinelli <stevemar@ca.ibm.com> Date: Tue, 9 Sep 2014 21:26:47 -0400 Subject: [PATCH] Add support for 'file' format objects Some objects can be saved as 'dirname/filename' which causes the existing support to fail. The correct behaviour should be to create the directories needed. Change-Id: I71c61bc3b0f76a3e6d2703bd45508f9d6483546e --- openstackclient/object/v1/lib/object.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/openstackclient/object/v1/lib/object.py b/openstackclient/object/v1/lib/object.py index 38b3c14ec7..7a23fc7698 100644 --- a/openstackclient/object/v1/lib/object.py +++ b/openstackclient/object/v1/lib/object.py @@ -16,6 +16,8 @@ """Object v1 API library""" +import os + import six try: @@ -171,6 +173,8 @@ def save_object( response = session.get("%s/%s/%s" % (url, container, obj), stream=True) if response.status_code == 200: + if not os.path.exists(os.path.dirname(file)): + os.makedirs(os.path.dirname(file)) with open(file, 'wb') as f: for chunk in response.iter_content(): f.write(chunk)