parts/buildout/site.py
changeset 307 c6bca38c1cbf
equal deleted inserted replaced
306:5ff1fc726848 307:c6bca38c1cbf
       
     1 """Append module search paths for third-party packages to sys.path.
       
     2 
       
     3 ****************************************************************
       
     4 * This module is automatically imported during initialization. *
       
     5 ****************************************************************
       
     6 
       
     7 In earlier versions of Python (up to 1.5a3), scripts or modules that
       
     8 needed to use site-specific modules would place ``import site''
       
     9 somewhere near the top of their code.  Because of the automatic
       
    10 import, this is no longer necessary (but code that does it still
       
    11 works).
       
    12 
       
    13 This will append site-specific paths to the module search path.  On
       
    14 Unix (including Mac OSX), it starts with sys.prefix and
       
    15 sys.exec_prefix (if different) and appends
       
    16 lib/python<version>/site-packages as well as lib/site-python.
       
    17 On other platforms (such as Windows), it tries each of the
       
    18 prefixes directly, as well as with lib/site-packages appended.  The
       
    19 resulting directories, if they exist, are appended to sys.path, and
       
    20 also inspected for path configuration files.
       
    21 
       
    22 For Debian and derivatives, this sys.path is augmented with directories
       
    23 for packages distributed within the distribution. Local addons go
       
    24 into /usr/local/lib/python<version>/dist-packages, Debian addons
       
    25 install into /usr/{lib,share}/python<version>/dist-packages.
       
    26 /usr/lib/python<version>/site-packages is not used.
       
    27 
       
    28 A path configuration file is a file whose name has the form
       
    29 <package>.pth; its contents are additional directories (one per line)
       
    30 to be added to sys.path.  Non-existing directories (or
       
    31 non-directories) are never added to sys.path; no directory is added to
       
    32 sys.path more than once.  Blank lines and lines beginning with
       
    33 '#' are skipped. Lines starting with 'import' are executed.
       
    34 
       
    35 For example, suppose sys.prefix and sys.exec_prefix are set to
       
    36 /usr/local and there is a directory /usr/local/lib/python2.5/site-packages
       
    37 with three subdirectories, foo, bar and spam, and two path
       
    38 configuration files, foo.pth and bar.pth.  Assume foo.pth contains the
       
    39 following:
       
    40 
       
    41   # foo package configuration
       
    42   foo
       
    43   bar
       
    44   bletch
       
    45 
       
    46 and bar.pth contains:
       
    47 
       
    48   # bar package configuration
       
    49   bar
       
    50 
       
    51 Then the following directories are added to sys.path, in this order:
       
    52 
       
    53   /usr/local/lib/python2.5/site-packages/bar
       
    54   /usr/local/lib/python2.5/site-packages/foo
       
    55 
       
    56 Note that bletch is omitted because it doesn't exist; bar precedes foo
       
    57 because bar.pth comes alphabetically before foo.pth; and spam is
       
    58 omitted because it is not mentioned in either path configuration file.
       
    59 
       
    60 After these path manipulations, an attempt is made to import a module
       
    61 named sitecustomize, which can perform arbitrary additional
       
    62 site-specific customizations.  If this import fails with an
       
    63 ImportError exception, it is silently ignored.
       
    64 
       
    65 """
       
    66 
       
    67 import sys
       
    68 import os
       
    69 import __builtin__
       
    70 
       
    71 # Prefixes for site-packages; add additional prefixes like /usr/local here
       
    72 PREFIXES = [sys.prefix, sys.exec_prefix]
       
    73 # Enable per user site-packages directory
       
    74 # set it to False to disable the feature or True to force the feature
       
    75 ENABLE_USER_SITE = False # buildout does not support user sites.
       
    76 # for distutils.commands.install
       
    77 USER_SITE = None
       
    78 USER_BASE = None
       
    79 
       
    80 
       
    81 def makepath(*paths):
       
    82     dir = os.path.abspath(os.path.join(*paths))
       
    83     return dir, os.path.normcase(dir)
       
    84 
       
    85 
       
    86 def abs__file__():
       
    87     """Set all module' __file__ attribute to an absolute path"""
       
    88     for m in sys.modules.values():
       
    89         if hasattr(m, '__loader__'):
       
    90             continue   # don't mess with a PEP 302-supplied __file__
       
    91         try:
       
    92             m.__file__ = os.path.abspath(m.__file__)
       
    93         except AttributeError:
       
    94             continue
       
    95 
       
    96 
       
    97 def removeduppaths():
       
    98     """ Remove duplicate entries from sys.path along with making them
       
    99     absolute"""
       
   100     # This ensures that the initial path provided by the interpreter contains
       
   101     # only absolute pathnames, even if we're running from the build directory.
       
   102     L = []
       
   103     known_paths = set()
       
   104     for dir in sys.path:
       
   105         # Filter out duplicate paths (on case-insensitive file systems also
       
   106         # if they only differ in case); turn relative paths into absolute
       
   107         # paths.
       
   108         dir, dircase = makepath(dir)
       
   109         if not dircase in known_paths:
       
   110             L.append(dir)
       
   111             known_paths.add(dircase)
       
   112     sys.path[:] = L
       
   113     return known_paths
       
   114 
       
   115 def _init_pathinfo():
       
   116     """Return a set containing all existing directory entries from sys.path"""
       
   117     d = set()
       
   118     for dir in sys.path:
       
   119         try:
       
   120             if os.path.isdir(dir):
       
   121                 dir, dircase = makepath(dir)
       
   122                 d.add(dircase)
       
   123         except TypeError:
       
   124             continue
       
   125     return d
       
   126 
       
   127 
       
   128 def addpackage(sitedir, name, known_paths):
       
   129     """Process a .pth file within the site-packages directory:
       
   130        For each line in the file, either combine it with sitedir to a path
       
   131        and add that to known_paths, or execute it if it starts with 'import '.
       
   132     """
       
   133     if known_paths is None:
       
   134         _init_pathinfo()
       
   135         reset = 1
       
   136     else:
       
   137         reset = 0
       
   138     fullname = os.path.join(sitedir, name)
       
   139     try:
       
   140         f = open(fullname, "rU")
       
   141     except IOError:
       
   142         return
       
   143     with f:
       
   144         for line in f:
       
   145             if line.startswith("#"):
       
   146                 continue
       
   147             if line.startswith(("import ", "import\t")):
       
   148                 exec line
       
   149                 continue
       
   150             line = line.rstrip()
       
   151             dir, dircase = makepath(sitedir, line)
       
   152             if not dircase in known_paths and os.path.exists(dir):
       
   153                 sys.path.append(dir)
       
   154                 known_paths.add(dircase)
       
   155     if reset:
       
   156         known_paths = None
       
   157     return known_paths
       
   158 
       
   159 
       
   160 def addsitedir(sitedir, known_paths=None):
       
   161     """Add 'sitedir' argument to sys.path if missing and handle .pth files in
       
   162     'sitedir'"""
       
   163     if known_paths is None:
       
   164         known_paths = _init_pathinfo()
       
   165         reset = 1
       
   166     else:
       
   167         reset = 0
       
   168     sitedir, sitedircase = makepath(sitedir)
       
   169     if not sitedircase in known_paths:
       
   170         sys.path.append(sitedir)        # Add path component
       
   171     try:
       
   172         names = os.listdir(sitedir)
       
   173     except os.error:
       
   174         return
       
   175     dotpth = os.extsep + "pth"
       
   176     names = [name for name in names if name.endswith(dotpth)]
       
   177     for name in sorted(names):
       
   178         addpackage(sitedir, name, known_paths)
       
   179     if reset:
       
   180         known_paths = None
       
   181     return known_paths
       
   182 
       
   183 
       
   184 def check_enableusersite():
       
   185     """Check if user site directory is safe for inclusion
       
   186 
       
   187     The function tests for the command line flag (including environment var),
       
   188     process uid/gid equal to effective uid/gid.
       
   189 
       
   190     None: Disabled for security reasons
       
   191     False: Disabled by user (command line option)
       
   192     True: Safe and enabled
       
   193     """
       
   194     if sys.flags.no_user_site:
       
   195         return False
       
   196 
       
   197     if hasattr(os, "getuid") and hasattr(os, "geteuid"):
       
   198         # check process uid == effective uid
       
   199         if os.geteuid() != os.getuid():
       
   200             return None
       
   201     if hasattr(os, "getgid") and hasattr(os, "getegid"):
       
   202         # check process gid == effective gid
       
   203         if os.getegid() != os.getgid():
       
   204             return None
       
   205 
       
   206     return True
       
   207 
       
   208 
       
   209 def addusersitepackages(known_paths):
       
   210     """Add a per user site-package to sys.path
       
   211 
       
   212     Each user has its own python directory with site-packages in the
       
   213     home directory.
       
   214 
       
   215     USER_BASE is the root directory for all Python versions
       
   216 
       
   217     USER_SITE is the user specific site-packages directory
       
   218 
       
   219     USER_SITE/.. can be used for data.
       
   220     """
       
   221     global USER_BASE, USER_SITE, ENABLE_USER_SITE
       
   222     env_base = os.environ.get("PYTHONUSERBASE", None)
       
   223 
       
   224     def joinuser(*args):
       
   225         return os.path.expanduser(os.path.join(*args))
       
   226 
       
   227     #if sys.platform in ('os2emx', 'riscos'):
       
   228     #    # Don't know what to put here
       
   229     #    USER_BASE = ''
       
   230     #    USER_SITE = ''
       
   231     if os.name == "nt":
       
   232         base = os.environ.get("APPDATA") or "~"
       
   233         USER_BASE = env_base if env_base else joinuser(base, "Python")
       
   234         USER_SITE = os.path.join(USER_BASE,
       
   235                                  "Python" + sys.version[0] + sys.version[2],
       
   236                                  "site-packages")
       
   237     else:
       
   238         USER_BASE = env_base if env_base else joinuser("~", ".local")
       
   239         USER_SITE = os.path.join(USER_BASE, "lib",
       
   240                                  "python" + sys.version[:3],
       
   241                                  "site-packages")
       
   242 
       
   243     if ENABLE_USER_SITE and os.path.isdir(USER_SITE):
       
   244         addsitedir(USER_SITE, known_paths)
       
   245     if ENABLE_USER_SITE:
       
   246         for dist_libdir in ("local/lib", "lib"):
       
   247             user_site = os.path.join(USER_BASE, dist_libdir,
       
   248                                      "python" + sys.version[:3],
       
   249                                      "dist-packages")
       
   250             if os.path.isdir(user_site):
       
   251                 addsitedir(user_site, known_paths)
       
   252     return known_paths
       
   253 
       
   254 
       
   255 def addsitepackages(known_paths):
       
   256     """Add site packages, as determined by zc.buildout.
       
   257 
       
   258     See original_addsitepackages, below, for the original version."""
       
   259     setuptools_path = '/home/nishanth/Desktop/pytask/eggs/setuptools-0.6c12dev_r85381-py2.6.egg'
       
   260     sys.path.append(setuptools_path)
       
   261     known_paths.add(os.path.normcase(setuptools_path))
       
   262     import pkg_resources
       
   263     buildout_paths = [
       
   264         '/home/nishanth/Desktop/pytask/eggs/setuptools-0.6c12dev_r85381-py2.6.egg',
       
   265         '/home/nishanth/Desktop/pytask/eggs/zc.buildout-1.5.2-py2.6.egg'
       
   266         ]
       
   267     for path in buildout_paths:
       
   268         sitedir, sitedircase = makepath(path)
       
   269         if not sitedircase in known_paths and os.path.exists(sitedir):
       
   270             sys.path.append(sitedir)
       
   271             known_paths.add(sitedircase)
       
   272             pkg_resources.working_set.add_entry(sitedir)
       
   273     sys.__egginsert = len(buildout_paths) # Support distribute.
       
   274     original_paths = [
       
   275         '/usr/local/lib/python2.6/dist-packages/django_tagging-0.3.1-py2.6.egg',
       
   276         '/usr/local/lib/python2.6/dist-packages/django_registration-0.7-py2.6.egg',
       
   277         '/usr/local/lib/python2.6/dist-packages/Django-1.2.4-py2.6.egg',
       
   278         '/usr/local/lib/python2.6/dist-packages/South-0.7.3-py2.6.egg',
       
   279         '/usr/local/lib/python2.6/dist-packages/pysqlite-2.6.0-py2.6-linux-x86_64.egg',
       
   280         '/usr/local/lib/python2.6/dist-packages/django_auth_ldap-1.0.7-py2.6.egg',
       
   281         '/usr/local/lib/python2.6/dist-packages',
       
   282         '/usr/lib/python2.6/dist-packages',
       
   283         '/usr/lib/python2.6/dist-packages/PIL',
       
   284         '/usr/lib/python2.6/dist-packages/gst-0.10',
       
   285         '/usr/lib/pymodules/python2.6',
       
   286         '/usr/lib/python2.6/dist-packages/gtk-2.0',
       
   287         '/usr/lib/pymodules/python2.6/gtk-2.0',
       
   288         '/usr/lib/python2.6/dist-packages/wx-2.8-gtk2-unicode'
       
   289         ]
       
   290     for path in original_paths:
       
   291         if path == setuptools_path or path not in known_paths:
       
   292             addsitedir(path, known_paths)
       
   293     return known_paths
       
   294 
       
   295 def original_addsitepackages(known_paths):
       
   296     """Add site-packages (and possibly site-python) to sys.path"""
       
   297     sitedirs = []
       
   298     seen = []
       
   299 
       
   300     for prefix in PREFIXES:
       
   301         if not prefix or prefix in seen:
       
   302             continue
       
   303         seen.append(prefix)
       
   304 
       
   305         if sys.platform in ('os2emx', 'riscos'):
       
   306             sitedirs.append(os.path.join(prefix, "Lib", "site-packages"))
       
   307         elif os.sep == '/':
       
   308             sitedirs.append(os.path.join(prefix, "local/lib",
       
   309                                         "python" + sys.version[:3],
       
   310                                         "dist-packages"))
       
   311             sitedirs.append(os.path.join(prefix, "lib",
       
   312                                         "python" + sys.version[:3],
       
   313                                         "dist-packages"))
       
   314             sitedirs.append(os.path.join(prefix, "lib", "dist-python"))
       
   315         else:
       
   316             sitedirs.append(prefix)
       
   317             sitedirs.append(os.path.join(prefix, "lib", "site-packages"))
       
   318 
       
   319         if sys.platform == "darwin":
       
   320             # for framework builds *only* we add the standard Apple
       
   321             # locations. Currently only per-user, but /Library and
       
   322             # /Network/Library could be added too
       
   323             if 'Python.framework' in prefix:
       
   324                 sitedirs.append(
       
   325                     os.path.expanduser(
       
   326                         os.path.join("~", "Library", "Python",
       
   327                                      sys.version[:3], "site-packages")))
       
   328 
       
   329     for sitedir in sitedirs:
       
   330         if os.path.isdir(sitedir):
       
   331             addsitedir(sitedir, known_paths)
       
   332 
       
   333     return known_paths
       
   334 
       
   335 
       
   336 def setBEGINLIBPATH():
       
   337     """The OS/2 EMX port has optional extension modules that do double duty
       
   338     as DLLs (and must use the .DLL file extension) for other extensions.
       
   339     The library search path needs to be amended so these will be found
       
   340     during module import.  Use BEGINLIBPATH so that these are at the start
       
   341     of the library search path.
       
   342 
       
   343     """
       
   344     dllpath = os.path.join(sys.prefix, "Lib", "lib-dynload")
       
   345     libpath = os.environ['BEGINLIBPATH'].split(';')
       
   346     if libpath[-1]:
       
   347         libpath.append(dllpath)
       
   348     else:
       
   349         libpath[-1] = dllpath
       
   350     os.environ['BEGINLIBPATH'] = ';'.join(libpath)
       
   351 
       
   352 
       
   353 def setquit():
       
   354     """Define new built-ins 'quit' and 'exit'.
       
   355     These are simply strings that display a hint on how to exit.
       
   356 
       
   357     """
       
   358     if os.sep == ':':
       
   359         eof = 'Cmd-Q'
       
   360     elif os.sep == '\\':
       
   361         eof = 'Ctrl-Z plus Return'
       
   362     else:
       
   363         eof = 'Ctrl-D (i.e. EOF)'
       
   364 
       
   365     class Quitter(object):
       
   366         def __init__(self, name):
       
   367             self.name = name
       
   368         def __repr__(self):
       
   369             return 'Use %s() or %s to exit' % (self.name, eof)
       
   370         def __call__(self, code=None):
       
   371             # Shells like IDLE catch the SystemExit, but listen when their
       
   372             # stdin wrapper is closed.
       
   373             try:
       
   374                 sys.stdin.close()
       
   375             except:
       
   376                 pass
       
   377             raise SystemExit(code)
       
   378     __builtin__.quit = Quitter('quit')
       
   379     __builtin__.exit = Quitter('exit')
       
   380 
       
   381 
       
   382 class _Printer(object):
       
   383     """interactive prompt objects for printing the license text, a list of
       
   384     contributors and the copyright notice."""
       
   385 
       
   386     MAXLINES = 23
       
   387 
       
   388     def __init__(self, name, data, files=(), dirs=()):
       
   389         self.__name = name
       
   390         self.__data = data
       
   391         self.__files = files
       
   392         self.__dirs = dirs
       
   393         self.__lines = None
       
   394 
       
   395     def __setup(self):
       
   396         if self.__lines:
       
   397             return
       
   398         data = None
       
   399         for dir in self.__dirs:
       
   400             for filename in self.__files:
       
   401                 filename = os.path.join(dir, filename)
       
   402                 try:
       
   403                     fp = file(filename, "rU")
       
   404                     data = fp.read()
       
   405                     fp.close()
       
   406                     break
       
   407                 except IOError:
       
   408                     pass
       
   409             if data:
       
   410                 break
       
   411         if not data:
       
   412             data = self.__data
       
   413         self.__lines = data.split('\n')
       
   414         self.__linecnt = len(self.__lines)
       
   415 
       
   416     def __repr__(self):
       
   417         self.__setup()
       
   418         if len(self.__lines) <= self.MAXLINES:
       
   419             return "\n".join(self.__lines)
       
   420         else:
       
   421             return "Type %s() to see the full %s text" % ((self.__name,)*2)
       
   422 
       
   423     def __call__(self):
       
   424         self.__setup()
       
   425         prompt = 'Hit Return for more, or q (and Return) to quit: '
       
   426         lineno = 0
       
   427         while 1:
       
   428             try:
       
   429                 for i in range(lineno, lineno + self.MAXLINES):
       
   430                     print self.__lines[i]
       
   431             except IndexError:
       
   432                 break
       
   433             else:
       
   434                 lineno += self.MAXLINES
       
   435                 key = None
       
   436                 while key is None:
       
   437                     key = raw_input(prompt)
       
   438                     if key not in ('', 'q'):
       
   439                         key = None
       
   440                 if key == 'q':
       
   441                     break
       
   442 
       
   443 def setcopyright():
       
   444     """Set 'copyright' and 'credits' in __builtin__"""
       
   445     __builtin__.copyright = _Printer("copyright", sys.copyright)
       
   446     if sys.platform[:4] == 'java':
       
   447         __builtin__.credits = _Printer(
       
   448             "credits",
       
   449             "Jython is maintained by the Jython developers (www.jython.org).")
       
   450     else:
       
   451         __builtin__.credits = _Printer("credits", """\
       
   452     Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
       
   453     for supporting Python development.  See www.python.org for more information.""")
       
   454     here = os.path.dirname(os.__file__)
       
   455     __builtin__.license = _Printer(
       
   456         "license", "See http://www.python.org/%.3s/license.html" % sys.version,
       
   457         ["LICENSE.txt", "LICENSE"],
       
   458         [os.path.join(here, os.pardir), here, os.curdir])
       
   459 
       
   460 
       
   461 class _Helper(object):
       
   462     """Define the built-in 'help'.
       
   463     This is a wrapper around pydoc.help (with a twist).
       
   464 
       
   465     """
       
   466 
       
   467     def __repr__(self):
       
   468         return "Type help() for interactive help, " \
       
   469                "or help(object) for help about object."
       
   470     def __call__(self, *args, **kwds):
       
   471         import pydoc
       
   472         return pydoc.help(*args, **kwds)
       
   473 
       
   474 def sethelper():
       
   475     __builtin__.help = _Helper()
       
   476 
       
   477 def aliasmbcs():
       
   478     """On Windows, some default encodings are not provided by Python,
       
   479     while they are always available as "mbcs" in each locale. Make
       
   480     them usable by aliasing to "mbcs" in such a case."""
       
   481     if sys.platform == 'win32':
       
   482         import locale, codecs
       
   483         enc = locale.getdefaultlocale()[1]
       
   484         if enc.startswith('cp'):            # "cp***" ?
       
   485             try:
       
   486                 codecs.lookup(enc)
       
   487             except LookupError:
       
   488                 import encodings
       
   489                 encodings._cache[enc] = encodings._unknown
       
   490                 encodings.aliases.aliases[enc] = 'mbcs'
       
   491 
       
   492 def setencoding():
       
   493     """Set the string encoding used by the Unicode implementation.  The
       
   494     default is 'ascii', but if you're willing to experiment, you can
       
   495     change this."""
       
   496     encoding = "ascii" # Default value set by _PyUnicode_Init()
       
   497     if 0:
       
   498         # Enable to support locale aware default string encodings.
       
   499         import locale
       
   500         loc = locale.getdefaultlocale()
       
   501         if loc[1]:
       
   502             encoding = loc[1]
       
   503     if 0:
       
   504         # Enable to switch off string to Unicode coercion and implicit
       
   505         # Unicode to string conversion.
       
   506         encoding = "undefined"
       
   507     if encoding != "ascii":
       
   508         # On Non-Unicode builds this will raise an AttributeError...
       
   509         sys.setdefaultencoding(encoding) # Needs Python Unicode build !
       
   510 
       
   511 
       
   512 def execsitecustomize():
       
   513     """Run custom site specific code, if available."""
       
   514     try:
       
   515         import sitecustomize
       
   516     except ImportError:
       
   517         pass
       
   518     except Exception:
       
   519         if sys.flags.verbose:
       
   520             sys.excepthook(*sys.exc_info())
       
   521         else:
       
   522             print >>sys.stderr, \
       
   523                 "'import sitecustomize' failed; use -v for traceback"
       
   524 
       
   525 
       
   526 def execusercustomize():
       
   527     """Run custom user specific code, if available."""
       
   528     try:
       
   529         import usercustomize
       
   530     except ImportError:
       
   531         pass
       
   532     except Exception:
       
   533         if sys.flags.verbose:
       
   534             sys.excepthook(*sys.exc_info())
       
   535         else:
       
   536             print>>sys.stderr, \
       
   537                 "'import usercustomize' failed; use -v for traceback"
       
   538 
       
   539 
       
   540 def main():
       
   541     global ENABLE_USER_SITE
       
   542 
       
   543     abs__file__()
       
   544     known_paths = removeduppaths()
       
   545     if ENABLE_USER_SITE is None:
       
   546         ENABLE_USER_SITE = check_enableusersite()
       
   547     known_paths = addusersitepackages(known_paths)
       
   548     known_paths = addsitepackages(known_paths)
       
   549     if sys.platform == 'os2emx':
       
   550         setBEGINLIBPATH()
       
   551     setquit()
       
   552     setcopyright()
       
   553     sethelper()
       
   554     aliasmbcs()
       
   555     setencoding()
       
   556     execsitecustomize()
       
   557     if ENABLE_USER_SITE:
       
   558         execusercustomize()
       
   559     # Remove sys.setdefaultencoding() so that users cannot change the
       
   560     # encoding after initialization.  The test for presence is needed when
       
   561     # this module is run as a script, because this code is executed twice.
       
   562     if hasattr(sys, "setdefaultencoding"):
       
   563         del sys.setdefaultencoding
       
   564 
       
   565 main()
       
   566 
       
   567 def _script():
       
   568     help = """\
       
   569     %s [--user-base] [--user-site]
       
   570 
       
   571     Without arguments print some useful information
       
   572     With arguments print the value of USER_BASE and/or USER_SITE separated
       
   573     by '%s'.
       
   574 
       
   575     Exit codes with --user-base or --user-site:
       
   576       0 - user site directory is enabled
       
   577       1 - user site directory is disabled by user
       
   578       2 - uses site directory is disabled by super user
       
   579           or for security reasons
       
   580      >2 - unknown error
       
   581     """
       
   582     args = sys.argv[1:]
       
   583     if not args:
       
   584         print "sys.path = ["
       
   585         for dir in sys.path:
       
   586             print "    %r," % (dir,)
       
   587         print "]"
       
   588         print "USER_BASE: %r (%s)" % (USER_BASE,
       
   589             "exists" if os.path.isdir(USER_BASE) else "doesn't exist")
       
   590         print "USER_SITE: %r (%s)" % (USER_SITE,
       
   591             "exists" if os.path.isdir(USER_SITE) else "doesn't exist")
       
   592         print "ENABLE_USER_SITE: %r" %  ENABLE_USER_SITE
       
   593         sys.exit(0)
       
   594 
       
   595     buffer = []
       
   596     if '--user-base' in args:
       
   597         buffer.append(USER_BASE)
       
   598     if '--user-site' in args:
       
   599         buffer.append(USER_SITE)
       
   600 
       
   601     if buffer:
       
   602         print os.pathsep.join(buffer)
       
   603         if ENABLE_USER_SITE:
       
   604             sys.exit(0)
       
   605         elif ENABLE_USER_SITE is False:
       
   606             sys.exit(1)
       
   607         elif ENABLE_USER_SITE is None:
       
   608             sys.exit(2)
       
   609         else:
       
   610             sys.exit(3)
       
   611     else:
       
   612         import textwrap
       
   613         print textwrap.dedent(help % (sys.argv[0], os.pathsep))
       
   614         sys.exit(10)
       
   615 
       
   616 if __name__ == '__main__':
       
   617     _script()