3 # A script for unpacking and installing different historic versions of
4 # Python in a consistent manner for side-by-side development testing.
6 # This was written for a Linux system (specifically Ubuntu) but should
7 # be reasonably generic to any POSIX-style system with a /usr/local
15 from Command import CommandRunner, Usage
18 #'1.5.2', # no longer available at python.org
33 downloads_dir = 'Downloads'
34 downloads_url = 'http://www.python.org/ftp/python'
38 short_options = 'ad:hnp:q'
39 long_options = ['all', 'help', 'no-exec', 'prefix=', 'quiet']
42 Usage: install_python.py [-ahnq] [-d DIR] [-p PREFIX] [VERSION ...]
44 -a, --all Install all SCons versions.
45 -d DIR, --downloads=DIR Downloads directory.
46 -h, --help Print this help and exit
47 -n, --no-exec No execute, just print command lines
48 -p PREFIX, --prefix=PREFIX Installation prefix.
49 -q, --quiet Quiet, don't print command lines
54 opts, args = getopt.getopt(argv[1:], short_options, long_options)
55 except getopt.error, msg:
59 if o in ('-a', '--all'):
61 elif o in ('-d', '--downloads'):
63 elif o in ('-h', '--help'):
66 elif o in ('-n', '--no-exec'):
67 CommandRunner.execute = CommandRunner.do_not_execute
68 elif o in ('-p', '--prefix'):
70 elif o in ('-q', '--quiet'):
71 CommandRunner.display = CommandRunner.do_not_display
73 sys.stderr.write(str(err.msg) + '\n')
74 sys.stderr.write('use -h to get help\n')
79 msg = 'install-scons.py: -a and version arguments both specified'
88 python = 'Python-' + version
89 tar_gz = os.path.join(downloads_dir, python + '.tgz')
90 tar_gz_url = os.path.join(downloads_url, version, python + '.tgz')
92 if (version.startswith('1.5') or
93 version.startswith('1.6') or
94 version.startswith('2.0')):
96 configureflags = '--with-threads'
102 cmd.subst_dictionary(locals())
104 if not os.path.exists(tar_gz):
105 if not os.path.exists(downloads_dir):
106 cmd.run('mkdir %(downloads_dir)s')
107 cmd.run('wget -O %(tar_gz)s %(tar_gz_url)s')
109 cmd.run('tar zxf %(tar_gz)s')
111 cmd.run('cd %(python)s')
113 if (version.startswith('1.6') or
114 version.startswith('2.0')):
116 def edit_modules_setup_in():
117 content = open('Modules/Setup.in', 'r').read()
118 content = content.replace('\n#zlib', '\nzlib')
119 open('Modules/Setup.in', 'w').write(content)
121 display = 'ed Modules/Setup.in <<EOF\ns/^#zlib/zlib/\nw\nq\nEOF\n'
122 cmd.run((edit_modules_setup_in,), display)
124 cmd.run('./configure --prefix=%(prefix)s %(configureflags)s 2>&1 | tee configure.out')
125 cmd.run('make 2>&1 | tee make.out')
126 cmd.run('%(sudo)s make install')
128 cmd.run('%(sudo)s rm -f %(prefix)s/bin/{idle,pydoc,python,python-config,smtpd.py}')
132 cmd.run((shutil.rmtree, python), 'rm -rf %(python)s')
134 if __name__ == "__main__":
139 # indent-tabs-mode:nil
141 # vim: set expandtab tabstop=4 shiftwidth=4: