forked from NCAR/lrose-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_src_release.py
executable file
·288 lines (218 loc) · 7.82 KB
/
build_src_release.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#!/usr/bin/env python
#===========================================================================
#
# Build and install binaries from a src release
# Should be run from within the untarred directory
#
#===========================================================================
import os
import sys
import shutil
import subprocess
from optparse import OptionParser
import time
from datetime import datetime
from datetime import date
from datetime import timedelta
import glob
from sys import platform
def main():
# globals
global thisScriptName
thisScriptName = os.path.basename(__file__)
global options
global runDir
global installDir
global dateStr
global timeStr
global debugStr
global releaseName
global package
global version
global srcRelease
global ostype
# parse the command line
usage = "usage: %prog [options]"
homeDir = os.environ['HOME']
prefixDefault = '/usr/local/lrose'
parser = OptionParser(usage)
parser.add_option('--debug',
dest='debug', default=False,
action="store_true",
help='Set debugging on')
parser.add_option('--verbose',
dest='verbose', default=False,
action="store_true",
help='Set verbose debugging on')
parser.add_option('--prefix',
dest='prefix', default=prefixDefault,
help='Directory for installation')
parser.add_option('--scripts',
dest='installScripts', default=False,
action="store_true",
help='Install scripts as well as binaries')
(options, args) = parser.parse_args()
if (options.verbose):
options.debug = True
debugStr = " "
if (options.verbose):
debugStr = " --verbose "
elif (options.debug):
debugStr = " --debug "
installDir = options.prefix
# runtime
now = time.gmtime()
nowTime = datetime(now.tm_year, now.tm_mon, now.tm_mday,
now.tm_hour, now.tm_min, now.tm_sec)
dateStr = nowTime.strftime("%Y%m%d")
timeStr = nowTime.strftime("%Y%m%d%H%M%S")
dateTimeStr = nowTime.strftime("%Y/%m/%d-%H:%M:%S")
runDir = os.getcwd()
# read in release info
readReleaseInfoFile()
# get the OS type - x86_64, i686, macosx_64
getOsType()
# let users know what we are doing
print >>sys.stderr, "****************************************************"
print >>sys.stderr, " Running " + thisScriptName
print >>sys.stderr, ""
print >>sys.stderr, " Building and installing " + package + " release"
print >>sys.stderr, " OS type: " + ostype
print >>sys.stderr, ""
print >>sys.stderr, " NCAR, Boulder, CO, USA"
print >>sys.stderr, ""
print >>sys.stderr, " " + dateTimeStr
print >>sys.stderr, ""
print >>sys.stderr, "****************************************************"
print >>sys.stderr, " dateStr: ", dateStr
print >>sys.stderr, " timeStr: ", timeStr
print >>sys.stderr, " platform: ", platform
print >>sys.stderr, " runDir: ", runDir
print >>sys.stderr, " installDir: ", installDir
print >>sys.stderr, " package: ", package
print >>sys.stderr, " version: ", version
print >>sys.stderr, " srcRelease: ", srcRelease
print >>sys.stderr, " installScripts: ", options.installScripts
print >>sys.stderr, "****************************************************"
# create the install dir
if (os.path.isdir(installDir) == False):
os.makedirs(installDir)
# build netcdf support
if (platform != "darwin"):
buildNetcdf()
# build and install the package
buildPackage()
#--------------------------------------------------------------------
# done
print(" **************************************************")
print(" *** Done building and installing src release ***")
print(" *** installed in dir: " + installDir + " ***")
print(" **************************************************")
sys.exit(0)
########################################################################
# read release information file
def readReleaseInfoFile():
global package
global version
global srcRelease
package = "unknown"
version = "unknown"
srcRelease = "unknown"
# open info file
releaseInfoPath = "ReleaseInfo.txt"
if (options.verbose):
print >>sys.stderr, "==>> reading info file: ", releaseInfoPath
info = open(releaseInfoPath, 'r')
# read in lines
lines = info.readlines()
# close
info.close()
# decode lines
if (len(lines) < 1):
print >>sys.stderr, "ERROR reading info file: ", releaseInfoPath
print >>sys.stderr, " No contents"
sys.exit(1)
for line in lines:
line = line.strip()
toks = line.split(":")
if (options.verbose):
print >>sys.stderr, " line: ", line
print >>sys.stderr, " toks: ", toks
if (len(toks) == 2):
if (toks[0] == "package"):
package = toks[1]
if (toks[0] == "version"):
version = toks[1]
if (toks[0] == "release"):
srcRelease = toks[1]
if (options.verbose):
print >>sys.stderr, "==>> done reading info file: ", releaseInfoPath
########################################################################
# get the OS type
def getOsType():
global ostype
if (platform == "darwin"):
ostype = "mac_osx"
return
ostype = "x86_64"
tmpFile = os.path.join("/tmp", "ostype." + timeStr + ".txt")
shellCmd("uname -a > " + tmpFile)
f = open(tmpFile, 'r')
lines = f.readlines()
f.close()
if (len(lines) < 1):
print >>sys.stderr, "ERROR getting OS type"
print >>sys.stderr, " 'uname -a' call did not succeed"
sys.exit(1)
for line in lines:
line = line.strip()
if (options.verbose):
print >>sys.stderr, " line: ", line
if (line.find("x86_64") > 0):
ostype = "x86_64"
elif (line.find("i686") > 0):
ostype = "i686"
########################################################################
# build netCDF
def buildNetcdf():
netcdfDir = os.path.join(runDir, "lrose-netcdf")
os.chdir(netcdfDir)
if (package == "lrose-cidd"):
shellCmd("./build_and_install_netcdf.m32 -x " + installDir)
else:
if (platform == "darwin"):
shellCmd("./build_and_install_netcdf.osx -x " + installDir)
else:
shellCmd("./build_and_install_netcdf -x " + installDir)
########################################################################
# build package
def buildPackage():
os.chdir(runDir)
args = ""
args = args + " --prefix " + installDir
args = args + " --package " + package
if (options.installScripts):
args = args + " --scripts "
shellCmd("./build/build_lrose.py " + args)
########################################################################
# Run a command in a shell, wait for it to complete
def shellCmd(cmd):
if (options.debug):
print >>sys.stderr, "running cmd:", cmd, " ....."
try:
retcode = subprocess.check_call(cmd, shell=True)
if retcode != 0:
print >>sys.stderr, "Child exited with code: ", retcode
sys.exit(1)
else:
if (options.verbose):
print >>sys.stderr, "Child returned code: ", retcode
except OSError, e:
print >>sys.stderr, "Execution failed:", e
sys.exit(1)
if (options.debug):
print >>sys.stderr, ".... done"
########################################################################
# Run - entry point
if __name__ == "__main__":
main()