3 # A script for unpacking and installing different historic versions of
4 # SCons in a consistent manner for side-by-side development testing.
6 # This abstracts the changes we've made to the SCons setup.py scripts in
7 # different versions so that, no matter what version is specified, it ends
8 # up installing the necessary script(s) and library into version-specific
9 # names that won't interfere with other things.
11 # By default, we expect to extract the .tar.gz files from a Downloads
12 # subdirectory in the current directory.
14 # Note that this script cleans up after itself, removing the extracted
15 # directory in which we do the build.
17 # This was written for a Linux system (specifically Ubuntu) but should
18 # be reasonably generic to any POSIX-style system with a /usr/local
26 from urllib
.request
import urlretrieve
28 from Command
import CommandRunner
, Usage
94 '2.0.0.alpha.20100508',
95 '2.0.0.beta.20100531',
96 '2.0.0.beta.20100605',
105 downloads_dir
= 'Downloads'
106 downloads_url
= 'http://downloads.sourceforge.net/scons'
107 if sys
.platform
== 'win32':
112 prefix
= '/usr/local'
113 python
= sys
.executable
115 short_options
= 'ad:hnp:q'
116 long_options
= ['all', 'help', 'no-exec', 'prefix=', 'quiet']
119 Usage: install_scons.py [-ahnq] [-d DIR] [-p PREFIX] [VERSION ...]
121 -a, --all Install all SCons versions.
122 -d DIR, --downloads=DIR Downloads directory.
123 -h, --help Print this help and exit
124 -n, --no-exec No execute, just print command lines
125 -p PREFIX, --prefix=PREFIX Installation prefix.
126 -q, --quiet Quiet, don't print command lines
131 opts
, args
= getopt
.getopt(argv
[1:], short_options
, long_options
)
132 except getopt
.error
as msg
:
136 if o
in ('-a', '--all'):
138 elif o
in ('-d', '--downloads'):
140 elif o
in ('-h', '--help'):
143 elif o
in ('-n', '--no-exec'):
144 CommandRunner
.execute
= CommandRunner
.do_not_execute
145 elif o
in ('-p', '--prefix'):
147 elif o
in ('-q', '--quiet'):
148 CommandRunner
.display
= CommandRunner
.do_not_display
150 sys
.stderr
.write(str(err
.msg
) + '\n')
151 sys
.stderr
.write('use -h to get help\n')
156 msg
= 'install-scons.py: -a and version arguments both specified'
157 sys
.stderr
.write(msg
)
162 cmd
= CommandRunner()
165 scons
= 'scons-' + version
166 tar_gz
= os
.path
.join(downloads_dir
, scons
+ '.tar.gz')
167 tar_gz_url
= "%s/%s.tar.gz" % (downloads_url
, scons
)
169 cmd
.subst_dictionary(locals())
171 if not os
.path
.exists(tar_gz
):
172 if not os
.path
.exists(downloads_dir
):
173 cmd
.run('mkdir %(downloads_dir)s')
174 cmd
.run((urlretrieve
, tar_gz_url
, tar_gz
),
175 'wget -O %(tar_gz)s %(tar_gz_url)s')
178 tarfile
.open(tar_gz
, "r:gz").extractall()
179 cmd
.run((extract
, tar_gz
), 'tar zxf %(tar_gz)s')
181 cmd
.run('cd %(scons)s')
183 if version
in ('0.01', '0.02', '0.03', '0.04', '0.05',
184 '0.06', '0.07', '0.08', '0.09', '0.10'):
186 # 0.01 through 0.10 install /usr/local/bin/scons and
187 # /usr/local/lib/scons. The "scons" script knows how to
188 # look up the library in a version-specific directory, but
189 # we have to move both it and the library directory into
190 # the right version-specific name by hand.
191 cmd
.run('%(python)s setup.py build')
192 cmd
.run('%(sudo)s %(python)s setup.py install --prefix=%(prefix)s')
193 cmd
.run('%(sudo)s mv %(prefix)s/bin/scons %(prefix)s/bin/scons-%(version)s')
194 cmd
.run('%(sudo)s mv %(prefix)s/lib/scons %(prefix)s/lib/scons-%(version)s')
196 elif version
in ('0.11', '0.12', '0.13', '0.14', '0.90'):
198 # 0.11 through 0.90 install /usr/local/bin/scons and
199 # /usr/local/lib/scons-%(version)s. We just need to move
200 # the script to a version-specific name.
201 cmd
.run('%(python)s setup.py build')
202 cmd
.run('%(sudo)s %(python)s setup.py install --prefix=%(prefix)s')
203 cmd
.run('%(sudo)s mv %(prefix)s/bin/scons %(prefix)s/bin/scons-%(version)s')
205 elif version
in ('0.91', '0.92', '0.93',
208 '0.96', '0.96.1', '0.96.90'):
210 # 0.91 through 0.96.90 install /usr/local/bin/scons,
211 # /usr/local/bin/sconsign and /usr/local/lib/scons-%(version)s.
212 # We need to move both scripts to version-specific names.
213 cmd
.run('%(python)s setup.py build')
214 cmd
.run('%(sudo)s %(python)s setup.py install --prefix=%(prefix)s')
215 cmd
.run('%(sudo)s mv %(prefix)s/bin/scons %(prefix)s/bin/scons-%(version)s')
216 cmd
.run('%(sudo)s mv %(prefix)s/bin/sconsign %(prefix)s/bin/sconsign-%(version)s')
217 lib_scons
= os
.path
.join(prefix
, 'lib', 'scons')
218 if os
.path
.isdir(lib_scons
):
219 cmd
.run('%(sudo)s mv %(prefix)s/lib/scons %(prefix)s/lib/scons-%(version)s')
223 # Versions from 0.96.91 and later support what we want
224 # with a --no-scons-script option.
225 cmd
.run('%(python)s setup.py build')
226 cmd
.run('%(sudo)s %(python)s setup.py install --prefix=%(prefix)s --no-scons-script')
230 cmd
.run((shutil
.rmtree
, scons
), 'rm -rf %(scons)s')
232 if __name__
== "__main__":
237 # indent-tabs-mode:nil
239 # vim: set expandtab tabstop=4 shiftwidth=4: