annotate ez_setup.py @ 33:7c7b7114864b MySQLdb

Merge back r555 for ez_setup usage
author kylev
date Wed, 11 Feb 2009 23:51:13 +0000
parents cbdd84eabe07
children 38bf72f3c3de
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
1 #!python
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
2 """Bootstrap setuptools installation
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
3
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
4 If you want to use setuptools in your package's setup.py, just include this
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
5 file in the same directory with it, and add this to the top of your setup.py::
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
6
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
7 from ez_setup import use_setuptools
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
8 use_setuptools()
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
9
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
10 If you want to require a specific version of setuptools, set a download
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
11 mirror, or use an alternate download directory, you can do so by supplying
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
12 the appropriate options to ``use_setuptools()``.
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
13
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
14 This file can also be run as a script to install or upgrade setuptools.
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
15 """
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
16 import sys
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
17 DEFAULT_VERSION = "0.6c5"
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
18 DEFAULT_URL = "http://cheeseshop.python.org/packages/%s/s/setuptools/" % sys.version[:3]
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
19
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
20 md5_data = {
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
21 'setuptools-0.6b1-py2.3.egg': '8822caf901250d848b996b7f25c6e6ca',
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
22 'setuptools-0.6b1-py2.4.egg': 'b79a8a403e4502fbb85ee3f1941735cb',
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
23 'setuptools-0.6b2-py2.3.egg': '5657759d8a6d8fc44070a9d07272d99b',
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
24 'setuptools-0.6b2-py2.4.egg': '4996a8d169d2be661fa32a6e52e4f82a',
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
25 'setuptools-0.6b3-py2.3.egg': 'bb31c0fc7399a63579975cad9f5a0618',
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
26 'setuptools-0.6b3-py2.4.egg': '38a8c6b3d6ecd22247f179f7da669fac',
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
27 'setuptools-0.6b4-py2.3.egg': '62045a24ed4e1ebc77fe039aa4e6f7e5',
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
28 'setuptools-0.6b4-py2.4.egg': '4cb2a185d228dacffb2d17f103b3b1c4',
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
29 'setuptools-0.6c1-py2.3.egg': 'b3f2b5539d65cb7f74ad79127f1a908c',
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
30 'setuptools-0.6c1-py2.4.egg': 'b45adeda0667d2d2ffe14009364f2a4b',
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
31 'setuptools-0.6c2-py2.3.egg': 'f0064bf6aa2b7d0f3ba0b43f20817c27',
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
32 'setuptools-0.6c2-py2.4.egg': '616192eec35f47e8ea16cd6a122b7277',
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
33 'setuptools-0.6c3-py2.3.egg': 'f181fa125dfe85a259c9cd6f1d7b78fa',
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
34 'setuptools-0.6c3-py2.4.egg': 'e0ed74682c998bfb73bf803a50e7b71e',
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
35 'setuptools-0.6c3-py2.5.egg': 'abef16fdd61955514841c7c6bd98965e',
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
36 'setuptools-0.6c4-py2.3.egg': 'b0b9131acab32022bfac7f44c5d7971f',
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
37 'setuptools-0.6c4-py2.4.egg': '2a1f9656d4fbf3c97bf946c0a124e6e2',
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
38 'setuptools-0.6c4-py2.5.egg': '8f5a052e32cdb9c72bcf4b5526f28afc',
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
39 'setuptools-0.6c5-py2.3.egg': 'ee9fd80965da04f2f3e6b3576e9d8167',
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
40 'setuptools-0.6c5-py2.4.egg': 'afe2adf1c01701ee841761f5bcd8aa64',
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
41 'setuptools-0.6c5-py2.5.egg': 'a8d3f61494ccaa8714dfed37bccd3d5d',
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
42 }
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
43
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
44 import sys, os
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
45
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
46 def _validate_md5(egg_name, data):
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
47 if egg_name in md5_data:
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
48 from md5 import md5
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
49 digest = md5(data).hexdigest()
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
50 if digest != md5_data[egg_name]:
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
51 print >>sys.stderr, (
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
52 "md5 validation of %s failed! (Possible download problem?)"
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
53 % egg_name
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
54 )
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
55 sys.exit(2)
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
56 return data
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
57
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
58
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
59 def use_setuptools(
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
60 version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir,
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
61 download_delay=15
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
62 ):
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
63 """Automatically find/download setuptools and make it available on sys.path
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
64
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
65 `version` should be a valid setuptools version number that is available
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
66 as an egg for download under the `download_base` URL (which should end with
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
67 a '/'). `to_dir` is the directory where setuptools will be downloaded, if
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
68 it is not already available. If `download_delay` is specified, it should
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
69 be the number of seconds that will be paused before initiating a download,
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
70 should one be required. If an older version of setuptools is installed,
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
71 this routine will print a message to ``sys.stderr`` and raise SystemExit in
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
72 an attempt to abort the calling script.
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
73 """
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
74 try:
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
75 import setuptools
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
76 if setuptools.__version__ == '0.0.1':
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
77 print >>sys.stderr, (
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
78 "You have an obsolete version of setuptools installed. Please\n"
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
79 "remove it from your system entirely before rerunning this script."
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
80 )
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
81 sys.exit(2)
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
82 except ImportError:
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
83 egg = download_setuptools(version, download_base, to_dir, download_delay)
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
84 sys.path.insert(0, egg)
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
85 import setuptools; setuptools.bootstrap_install_from = egg
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
86
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
87 import pkg_resources
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
88 try:
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
89 pkg_resources.require("setuptools>="+version)
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
90
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
91 except pkg_resources.VersionConflict, e:
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
92 # XXX could we install in a subprocess here?
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
93 print >>sys.stderr, (
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
94 "The required version of setuptools (>=%s) is not available, and\n"
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
95 "can't be installed while this script is running. Please install\n"
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
96 " a more recent version first.\n\n(Currently using %r)"
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
97 ) % (version, e.args[0])
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
98 sys.exit(2)
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
99
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
100 def download_setuptools(
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
101 version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir,
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
102 delay = 15
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
103 ):
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
104 """Download setuptools from a specified location and return its filename
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
105
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
106 `version` should be a valid setuptools version number that is available
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
107 as an egg for download under the `download_base` URL (which should end
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
108 with a '/'). `to_dir` is the directory where the egg will be downloaded.
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
109 `delay` is the number of seconds to pause before an actual download attempt.
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
110 """
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
111 import urllib2, shutil
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
112 egg_name = "setuptools-%s-py%s.egg" % (version,sys.version[:3])
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
113 url = download_base + egg_name
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
114 saveto = os.path.join(to_dir, egg_name)
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
115 src = dst = None
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
116 if not os.path.exists(saveto): # Avoid repeated downloads
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
117 try:
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
118 from distutils import log
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
119 if delay:
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
120 log.warn("""
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
121 ---------------------------------------------------------------------------
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
122 This script requires setuptools version %s to run (even to display
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
123 help). I will attempt to download it for you (from
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
124 %s), but
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
125 you may need to enable firewall access for this script first.
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
126 I will start the download in %d seconds.
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
127
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
128 (Note: if this machine does not have network access, please obtain the file
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
129
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
130 %s
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
131
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
132 and place it in this directory before rerunning this script.)
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
133 ---------------------------------------------------------------------------""",
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
134 version, download_base, delay, url
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
135 ); from time import sleep; sleep(delay)
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
136 log.warn("Downloading %s", url)
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
137 src = urllib2.urlopen(url)
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
138 # Read/write all in one block, so we don't create a corrupt file
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
139 # if the download is interrupted.
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
140 data = _validate_md5(egg_name, src.read())
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
141 dst = open(saveto,"wb"); dst.write(data)
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
142 finally:
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
143 if src: src.close()
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
144 if dst: dst.close()
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
145 return os.path.realpath(saveto)
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
146
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
147 def main(argv, version=DEFAULT_VERSION):
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
148 """Install or upgrade setuptools and EasyInstall"""
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
149
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
150 try:
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
151 import setuptools
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
152 except ImportError:
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
153 egg = None
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
154 try:
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
155 egg = download_setuptools(version, delay=0)
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
156 sys.path.insert(0,egg)
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
157 from setuptools.command.easy_install import main
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
158 return main(list(argv)+[egg]) # we're done here
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
159 finally:
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
160 if egg and os.path.exists(egg):
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
161 os.unlink(egg)
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
162 else:
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
163 if setuptools.__version__ == '0.0.1':
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
164 # tell the user to uninstall obsolete version
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
165 use_setuptools(version)
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
166
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
167 req = "setuptools>="+version
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
168 import pkg_resources
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
169 try:
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
170 pkg_resources.require(req)
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
171 except pkg_resources.VersionConflict:
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
172 try:
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
173 from setuptools.command.easy_install import main
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
174 except ImportError:
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
175 from easy_install import main
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
176 main(list(argv)+[download_setuptools(delay=0)])
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
177 sys.exit(0) # try to force an exit
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
178 else:
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
179 if argv:
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
180 from setuptools.command.easy_install import main
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
181 main(argv)
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
182 else:
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
183 print "Setuptools version",version,"or greater has been installed."
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
184 print '(Run "ez_setup.py -U setuptools" to reinstall or upgrade.)'
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
185
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
186
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
187
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
188 def update_md5(filenames):
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
189 """Update our built-in md5 registry"""
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
190
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
191 import re
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
192 from md5 import md5
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
193
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
194 for name in filenames:
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
195 base = os.path.basename(name)
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
196 f = open(name,'rb')
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
197 md5_data[base] = md5(f.read()).hexdigest()
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
198 f.close()
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
199
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
200 data = [" %r: %r,\n" % it for it in md5_data.items()]
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
201 data.sort()
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
202 repl = "".join(data)
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
203
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
204 import inspect
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
205 srcfile = inspect.getsourcefile(sys.modules[__name__])
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
206 f = open(srcfile, 'rb'); src = f.read(); f.close()
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
207
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
208 match = re.search("\nmd5_data = {\n([^}]+)}", src)
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
209 if not match:
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
210 print >>sys.stderr, "Internal error!"
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
211 sys.exit(2)
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
212
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
213 src = src[:match.start(1)] + repl + src[match.end(1):]
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
214 f = open(srcfile,'w')
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
215 f.write(src)
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
216 f.close()
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
217
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
218
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
219 if __name__=='__main__':
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
220 if len(sys.argv)>2 and sys.argv[1]=='--md5update':
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
221 update_md5(sys.argv[2:])
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
222 else:
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
223 main(sys.argv[1:])
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
224
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
225
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
226
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
227
cbdd84eabe07 Added to make build bot happy.
adustman
parents:
diff changeset
228