Revision 2715ade4 snf-pithos-tools/distribute_setup.py
b/snf-pithos-tools/distribute_setup.py | ||
---|---|---|
144 | 144 |
except ImportError: |
145 | 145 |
return _do_download(version, download_base, to_dir, download_delay) |
146 | 146 |
try: |
147 |
pkg_resources.require("distribute>="+version)
|
|
147 |
pkg_resources.require("distribute>=" + version)
|
|
148 | 148 |
return |
149 | 149 |
except pkg_resources.VersionConflict: |
150 | 150 |
e = sys.exc_info()[1] |
151 | 151 |
if was_imported: |
152 | 152 |
sys.stderr.write( |
153 |
"The required version of distribute (>=%s) is not available,\n" |
|
154 |
"and can't be installed while this script is running. Please\n" |
|
155 |
"install a more recent version first, using\n" |
|
156 |
"'easy_install -U distribute'." |
|
157 |
"\n\n(Currently using %r)\n" % (version, e.args[0])) |
|
153 |
"The required version of distribute (>=%s) is not available,\n"
|
|
154 |
"and can't be installed while this script is running. Please\n"
|
|
155 |
"install a more recent version first, using\n"
|
|
156 |
"'easy_install -U distribute'."
|
|
157 |
"\n\n(Currently using %r)\n" % (version, e.args[0]))
|
|
158 | 158 |
sys.exit(2) |
159 | 159 |
else: |
160 | 160 |
del pkg_resources, sys.modules['pkg_resources'] # reload ok |
... | ... | |
167 | 167 |
if not no_fake: |
168 | 168 |
_create_fake_setuptools_pkg_info(to_dir) |
169 | 169 |
|
170 |
|
|
170 | 171 |
def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL, |
171 | 172 |
to_dir=os.curdir, delay=15): |
172 | 173 |
"""Download distribute from a specified location and return its filename |
... | ... | |
203 | 204 |
dst.close() |
204 | 205 |
return os.path.realpath(saveto) |
205 | 206 |
|
207 |
|
|
206 | 208 |
def _no_sandbox(function): |
207 | 209 |
def __no_sandbox(*args, **kw): |
208 | 210 |
try: |
... | ... | |
227 | 229 |
|
228 | 230 |
return __no_sandbox |
229 | 231 |
|
232 |
|
|
230 | 233 |
def _patch_file(path, content): |
231 | 234 |
"""Will backup the file then patch it""" |
232 | 235 |
existing_content = open(path).read() |
... | ... | |
245 | 248 |
|
246 | 249 |
_patch_file = _no_sandbox(_patch_file) |
247 | 250 |
|
251 |
|
|
248 | 252 |
def _same_content(path, content): |
249 | 253 |
return open(path).read() == content |
250 | 254 |
|
255 |
|
|
251 | 256 |
def _rename_path(path): |
252 | 257 |
new_name = path + '.OLD.%s' % time.time() |
253 | 258 |
log.warn('Renaming %s into %s', path, new_name) |
254 | 259 |
os.rename(path, new_name) |
255 | 260 |
return new_name |
256 | 261 |
|
262 |
|
|
257 | 263 |
def _remove_flat_installation(placeholder): |
258 | 264 |
if not os.path.isdir(placeholder): |
259 | 265 |
log.warn('Unkown installation at %s', placeholder) |
... | ... | |
289 | 295 |
|
290 | 296 |
_remove_flat_installation = _no_sandbox(_remove_flat_installation) |
291 | 297 |
|
298 |
|
|
292 | 299 |
def _after_install(dist): |
293 | 300 |
log.warn('After install bootstrap.') |
294 | 301 |
placeholder = dist.get_command_obj('install').install_purelib |
295 | 302 |
_create_fake_setuptools_pkg_info(placeholder) |
296 | 303 |
|
304 |
|
|
297 | 305 |
def _create_fake_setuptools_pkg_info(placeholder): |
298 | 306 |
if not placeholder or not os.path.exists(placeholder): |
299 | 307 |
log.warn('Could not find the install location') |
300 | 308 |
return |
301 | 309 |
pyver = '%s.%s' % (sys.version_info[0], sys.version_info[1]) |
302 | 310 |
setuptools_file = 'setuptools-%s-py%s.egg-info' % \ |
303 |
(SETUPTOOLS_FAKED_VERSION, pyver)
|
|
311 |
(SETUPTOOLS_FAKED_VERSION, pyver) |
|
304 | 312 |
pkg_info = os.path.join(placeholder, setuptools_file) |
305 | 313 |
if os.path.exists(pkg_info): |
306 | 314 |
log.warn('%s already exists', pkg_info) |
... | ... | |
321 | 329 |
finally: |
322 | 330 |
f.close() |
323 | 331 |
|
324 |
_create_fake_setuptools_pkg_info = _no_sandbox(_create_fake_setuptools_pkg_info) |
|
332 |
_create_fake_setuptools_pkg_info = _no_sandbox( |
|
333 |
_create_fake_setuptools_pkg_info) |
|
334 |
|
|
325 | 335 |
|
326 | 336 |
def _patch_egg_dir(path): |
327 | 337 |
# let's check if it's already patched |
... | ... | |
343 | 353 |
|
344 | 354 |
_patch_egg_dir = _no_sandbox(_patch_egg_dir) |
345 | 355 |
|
356 |
|
|
346 | 357 |
def _before_install(): |
347 | 358 |
log.warn('Before install bootstrap.') |
348 | 359 |
_fake_setuptools() |
... | ... | |
351 | 362 |
def _under_prefix(location): |
352 | 363 |
if 'install' not in sys.argv: |
353 | 364 |
return True |
354 |
args = sys.argv[sys.argv.index('install')+1:]
|
|
365 |
args = sys.argv[sys.argv.index('install') + 1:]
|
|
355 | 366 |
for index, arg in enumerate(args): |
356 | 367 |
for option in ('--root', '--prefix'): |
357 | 368 |
if arg.startswith('%s=' % option): |
... | ... | |
359 | 370 |
return location.startswith(top_dir) |
360 | 371 |
elif arg == option: |
361 | 372 |
if len(args) > index: |
362 |
top_dir = args[index+1]
|
|
373 |
top_dir = args[index + 1]
|
|
363 | 374 |
return location.startswith(top_dir) |
364 | 375 |
if arg == '--user' and USER_SITE is not None: |
365 | 376 |
return location.startswith(USER_SITE) |
... | ... | |
380 | 391 |
replacement=False)) |
381 | 392 |
except TypeError: |
382 | 393 |
# old distribute API |
383 |
setuptools_dist = ws.find(pkg_resources.Requirement.parse('setuptools')) |
|
394 |
setuptools_dist = ws.find( |
|
395 |
pkg_resources.Requirement.parse('setuptools')) |
|
384 | 396 |
|
385 | 397 |
if setuptools_dist is None: |
386 | 398 |
log.warn('No setuptools distribution found') |
... | ... | |
406 | 418 |
log.warn('Egg installation') |
407 | 419 |
pkg_info = os.path.join(setuptools_location, 'EGG-INFO', 'PKG-INFO') |
408 | 420 |
if (os.path.exists(pkg_info) and |
409 |
_same_content(pkg_info, SETUPTOOLS_PKG_INFO)): |
|
421 |
_same_content(pkg_info, SETUPTOOLS_PKG_INFO)):
|
|
410 | 422 |
log.warn('Already patched.') |
411 | 423 |
return |
412 | 424 |
log.warn('Patching...') |
... | ... | |
448 | 460 |
# Extract directories with a safe mode. |
449 | 461 |
directories.append(tarinfo) |
450 | 462 |
tarinfo = copy.copy(tarinfo) |
451 |
tarinfo.mode = 448 # decimal for oct 0700 |
|
463 |
tarinfo.mode = 448 # decimal for oct 0700
|
|
452 | 464 |
self.extract(tarinfo, path) |
453 | 465 |
|
454 | 466 |
# Reverse sort directories. |
Also available in: Unified diff