Revision 670b67f4
b/astakosclient/distribute_setup.py | ||
---|---|---|
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\n"
|
|
154 |
"available and can't be installed while this script\n"
|
|
155 |
"is running. Please install a more recent version first,\n"
|
|
156 |
"using '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) |
... | ... | |
323 | 331 |
|
324 | 332 |
_create_fake_setuptools_pkg_info = _no_sandbox(_create_fake_setuptools_pkg_info) |
325 | 333 |
|
334 |
|
|
326 | 335 |
def _patch_egg_dir(path): |
327 | 336 |
# let's check if it's already patched |
328 | 337 |
pkg_info = os.path.join(path, 'EGG-INFO', 'PKG-INFO') |
... | ... | |
343 | 352 |
|
344 | 353 |
_patch_egg_dir = _no_sandbox(_patch_egg_dir) |
345 | 354 |
|
355 |
|
|
346 | 356 |
def _before_install(): |
347 | 357 |
log.warn('Before install bootstrap.') |
348 | 358 |
_fake_setuptools() |
... | ... | |
406 | 416 |
log.warn('Egg installation') |
407 | 417 |
pkg_info = os.path.join(setuptools_location, 'EGG-INFO', 'PKG-INFO') |
408 | 418 |
if (os.path.exists(pkg_info) and |
409 |
_same_content(pkg_info, SETUPTOOLS_PKG_INFO)):
|
|
419 |
_same_content(pkg_info, SETUPTOOLS_PKG_INFO)): |
|
410 | 420 |
log.warn('Already patched.') |
411 | 421 |
return |
412 | 422 |
log.warn('Patching...') |
... | ... | |
448 | 458 |
# Extract directories with a safe mode. |
449 | 459 |
directories.append(tarinfo) |
450 | 460 |
tarinfo = copy.copy(tarinfo) |
451 |
tarinfo.mode = 448 # decimal for oct 0700 |
|
461 |
tarinfo.mode = 448 # decimal for oct 0700
|
|
452 | 462 |
self.extract(tarinfo, path) |
453 | 463 |
|
454 | 464 |
# Reverse sort directories. |
Also available in: Unified diff