Skip to content

Commit 5f831da

Browse files
committed
Made some updates to the regression script. Still to do: better reporting and testing on Windows.
1 parent 973e29e commit 5f831da

File tree

1 file changed

+105
-57
lines changed

1 file changed

+105
-57
lines changed

libs/network/tools/regression.py

Lines changed: 105 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -9,110 +9,158 @@
99

1010

1111
import os
12+
import sys
1213
import urllib2
13-
from urlparse import urlparse
14+
import urlparse
1415
import optparse
15-
import tarfile
1616
import string
17+
import subprocess
1718

1819

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"
2326

2427

2528
def check_boost_installation():
2629
""" Gets information about the user's boost environment. """
2730

28-
env = os.getenv('BOOST_ROOT')
31+
env = os.getenv("BOOST_ROOT")
2932
assert(env is not None)
3033

3134
# get boost version from version.hpp
3235
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")
3538
for line in f:
36-
if line.startswith('#define BOOST_LIB_VERSION'):
39+
if line.startswith("#define BOOST_LIB_VERSION"):
3740
begin = string.find(line, '"')
3841
end = string.rfind(line, '"')
3942
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+
""" """
4054

41-
assert(version is not None)
55+
if bjam is None:
56+
bjam = "bjam"
4257

43-
return {'root': env,
44-
'version': version }
58+
results = open("results.txt", "w+")
59+
rc = subprocess.call(bjam, stdout=results, stderr=results)
4560

4661

47-
def download_tarball():
62+
def download_tarball(stage):
4863
""" 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]
5367
path = os.path.join(stage, filename)
54-
f = open(path, 'w+')
68+
f = open(path, "w+")
5569
f.write(r.read())
5670
return filename
5771

5872
def unpack_tarball(stage, filename):
5973
""" Unpacks the tarball into a stage directory. """
6074

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+
6183
os.chdir(stage)
6284
f = tarfile.open(os.path.join(stage, filename))
6385
f.extractall()
64-
(root, ext) = os.path.splitext(filename)
65-
print(root)
6686
os.chdir(root)
6787

6888

69-
def download_zipball():
89+
def download_zipball(stage):
7090
""" Downloads the latest zipfile from the mikhailberis fork. """
7191

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]
7494
path = os.path.join(stage, filename)
75-
f = open(path, 'w+')
95+
f = open(path, "w+")
7696
f.write(r.read())
7797
return filename
7898

7999
def unpack_zipball(stage, filename):
80100
""" Unpacks the zip file into a stage directory. """
81101

82-
f = zipfile.ZipFile(os.path.join(stage, filename))
83-
f.extractall()
84-
102+
import zipfile
103+
import shutil
85104

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))
90109

110+
os.chdir(stage)
111+
f = zipfile.ZipFile(os.path.join(stage, filename))
112+
f.extractall()
113+
os.chdir(root)
91114

92-
if __name__ == '__main__':
93115

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.")
96137

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

Comments
 (0)