utils/swift/download_container: python3 adjustment
Plan content from swift may need to be encoded if Python 3. Change-Id: Ia2108f3f64e3ae043cd050b5c3748682d0a816de Co-Authored-By: Michele Baldessari <michele@acksyn.org> Co-Authored-By: Alex Schultz <aschultz@redhat.com>
This commit is contained in:
parent
957c9bd514
commit
ebaf337321
@ -64,6 +64,10 @@ def download_container(swiftclient, container, dest,
|
|||||||
is_newer = False
|
is_newer = False
|
||||||
filename = obj['name']
|
filename = obj['name']
|
||||||
contents = swiftclient.get_object(container, filename)[1]
|
contents = swiftclient.get_object(container, filename)[1]
|
||||||
|
try:
|
||||||
|
contents = contents.encode('utf-8')
|
||||||
|
except (UnicodeDecodeError, AttributeError):
|
||||||
|
pass
|
||||||
path = os.path.join(dest, filename)
|
path = os.path.join(dest, filename)
|
||||||
dirname = os.path.dirname(path)
|
dirname = os.path.dirname(path)
|
||||||
already_exists = os.path.exists(path)
|
already_exists = os.path.exists(path)
|
||||||
@ -89,7 +93,9 @@ def download_container(swiftclient, container, dest,
|
|||||||
if not os.path.exists(dirname):
|
if not os.path.exists(dirname):
|
||||||
os.makedirs(dirname)
|
os.makedirs(dirname)
|
||||||
|
|
||||||
with open(path, 'w') as f:
|
# open in binary as the swift client returns error
|
||||||
|
# under python3 if opened as text
|
||||||
|
with open(path, 'wb') as f:
|
||||||
f.write(contents)
|
f.write(contents)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user