|
9 | 9 |
|
10 | 10 |
|
11 | 11 | import os
|
| 12 | +import sys |
12 | 13 | import urllib2
|
13 |
| -from urlparse import urlparse |
| 14 | +import urlparse |
14 | 15 | import optparse
|
15 |
| -import tarfile |
16 | 16 | import string
|
| 17 | +import subprocess |
17 | 18 |
|
18 | 19 |
|
19 |
| -repo_root = 'http://github.com/mikhailberis/cpp-netlib/' |
20 |
| -stage = '/tmp' |
21 |
| -branch = '0.6-devel' |
22 |
| - |
| 20 | +# |
| 21 | +# Some constants |
| 22 | +# |
| 23 | +repo_root = "http://github.com/mikhailberis/cpp-netlib/" |
| 24 | +branch = "0.6-devel" |
| 25 | +boost_minimum_version = "1_40" |
23 | 26 |
|
24 | 27 |
|
25 | 28 | def check_boost_installation():
|
26 | 29 | """ Gets information about the user's boost environment. """
|
27 | 30 |
|
28 |
| - env = os.getenv('BOOST_ROOT') |
| 31 | + env = os.getenv("BOOST_ROOT") |
29 | 32 | assert(env is not None)
|
30 | 33 |
|
31 | 34 | # get boost version from version.hpp
|
32 | 35 | version = None
|
33 |
| - version_hpp = os.path.join(env, 'boost', 'version.hpp') |
34 |
| - f = open(version_hpp) |
| 36 | + version_hpp = os.path.join(env, "boost", "version.hpp") |
| 37 | + f = open(version_hpp, "r") |
35 | 38 | for line in f:
|
36 |
| - if line.startswith('#define BOOST_LIB_VERSION'): |
| 39 | + if line.startswith("#define BOOST_LIB_VERSION"): |
37 | 40 | begin = string.find(line, '"')
|
38 | 41 | end = string.rfind(line, '"')
|
39 | 42 | version = line[begin + 1:end]
|
| 43 | + break |
| 44 | + |
| 45 | + class Params: pass |
| 46 | + params = Params() |
| 47 | + params.root = env |
| 48 | + params.version = version |
| 49 | + return params |
| 50 | + |
| 51 | + |
| 52 | +def build(bjam, user_config=None): |
| 53 | + """ """ |
40 | 54 |
|
41 |
| - assert(version is not None) |
| 55 | + if bjam is None: |
| 56 | + bjam = "bjam" |
42 | 57 |
|
43 |
| - return {'root': env, |
44 |
| - 'version': version } |
| 58 | + results = open("results.txt", "w+") |
| 59 | + rc = subprocess.call(bjam, stdout=results, stderr=results) |
45 | 60 |
|
46 | 61 |
|
47 |
| -def download_tarball(): |
| 62 | +def download_tarball(stage): |
48 | 63 | """ 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] |
| 64 | + |
| 65 | + r = urllib2.urlopen(repo_root + "tarball/" + branch) |
| 66 | + filename = urlparse.urlparse(r.geturl()).path.split("/")[-1] |
53 | 67 | path = os.path.join(stage, filename)
|
54 |
| - f = open(path, 'w+') |
| 68 | + f = open(path, "w+") |
55 | 69 | f.write(r.read())
|
56 | 70 | return filename
|
57 | 71 |
|
58 | 72 | def unpack_tarball(stage, filename):
|
59 | 73 | """ Unpacks the tarball into a stage directory. """
|
60 | 74 |
|
| 75 | + import tarfile |
| 76 | + import shutil |
| 77 | + |
| 78 | + (root, ext) = os.path.splitext(filename) |
| 79 | + (root, ext) = os.path.splitext(root) |
| 80 | + if os.path.exists(os.path.join(stage, root)): |
| 81 | + shutil.rmtree(os.path.join(stage, root)) |
| 82 | + |
61 | 83 | os.chdir(stage)
|
62 | 84 | f = tarfile.open(os.path.join(stage, filename))
|
63 | 85 | f.extractall()
|
64 |
| - (root, ext) = os.path.splitext(filename) |
65 |
| - print(root) |
66 | 86 | os.chdir(root)
|
67 | 87 |
|
68 | 88 |
|
69 |
| -def download_zipball(): |
| 89 | +def download_zipball(stage): |
70 | 90 | """ Downloads the latest zipfile from the mikhailberis fork. """
|
71 | 91 |
|
72 |
| - r = urllib2.urlopen(repo_root + '/zipball/' + branch) |
73 |
| - filename = urlparse(r.geturl()).path.split('/')[-1] |
| 92 | + r = urllib2.urlopen(repo_root + "zipball/" + branch) |
| 93 | + filename = urlparse.urlparse(r.geturl()).path.split("/")[-1] |
74 | 94 | path = os.path.join(stage, filename)
|
75 |
| - f = open(path, 'w+') |
| 95 | + f = open(path, "w+") |
76 | 96 | f.write(r.read())
|
77 | 97 | return filename
|
78 | 98 |
|
79 | 99 | def unpack_zipball(stage, filename):
|
80 | 100 | """ Unpacks the zip file into a stage directory. """
|
81 | 101 |
|
82 |
| - f = zipfile.ZipFile(os.path.join(stage, filename)) |
83 |
| - f.extractall() |
84 |
| - |
| 102 | + import zipfile |
| 103 | + import shutil |
85 | 104 |
|
86 |
| -def build(): |
87 |
| - """ Invokes bjam. Runs all unit tests. """ |
88 |
| - |
89 |
| - # Somehow we have to report any failures |
| 105 | + (root, ext) = os.path.splitext(filename) |
| 106 | + (root, ext) = os.path.splitext(root) |
| 107 | + if os.path.exists(os.path.join(stage, root)): |
| 108 | + shutil.rmtree(os.path.join(stage, root)) |
90 | 109 |
|
| 110 | + os.chdir(stage) |
| 111 | + f = zipfile.ZipFile(os.path.join(stage, filename)) |
| 112 | + f.extractall() |
| 113 | + os.chdir(root) |
91 | 114 |
|
92 |
| -if __name__ == '__main__': |
93 | 115 |
|
94 |
| - params = check_boost_installation() |
95 |
| - print(params) |
| 116 | +if __name__ == "__main__": |
| 117 | + |
| 118 | + opt = optparse.OptionParser( |
| 119 | + usage="%prog [options]") |
| 120 | + |
| 121 | + opt.add_option("--zip", |
| 122 | + action="store_false", |
| 123 | + help="Downloads the zip file.") |
| 124 | + opt.add_option("--tar", |
| 125 | + action="store_false", |
| 126 | + help="Downloads the tar.gz file.") |
| 127 | + opt.add_option("--stage", |
| 128 | + metavar="DIR", |
| 129 | + help="the stage directory.") |
| 130 | + opt.add_option("--branch", |
| 131 | + help="the Git branch to check.") |
| 132 | + opt.add_option("--bjam", |
| 133 | + help="The path to the bjam binary if it's not in the system path.") |
| 134 | + opt.add_option("--user-config", |
| 135 | + metavar="FILE", |
| 136 | + help="the user-config file to use.") |
96 | 137 |
|
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) |
| 138 | + (opts, args) = opt.parse_args() |
| 139 | + |
| 140 | + if (opts.zip is None and opts.tar is None) or \ |
| 141 | + (opts.zip is not None and opts.tar is not None): |
| 142 | + print("Please specify either zip or tar") |
| 143 | + sys.exit(-1) |
| 144 | + |
| 145 | + if opts.stage is None: |
| 146 | + opts.stage = "/tmp" |
| 147 | + print("stage: %s" % opts.stage) |
| 148 | + |
| 149 | + boost_params = check_boost_installation() |
| 150 | + assert(boost_params.version is not None) |
| 151 | + assert(boost_params.version > boost_minimum_version) |
| 152 | + print("boost_root: %s" % boost_params.root) |
| 153 | + print("boost_version: %s" % boost_params.version) |
| 154 | + |
| 155 | + try: |
| 156 | + if opts.zip is not None: |
| 157 | + filename = download_zipball(opts.stage) |
| 158 | + unpack_zipball(opts.stage, filename) |
| 159 | + elif opts.tar is not None: |
| 160 | + filename = download_tarball(opts.stage) |
| 161 | + unpack_tarball(opts.stage, filename) |
| 162 | + |
| 163 | + build(opts.bjam, opts.user_config) |
| 164 | + |
| 165 | + except Exception, e: |
| 166 | + print(e) |
0 commit comments