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