From eb23cf5992c4c169343cad64c308be1921e7908d Mon Sep 17 00:00:00 2001 From: Joshua Hesketh Date: Thu, 3 Jul 2014 11:46:00 +1000 Subject: [PATCH] Fix magic in zuul_swift_upload It turns out there are two implementations of libmagic for python. PyPI has a wrapper (https://github.com/ahupp/python-magic) and ubuntu packages the bindings from (https://github.com/file/file). Update zuul_swift_upload to try the wrapper first and fall back to the bindings. If both don't work an exception should be raised. Change-Id: I248163d610b074c6de8a6408a6c458d3198d18cc --- .../files/slave_scripts/zuul_swift_upload.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/openstack_project/files/slave_scripts/zuul_swift_upload.py b/modules/openstack_project/files/slave_scripts/zuul_swift_upload.py index 8f5d0c3fbd..dbe8993b14 100755 --- a/modules/openstack_project/files/slave_scripts/zuul_swift_upload.py +++ b/modules/openstack_project/files/slave_scripts/zuul_swift_upload.py @@ -78,8 +78,16 @@ def swift_form_post_submit(file_list, url, hmac_body, signature): files = {} for i, f in enumerate(file_list): + try: + file_mime = magic.from_file(f['path'], mime=True) + except AttributeError: + # no magic.from_file, we might be using the libmagic bindings + m = magic.open(magic.MIME) + m.load() + file_mime = m.file(f['path']).split(';')[0] + files['file%d' % (i + 1)] = (f['filename'], open(f['path'], 'rb'), - magic.from_file(f['path'], mime=True)) + file_mime) requests.post(url, data=payload, files=files)