home *** CD-ROM | disk | FTP | other *** search
/ PC Extra 07 & 08 / pca1507.iso / Software / psp8 / Data1.cab / site.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2003-04-22  |  10.8 KB  |  334 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.2)
  3.  
  4. """Append module search paths for third-party packages to sys.path.
  5.  
  6. ****************************************************************
  7. * This module is automatically imported during initialization. *
  8. ****************************************************************
  9.  
  10. In earlier versions of Python (up to 1.5a3), scripts or modules that
  11. needed to use site-specific modules would place ``import site''
  12. somewhere near the top of their code.  Because of the automatic
  13. import, this is no longer necessary (but code that does it still
  14. works).
  15.  
  16. This will append site-specific paths to to the module search path.  On
  17. Unix, it starts with sys.prefix and sys.exec_prefix (if different) and
  18. appends lib/python<version>/site-packages as well as lib/site-python.
  19. On other platforms (mainly Mac and Windows), it uses just sys.prefix
  20. (and sys.exec_prefix, if different, but this is unlikely).  The
  21. resulting directories, if they exist, are appended to sys.path, and
  22. also inspected for path configuration files.
  23.  
  24. A path configuration file is a file whose name has the form
  25. <package>.pth; its contents are additional directories (one per line)
  26. to be added to sys.path.  Non-existing directories (or
  27. non-directories) are never added to sys.path; no directory is added to
  28. sys.path more than once.  Blank lines and lines beginning with
  29. '#' are skipped. Lines starting with 'import' are executed.
  30.  
  31. For example, suppose sys.prefix and sys.exec_prefix are set to
  32. /usr/local and there is a directory /usr/local/lib/python1.5/site-packages
  33. with three subdirectories, foo, bar and spam, and two path
  34. configuration files, foo.pth and bar.pth.  Assume foo.pth contains the
  35. following:
  36.  
  37.   # foo package configuration
  38.   foo
  39.   bar
  40.   bletch
  41.  
  42. and bar.pth contains:
  43.  
  44.   # bar package configuration
  45.   bar
  46.  
  47. Then the following directories are added to sys.path, in this order:
  48.  
  49.   /usr/local/lib/python1.5/site-packages/bar
  50.   /usr/local/lib/python1.5/site-packages/foo
  51.  
  52. Note that bletch is omitted because it doesn't exist; bar precedes foo
  53. because bar.pth comes alphabetically before foo.pth; and spam is
  54. omitted because it is not mentioned in either path configuration file.
  55.  
  56. After these path manipulations, an attempt is made to import a module
  57. named sitecustomize, which can perform arbitrary additional
  58. site-specific customizations.  If this import fails with an
  59. ImportError exception, it is silently ignored.
  60.  
  61. """
  62. import sys
  63. import os
  64.  
  65. def makepath(*paths):
  66.     dir = os.path.abspath(os.path.join(*paths))
  67.     return (dir, os.path.normcase(dir))
  68.  
  69. for m in sys.modules.values():
  70.     if hasattr(m, '__file__') and m.__file__:
  71.         m.__file__ = os.path.abspath(m.__file__)
  72.     
  73.  
  74. del m
  75. L = []
  76. _dirs_in_sys_path = { }
  77. for dir in sys.path:
  78.     if sys.platform != 'mac':
  79.         if dir and not os.path.isdir(dir):
  80.             continue
  81.         
  82.     elif dir and not os.path.exists(dir):
  83.         continue
  84.     
  85.     (dir, dircase) = makepath(dir)
  86.     if not _dirs_in_sys_path.has_key(dircase):
  87.         L.append(dir)
  88.         _dirs_in_sys_path[dircase] = 1
  89.     
  90.  
  91. sys.path[:] = L
  92. del dir
  93. del L
  94. if os.name == 'posix' and os.path.basename(sys.path[-1]) == 'Modules':
  95.     from distutils.util import get_platform
  96.     s = 'build/lib.%s-%.3s' % (get_platform(), sys.version)
  97.     s = os.path.join(os.path.dirname(sys.path[-1]), s)
  98.     sys.path.append(s)
  99.     del get_platform
  100.     del s
  101.  
  102.  
  103. def _init_pathinfo():
  104.     global _dirs_in_sys_path
  105.     _dirs_in_sys_path = d = { }
  106.     for dir in sys.path:
  107.         if dir and not os.path.isdir(dir):
  108.             continue
  109.         
  110.         (dir, dircase) = makepath(dir)
  111.         d[dircase] = 1
  112.     
  113.  
  114.  
  115. def addsitedir(sitedir):
  116.     global _dirs_in_sys_path
  117.     if _dirs_in_sys_path is None:
  118.         _init_pathinfo()
  119.         reset = 1
  120.     else:
  121.         reset = 0
  122.     (sitedir, sitedircase) = makepath(sitedir)
  123.     if not _dirs_in_sys_path.has_key(sitedircase):
  124.         sys.path.append(sitedir)
  125.     
  126.     
  127.     try:
  128.         names = os.listdir(sitedir)
  129.     except os.error:
  130.         return None
  131.  
  132.     names.sort()
  133.     for name in names:
  134.         if name[-4:] == os.extsep + 'pth':
  135.             addpackage(sitedir, name)
  136.         
  137.     
  138.     if reset:
  139.         _dirs_in_sys_path = None
  140.     
  141.  
  142.  
  143. def addpackage(sitedir, name):
  144.     global _dirs_in_sys_path
  145.     if _dirs_in_sys_path is None:
  146.         _init_pathinfo()
  147.         reset = 1
  148.     else:
  149.         reset = 0
  150.     fullname = os.path.join(sitedir, name)
  151.     
  152.     try:
  153.         f = open(fullname)
  154.     except IOError:
  155.         return None
  156.  
  157.     while 1:
  158.         dir = f.readline()
  159.         if not dir:
  160.             break
  161.         
  162.         if dir[0] == '#':
  163.             continue
  164.         
  165.         if dir.startswith('import'):
  166.             exec dir
  167.             continue
  168.         
  169.         if dir[-1] == '\n':
  170.             dir = dir[:-1]
  171.         
  172.         (dir, dircase) = makepath(sitedir, dir)
  173.         if not _dirs_in_sys_path.has_key(dircase) and os.path.exists(dir):
  174.             sys.path.append(dir)
  175.             _dirs_in_sys_path[dircase] = 1
  176.         
  177.     if reset:
  178.         _dirs_in_sys_path = None
  179.     
  180.  
  181. prefixes = [
  182.     sys.prefix]
  183. if sys.exec_prefix != sys.prefix:
  184.     prefixes.append(sys.exec_prefix)
  185.  
  186. for prefix in prefixes:
  187.     if prefix:
  188.         if os.sep == '/':
  189.             sitedirs = [
  190.                 os.path.join(prefix, 'lib', 'python' + sys.version[:3], 'site-packages'),
  191.                 os.path.join(prefix, 'lib', 'site-python')]
  192.         else:
  193.             sitedirs = [
  194.                 prefix,
  195.                 os.path.join(prefix, 'lib', 'site-packages')]
  196.         for sitedir in sitedirs:
  197.             if os.path.isdir(sitedir):
  198.                 addsitedir(sitedir)
  199.             
  200.         
  201.     
  202.  
  203. _dirs_in_sys_path = None
  204. if os.sep == ':':
  205.     exit = 'Use Cmd-Q to quit.'
  206. elif os.sep == '\\':
  207.     exit = 'Use Ctrl-Z plus Return to exit.'
  208. else:
  209.     exit = 'Use Ctrl-D (i.e. EOF) to exit.'
  210. import __builtin__
  211. __builtin__.quit = __builtin__.exit = exit
  212. del exit
  213.  
  214. class _Printer:
  215.     MAXLINES = 23
  216.     
  217.     def __init__(self, name, data, files = (), dirs = ()):
  218.         self._Printer__name = name
  219.         self._Printer__data = data
  220.         self._Printer__files = files
  221.         self._Printer__dirs = dirs
  222.         self._Printer__lines = None
  223.  
  224.     
  225.     def _Printer__setup(self):
  226.         if self._Printer__lines:
  227.             return None
  228.         
  229.         data = None
  230.         for dir in self._Printer__dirs:
  231.             for file in self._Printer__files:
  232.                 file = os.path.join(dir, file)
  233.                 
  234.                 try:
  235.                     fp = open(file)
  236.                     data = fp.read()
  237.                     fp.close()
  238.                 except IOError:
  239.                     pass
  240.  
  241.             
  242.             if data:
  243.                 break
  244.             
  245.         
  246.         if not data:
  247.             data = self._Printer__data
  248.         
  249.         self._Printer__lines = data.split('\n')
  250.         self._Printer__linecnt = len(self._Printer__lines)
  251.  
  252.     
  253.     def __repr__(self):
  254.         self._Printer__setup()
  255.         if len(self._Printer__lines) <= self.MAXLINES:
  256.             return '\n'.join(self._Printer__lines)
  257.         else:
  258.             return 'Type %s() to see the full %s text' % (self._Printer__name,) * 2
  259.  
  260.     
  261.     def __call__(self):
  262.         self._Printer__setup()
  263.         prompt = 'Hit Return for more, or q (and Return) to quit: '
  264.         lineno = 0
  265.         while 1:
  266.             
  267.             try:
  268.                 for i in range(lineno, lineno + self.MAXLINES):
  269.                     print self._Printer__lines[i]
  270.             except IndexError:
  271.                 break
  272.  
  273.             lineno += self.MAXLINES
  274.             key = None
  275.             while key is None:
  276.                 key = raw_input(prompt)
  277.                 if key not in ('', 'q'):
  278.                     key = None
  279.                 
  280.             if key == 'q':
  281.                 break
  282.             
  283.  
  284.  
  285. __builtin__.copyright = _Printer('copyright', sys.copyright)
  286. if sys.platform[:4] == 'java':
  287.     __builtin__.credits = _Printer('credits', 'Jython is maintained by the Jython developers (www.jython.org).')
  288. else:
  289.     __builtin__.credits = _Printer('credits', 'Thanks to CWI, CNRI, BeOpen.com, Digital Creations and a cast of thousands\nfor supporting Python development.  See www.python.org for more information.')
  290. here = os.path.dirname(os.__file__)
  291. __builtin__.license = _Printer('license', 'See http://www.python.org/%.3s/license.html' % sys.version, [
  292.     'LICENSE.txt',
  293.     'LICENSE'], [
  294.     os.path.join(here, os.pardir),
  295.     here,
  296.     os.curdir])
  297.  
  298. class _Helper:
  299.     
  300.     def __repr__(self):
  301.         return 'Type help() for interactive help, or help(object) for help about object.'
  302.  
  303.     
  304.     def __call__(self, *args, **kwds):
  305.         import pydoc
  306.         return pydoc.help(*args, **kwds)
  307.  
  308.  
  309. __builtin__.help = _Helper()
  310. encoding = 'ascii'
  311. if encoding != 'ascii':
  312.     sys.setdefaultencoding(encoding)
  313.  
  314.  
  315. try:
  316.     import sitecustomize
  317. except ImportError:
  318.     pass
  319.  
  320. if hasattr(sys, 'setdefaultencoding'):
  321.     del sys.setdefaultencoding
  322.  
  323.  
  324. def _test():
  325.     print 'sys.path = ['
  326.     for dir in sys.path:
  327.         print '    %s,' % `dir`
  328.     
  329.     print ']'
  330.  
  331. if __name__ == '__main__':
  332.     _test()
  333.  
  334.