src/ldt/distribute_setup.py
changeset 63 93325a5d61f0
parent 48 ef3a8cfef2bc
equal deleted inserted replaced
62:27253368f045 63:93325a5d61f0
    11 mirror, or use an alternate download directory, you can do so by supplying
    11 mirror, or use an alternate download directory, you can do so by supplying
    12 the appropriate options to ``use_setuptools()``.
    12 the appropriate options to ``use_setuptools()``.
    13 
    13 
    14 This file can also be run as a script to install or upgrade setuptools.
    14 This file can also be run as a script to install or upgrade setuptools.
    15 """
    15 """
       
    16 from distutils import log
       
    17 import fnmatch
    16 import os
    18 import os
    17 import sys
    19 import sys
       
    20 import tarfile
       
    21 import tempfile
    18 import time
    22 import time
    19 import fnmatch
       
    20 import tempfile
       
    21 import tarfile
       
    22 from distutils import log
       
    23 
    23 
    24 try:
    24 try:
    25     from site import USER_SITE
    25     from site import USER_SITE
    26 except ImportError:
    26 except ImportError:
    27     USER_SITE = None
    27     USER_SITE = None
   142                     _fake_setuptools()
   142                     _fake_setuptools()
   143                 raise ImportError
   143                 raise ImportError
   144         except ImportError:
   144         except ImportError:
   145             return _do_download(version, download_base, to_dir, download_delay)
   145             return _do_download(version, download_base, to_dir, download_delay)
   146         try:
   146         try:
   147             pkg_resources.require("distribute>="+version)
   147             pkg_resources.require("distribute>=" + version)
   148             return
   148             return
   149         except pkg_resources.VersionConflict:
   149         except pkg_resources.VersionConflict:
   150             e = sys.exc_info()[1]
   150             e = sys.exc_info()[1]
   151             if was_imported:
   151             if was_imported:
   152                 sys.stderr.write(
   152                 sys.stderr.write(
   220 
   220 
   221         try:
   221         try:
   222             return function(*args, **kw)
   222             return function(*args, **kw)
   223         finally:
   223         finally:
   224             if patched:
   224             if patched:
   225                 DirectorySandbox._violation = DirectorySandbox._old
   225                 DirectorySandbox._violation = DirectorySandbox._old #@UndefinedVariable
   226                 del DirectorySandbox._old
   226                 del DirectorySandbox._old
   227 
   227 
   228     return __no_sandbox
   228     return __no_sandbox
   229 
   229 
   230 def _patch_file(path, content):
   230 def _patch_file(path, content):
   349 
   349 
   350 
   350 
   351 def _under_prefix(location):
   351 def _under_prefix(location):
   352     if 'install' not in sys.argv:
   352     if 'install' not in sys.argv:
   353         return True
   353         return True
   354     args = sys.argv[sys.argv.index('install')+1:]
   354     args = sys.argv[sys.argv.index('install') + 1:]
   355     for index, arg in enumerate(args):
   355     for index, arg in enumerate(args):
   356         for option in ('--root', '--prefix'):
   356         for option in ('--root', '--prefix'):
   357             if arg.startswith('%s=' % option):
   357             if arg.startswith('%s=' % option):
   358                 top_dir = arg.split('root=')[-1]
   358                 top_dir = arg.split('root=')[-1]
   359                 return location.startswith(top_dir)
   359                 return location.startswith(top_dir)
   360             elif arg == option:
   360             elif arg == option:
   361                 if len(args) > index:
   361                 if len(args) > index:
   362                     top_dir = args[index+1]
   362                     top_dir = args[index + 1]
   363                     return location.startswith(top_dir)
   363                     return location.startswith(top_dir)
   364         if arg == '--user' and USER_SITE is not None:
   364         if arg == '--user' and USER_SITE is not None:
   365             return location.startswith(USER_SITE)
   365             return location.startswith(USER_SITE)
   366     return True
   366     return True
   367 
   367