source: CMTManagement/cmt_build_binaries@ 689

Last change on this file since 689 was 420, checked in by garonne, 18 years ago
  • Property svn:executable set to *
File size: 7.0 KB
Line 
1#!/usr/bin/env python
2#--------------------------------#
3# Author: V.garonne #
4# Mail: garonne@lal.in2p3.fr #
5# Description: script to build #
6# binaries and the tarball on a #
7# certain host #
8#--------------------------------#
9
10import os, sys, commands, string, glob
11import shutil
12
13def checkPythonVersion (major=1,minor=5):
14 version = float(str(major) +'.'+ str(minor))
15 if string.find(sys.version, '1.5') != -1:
16 thisversion = float(1.5)
17 else:
18 thisversion = float(str(sys.version_info[0]) + '.' + str(sys.version_info[1]))
19 if version > thisversion:
20 # try to find the good python version >= 2.3
21 paths = string.split(os.environ['PATH'],':')
22 print 'hmmm look for the appropriate python version, this one is',\
23 thisversion,'and the required version is python >=', version
24 pythons = []
25 for path in paths:
26 pythons = glob.glob1(path, 'python*')
27 for python in pythons:
28 cmd = python +' -c "import sys; print sys.version"'
29 status, thisversion = commands.getstatusoutput(cmd)
30 if string.find(thisversion, '1.5') != -1:
31 thisversion = float(1.5)
32 else:
33 cmd = python +' -c "import sys; print sys.version_info"'
34 status, thisversion = commands.getstatusoutput(cmd)
35 thisversion = eval (str(thisversion))
36 thisversion = float(str(thisversion[0]) +'.'+ str(thisversion[1]))
37 if (thisversion >= version):
38 print 'found and load', python
39 sys.argv.insert (0, python)
40 os.execvp (python, sys.argv)
41 print 'The appropriate version of python >=' + str(version) + ' is not here, check your PATH variable or install it'
42 sys.exit(-1)
43checkPythonVersion (2,2)
44
45# for package version dependant
46import tarfile
47import urllib
48
49# My own python 'tar -xvzf' in waiting python 2.5...
50def extractall(tarball, path="."):
51 tar = tarfile.open(tarball)
52 directories = []
53 for tarinfo in tar:
54 if tarinfo.isdir():
55 try:
56 os.makedirs(os.path.join(path, tarinfo.name), 0777)
57 except EnvironmentError:
58 pass
59 directories.append(tarinfo)
60 else:
61 tar.extract(tarinfo, path)
62
63 # Reverse sort directories.
64 directories.sort (lambda a, b: cmp(a.name, b.name))
65 directories.reverse()
66
67 # Set correct owner, mtime and filemode on directories.
68 for tarinfo in directories:
69 path = os.path.join(path, tarinfo.name)
70 tar.chown(tarinfo, path)
71 #tar.utime(tarinfo, path)
72 #tar.chmod(tarinfo, path)
73 tar.close()
74
75
76#--------------------# MAIN #-------------------------#
77if __name__ == '__main__':
78
79 # Check arguments
80 checkPythonVersion(2,2)
81 if len(sys.argv) != 3:
82 print sys.arvg[0], '<version>' , '<platform>'
83 sys.exit(-1)
84 else:
85 version = sys.argv[1]
86 platform = sys.argv[2]
87
88 preambule = 'cmt_build_binaries >'
89 tarball = "CMT"+version+".tar.gz"
90 www = "http://www.cmtsite.org"
91 here = os.getcwd()
92
93 # get or untar CMT source tarball
94 if not os.path.exists(tarball):
95 print preambule + 'the CMT tarball is not here'
96 print preambule + 'try to get it from the web site '+ www
97 h = urllib.urlretrieve(www + '/' + version + '/' + tarball, tarball)
98 if not os.path.exists(tarball):
99 print preambule + 'the CMT tarball is still not here'
100 sys.exit(-1)
101
102 # get real platform name
103 if not (platform == 'VisualC' and sys.platform == 'cygwin'):
104 sysname = os.uname() [0]
105 machine = os.uname() [4]
106 platform = sysname + '-' + machine
107 platform = string.replace (platform, ' ','')
108 print preambule,'platform =', platform
109
110 if os.path.exists('CMT'):
111 try:
112 shutil.rmtree('CMT')
113 except:
114 pass
115 print preambule + " untar "+tarball+" source tarball"
116 extractall(tarball=tarball)
117
118
119 # configure, compile and create bin tarball
120 if platform == 'VisualC':
121 f = open ('cmtnmake','w+')
122 content = 'call rlogin.bat\n'
123 content = content + 'cd CMT\\'+version+'\mgr\n'
124 content = content + 'call INSTALL.bat\n'
125 content = content + 'call setup.bat\n'
126 content = content + 'nmake /f nmake\n'
127 f.write (content)
128 f.close()
129 cmd = 'cmd < cmtnmake'
130 else:
131 os.chdir ("CMT/" + version + "/mgr")
132 cmd= 'tcsh -c " ./INSTALL; source setup.csh ;'
133 if sys.platform == 'darwin':
134 cmd = cmd + 'make'
135 elif sys.platform == 'cygwin':
136 cmd = cmd + 'make'
137 elif sys.platform == 'VisualC':
138 cmd = cmd + 'setup.bat;'
139 cmd = cmd + 'nmake /f nmake'
140 else:
141 cmd = cmd + 'gmake STATIC=1'
142 cmd = cmd + '"'
143 print preambule + cmd
144 status, output = commands.getstatusoutput (cmd)
145 print output
146 if platform == 'VisualC':
147 os.remove('cmtnmake')
148
149 print preambule + ' first do the clean up for preparing archive'
150 os.chdir(here)
151 # first do the clean up
152 files = ['cmt_deps', 'last-rebuild', 'CMT_setup.make', 'cmt_dependencies.make']
153 for file in files:
154 if os.path.exists ('CMT/'+version+'/'+platform +'/' + file):
155 if os.path.isdir ('CMT/'+version+'/'+platform +'/' + file):
156 shutil.rmtree ('CMT/'+version+'/'+platform +'/' + file)
157 else:
158 os.remove ('CMT/'+version+'/'+platform +'/' + file)
159
160 if platform =='VisualC':
161 shutil.rmtree ('CMT/'+version+'/'+platform+'/cmt' )
162 else:
163 if os.path.exists ('CMT/'+version+'/'+platform +'/cmt'):
164 os.remove ('CMT/'+version+'/'+platform +'/cmt')
165 os.chdir('CMT/'+version+'/'+platform +'/')
166 os.symlink ('cmt.exe', 'cmt')
167 os.chdir(here)
168 files = glob.glob1('CMT/'+version+'/'+platform, '*.o')
169 for file in files:
170 print preambule + 'remove CMT/'+version+'/'+platform + '/' +file
171 os.remove ('CMT/'+version+'/'+platform + '/' +file)
172
173 print preambule + ' do the tarball for ' + platform
174 namelist = ['mgr', 'src', platform]
175# if platform == 'Linux-i686':
176# os.chdir('CMT/'+version)
177# os.symlink ('Linux-i686', 'Linux-x86_64')
178# os.chdir(here)
179# namelist.append('Linux-x86_64')
180
181 tar = tarfile.open("CMT"+version+platform+".tar.gz", "w:gz")
182 for name in namelist:
183 print preambule + ' add the file ' + name + ' to the bin archive'
184 tar.add(name='CMT/'+version+'/'+ name, arcname='CMT'+'/'+version+'/'+name)
185 tar.close()
186#------------------------------- End of File --------------------------------------#
Note: See TracBrowser for help on using the repository browser.