|
9 | 9 |
|
10 | 10 |
|
11 | 11 | importos
|
| 12 | +importsys |
12 | 13 | importurllib2
|
13 |
| -fromurlparseimporturlparse |
| 14 | +importurlparse |
14 | 15 | importoptparse
|
15 |
| -importtarfile |
16 | 16 | importstring
|
| 17 | +importsubprocess |
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 | defcheck_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(envisnotNone)
|
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 | forlineinf:
|
36 |
| -ifline.startswith('#define BOOST_LIB_VERSION'): |
| 39 | +ifline.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 | +classParams:pass |
| 46 | +params=Params() |
| 47 | +params.root=env |
| 48 | +params.version=version |
| 49 | +returnparams |
| 50 | + |
| 51 | + |
| 52 | +defbuild(bjam,user_config=None): |
| 53 | +""" """ |
40 | 54 |
|
41 |
| -assert(versionisnotNone) |
| 55 | +ifbjamisNone: |
| 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 |
| -defdownload_tarball(): |
| 62 | +defdownload_tarball(stage): |
48 | 63 | """ Downloads the latest tarball from the mikhailberis fork. """
|
49 |
| - |
50 |
| -printrepo_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 | returnfilename
|
57 | 71 |
|
58 | 72 | defunpack_tarball(stage,filename):
|
59 | 73 | """ Unpacks the tarball into a stage directory. """
|
60 | 74 |
|
| 75 | +importtarfile |
| 76 | +importshutil |
| 77 | + |
| 78 | + (root,ext)=os.path.splitext(filename) |
| 79 | + (root,ext)=os.path.splitext(root) |
| 80 | +ifos.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 |
| -defdownload_zipball(): |
| 89 | +defdownload_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 | returnfilename
|
78 | 98 |
|
79 | 99 | defunpack_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 | +importzipfile |
| 103 | +importshutil |
85 | 104 |
|
86 |
| -defbuild(): |
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 | +ifos.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.zipisNoneandopts.tarisNone)or \ |
| 141 | + (opts.zipisnotNoneandopts.tarisnotNone): |
| 142 | +print("Please specify either zip or tar") |
| 143 | +sys.exit(-1) |
| 144 | + |
| 145 | +ifopts.stageisNone: |
| 146 | +opts.stage="/tmp" |
| 147 | +print("stage: %s"%opts.stage) |
| 148 | + |
| 149 | +boost_params=check_boost_installation() |
| 150 | +assert(boost_params.versionisnotNone) |
| 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 | +ifopts.zipisnotNone: |
| 157 | +filename=download_zipball(opts.stage) |
| 158 | +unpack_zipball(opts.stage,filename) |
| 159 | +elifopts.tarisnotNone: |
| 160 | +filename=download_tarball(opts.stage) |
| 161 | +unpack_tarball(opts.stage,filename) |
| 162 | + |
| 163 | +build(opts.bjam,opts.user_config) |
| 164 | + |
| 165 | +exceptException,e: |
| 166 | +print(e) |