|
| 1 | +# Copyright (c) Glyn Matthews 2010. |
| 2 | +# Distributed under the Boost Software License, Version 1.0. |
| 3 | +# (See accompanying file LICENSE_1_0.txt or copy at |
| 4 | +# http://www.boost.org/LICENSE_1_0.txt) |
| 5 | +# |
| 6 | +# This script downloads either a tarball or zipfile of the latest version of the |
| 7 | +# main repo. |
| 8 | +# |
| 9 | + |
| 10 | + |
| 11 | +import os |
| 12 | +import urllib2 |
| 13 | +from urlparse import urlparse |
| 14 | +import optparse |
| 15 | +import tarfile |
| 16 | +import string |
| 17 | + |
| 18 | + |
| 19 | +repo_root = 'http://github.com/mikhailberis/cpp-netlib/' |
| 20 | +stage = '/tmp' |
| 21 | +branch = '0.6-devel' |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | +def check_boost_installation(): |
| 26 | + """ Gets information about the user's boost environment. """ |
| 27 | + |
| 28 | + env = os.getenv('BOOST_ROOT') |
| 29 | + assert(env is not None) |
| 30 | + |
| 31 | + # get boost version from version.hpp |
| 32 | + version = None |
| 33 | + version_hpp = os.path.join(env, 'boost', 'version.hpp') |
| 34 | + f = open(version_hpp) |
| 35 | + for line in f: |
| 36 | + if line.startswith('#define BOOST_LIB_VERSION'): |
| 37 | + begin = string.find(line, '"') |
| 38 | + end = string.rfind(line, '"') |
| 39 | + version = line[begin + 1:end] |
| 40 | + |
| 41 | + assert(version is not None) |
| 42 | + |
| 43 | + return {'root': env, |
| 44 | + 'version': version } |
| 45 | + |
| 46 | + |
| 47 | +def download_tarball(): |
| 48 | + """ Downloads the latest tarball from the mikhailberis fork. """ |
| 49 | + |
| 50 | + print repo_root + 'tarball/' + branch |
| 51 | + r = urllib2.urlopen(repo_root + 'tarball/' + branch) |
| 52 | + filename = urlparse(r.geturl()).path.split('/')[-1] |
| 53 | + path = os.path.join(stage, filename) |
| 54 | + f = open(path, 'w+') |
| 55 | + f.write(r.read()) |
| 56 | + return filename |
| 57 | + |
| 58 | +def unpack_tarball(stage, filename): |
| 59 | + """ Unpacks the tarball into a stage directory. """ |
| 60 | + |
| 61 | + os.chdir(stage) |
| 62 | + f = tarfile.open(os.path.join(stage, filename)) |
| 63 | + f.extractall() |
| 64 | + (root, ext) = os.path.splitext(filename) |
| 65 | + print(root) |
| 66 | + os.chdir(root) |
| 67 | + |
| 68 | + |
| 69 | +def download_zipball(): |
| 70 | + """ Downloads the latest zipfile from the mikhailberis fork. """ |
| 71 | + |
| 72 | + r = urllib2.urlopen(repo_root + '/zipball/' + branch) |
| 73 | + filename = urlparse(r.geturl()).path.split('/')[-1] |
| 74 | + path = os.path.join(stage, filename) |
| 75 | + f = open(path, 'w+') |
| 76 | + f.write(r.read()) |
| 77 | + return filename |
| 78 | + |
| 79 | +def unpack_zipball(stage, filename): |
| 80 | + """ Unpacks the zip file into a stage directory. """ |
| 81 | + |
| 82 | + f = zipfile.ZipFile(os.path.join(stage, filename)) |
| 83 | + f.extractall() |
| 84 | + |
| 85 | + |
| 86 | +def build(): |
| 87 | + """ Invokes bjam. Runs all unit tests. """ |
| 88 | + |
| 89 | + # Somehow we have to report any failures |
| 90 | + |
| 91 | + |
| 92 | +if __name__ == '__main__': |
| 93 | + |
| 94 | + params = check_boost_installation() |
| 95 | + print(params) |
| 96 | + |
| 97 | + # try: |
| 98 | + # opt = optparse.OptionParser( |
| 99 | + # usage="%prog [options]") |
| 100 | + # |
| 101 | + # opt.add_option('--zip', |
| 102 | + # help='uses the zip') |
| 103 | + # opt.add_option('--tar', |
| 104 | + # help='uses the tar.gz') |
| 105 | + # opt.add_option('--stage', |
| 106 | + # help='the stage directory') |
| 107 | + # opt.add_option('--branch', |
| 108 | + # help='the branch to check.') |
| 109 | + # |
| 110 | + # opt.parse_args() |
| 111 | + # |
| 112 | + # |
| 113 | + # filename = download_tarball() |
| 114 | + # print(filename) |
| 115 | + # unpack_tarball(stage, filename) |
| 116 | + # |
| 117 | + # except urllib2.URLError, e: |
| 118 | + # print('%s' % e) |
0 commit comments