blob: dfb8658053545af5ed9a2e21386e0beb3185ec7e [file] [log] [blame]
# Copyright (C) PyZMQ Developers
# Distributed under the terms of the Modified BSD License.
# This bundling code is largely adapted from pyzmq-static's by
# Brandon Craig-Rhodes, which is itself BSD licensed.
# This bundling code is largely adapted from pyzmq's code
# PyZMQ Developers, which is itself Modified BSD licensed.
import os
import shutil
import stat
import sys
import tarfile
from glob import glob
from subprocess import Popen, PIPE
# py2
from urllib2 import urlopen
except ImportError:
# py3
from urllib.request import urlopen
from . import log
# Constants
min_qpid_proton = (0, 14, 0)
min_qpid_proton_str = "%i.%i.%i" % min_qpid_proton
bundled_version = (0, 14, 1)
bundled_version_str = "%i.%i.%i" % bundled_version
libqpid_proton = "qpid-proton-%s.tar.gz" % bundled_version_str
libqpid_proton_url = ("" %
(bundled_version_str, libqpid_proton))
HERE = os.path.dirname(__file__)
ROOT = os.path.dirname(HERE)
def fetch_archive(savedir, url, fname):
"""Download an archive to a specific location
:param savedir: Destination dir
:param url: URL where the archive should be downloaded from
:param fname: Archive's filename
dest = os.path.join(savedir, fname)
if os.path.exists(dest):"already have %s" % fname)
return dest"fetching %s into %s" % (url, savedir))
if not os.path.exists(savedir):
req = urlopen(url)
with open(dest, 'wb') as f:
return dest
def fetch_libqpid_proton(savedir):
"""Download qpid-proton to `savedir`."""
def _c_only(members):
# just extract the files necessary to build the shared library
for tarinfo in members:
npath = os.path.normpath(
if ("proton-c/src" in npath or
"proton-c/include" in npath or
"proton-c/mllib" in npath):
yield tarinfo
dest = os.path.join(savedir, 'qpid-proton')
if os.path.exists(dest):"already have %s" % dest)
fname = fetch_archive(savedir, libqpid_proton_url, libqpid_proton)
tf =
member = tf.firstmember.path
if member == '.':
member = tf.getmembers()[1].path
with_version = os.path.join(savedir, member)
tf.extractall(savedir, members=_c_only(tf))
shutil.move(with_version, dest)