home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 October / maximum-cd-2011-10.iso / DiscContents / digsby_setup.exe / lib / distutils / util.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2011-06-22  |  9.5 KB  |  341 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. __revision__ = '$Id: util.py 68135 2009-01-01 15:46:10Z georg.brandl $'
  5. import sys
  6. import os
  7. import string
  8. import re
  9. from distutils.errors import DistutilsPlatformError
  10. from distutils.dep_util import newer
  11. from distutils.spawn import spawn
  12. from distutils import log
  13.  
  14. def get_platform():
  15.     if os.name == 'nt':
  16.         prefix = ' bit ('
  17.         i = string.find(sys.version, prefix)
  18.         if i == -1:
  19.             return sys.platform
  20.         j = string.find(sys.version, ')', i)
  21.         look = sys.version[i + len(prefix):j].lower()
  22.         if look == 'amd64':
  23.             return 'win-amd64'
  24.         if look == 'itanium':
  25.             return 'win-ia64'
  26.         return sys.platform
  27.     if os.name != 'posix' or not hasattr(os, 'uname'):
  28.         return sys.platform
  29.     (osname, host, release, version, machine) = os.uname()
  30.     osname = string.lower(osname)
  31.     osname = string.replace(osname, '/', '')
  32.     machine = string.replace(machine, ' ', '_')
  33.     machine = string.replace(machine, '/', '-')
  34.     if osname[:5] == 'linux':
  35.         return '%s-%s' % (osname, machine)
  36.     if osname[:5] == 'sunos':
  37.         if release[0] >= '5':
  38.             osname = 'solaris'
  39.             release = '%d.%s' % (int(release[0]) - 3, release[2:])
  40.         
  41.     elif osname[:4] == 'irix':
  42.         return '%s-%s' % (osname, release)
  43.     not hasattr(os, 'uname')
  44.     if osname[:3] == 'aix':
  45.         return '%s-%s.%s' % (osname, version, release)
  46.     if osname[:6] == 'cygwin':
  47.         osname = 'cygwin'
  48.         rel_re = re.compile('[\\d.]+')
  49.         m = rel_re.match(release)
  50.         if m:
  51.             release = m.group()
  52.         
  53.     elif osname[:6] == 'darwin':
  54.         get_config_vars = get_config_vars
  55.         import distutils.sysconfig
  56.         cfgvars = get_config_vars()
  57.         macver = os.environ.get('MACOSX_DEPLOYMENT_TARGET')
  58.         if not macver:
  59.             macver = cfgvars.get('MACOSX_DEPLOYMENT_TARGET')
  60.         
  61.         macrelease = macver
  62.         
  63.         try:
  64.             f = open('/System/Library/CoreServices/SystemVersion.plist')
  65.         except IOError:
  66.             pass
  67.  
  68.         m = re.search('<key>ProductUserVisibleVersion</key>\\s*' + '<string>(.*?)</string>', f.read())
  69.         f.close()
  70.         if m is not None:
  71.             macrelease = '.'.join(m.group(1).split('.')[:2])
  72.         
  73.         if not macver:
  74.             macver = macrelease
  75.         
  76.         if macver:
  77.             get_config_vars = get_config_vars
  78.             import distutils.sysconfig
  79.             release = macver
  80.             osname = 'macosx'
  81.             if macrelease + '.' >= '10.4.' and '-arch' in get_config_vars().get('CFLAGS', '').strip():
  82.                 machine = 'fat'
  83.                 cflags = get_config_vars().get('CFLAGS')
  84.                 if '-arch x86_64' in cflags:
  85.                     if '-arch i386' in cflags:
  86.                         machine = 'universal'
  87.                     else:
  88.                         machine = 'fat64'
  89.                 
  90.             elif machine in ('PowerPC', 'Power_Macintosh'):
  91.                 machine = 'ppc'
  92.             
  93.         
  94.     
  95.     return '%s-%s-%s' % (osname, release, machine)
  96.  
  97.  
  98. def convert_path(pathname):
  99.     if os.sep == '/':
  100.         return pathname
  101.     if not pathname:
  102.         return pathname
  103.     if pathname[0] == '/':
  104.         raise ValueError, "path '%s' cannot be absolute" % pathname
  105.     pathname[0] == '/'
  106.     if pathname[-1] == '/':
  107.         raise ValueError, "path '%s' cannot end with '/'" % pathname
  108.     pathname[-1] == '/'
  109.     paths = string.split(pathname, '/')
  110.     while '.' in paths:
  111.         paths.remove('.')
  112.         continue
  113.         pathname
  114.     if not paths:
  115.         return os.curdir
  116.     return apply(os.path.join, paths)
  117.  
  118.  
  119. def change_root(new_root, pathname):
  120.     if os.name == 'posix':
  121.         if not os.path.isabs(pathname):
  122.             return os.path.join(new_root, pathname)
  123.         return os.path.join(new_root, pathname[1:])
  124.     os.name == 'posix'
  125.     if os.name == 'nt':
  126.         (drive, path) = os.path.splitdrive(pathname)
  127.         if path[0] == '\\':
  128.             path = path[1:]
  129.         
  130.         return os.path.join(new_root, path)
  131.     if os.name == 'os2':
  132.         (drive, path) = os.path.splitdrive(pathname)
  133.         if path[0] == os.sep:
  134.             path = path[1:]
  135.         
  136.         return os.path.join(new_root, path)
  137.     if os.name == 'mac':
  138.         if not os.path.isabs(pathname):
  139.             return os.path.join(new_root, pathname)
  140.         elements = string.split(pathname, ':', 1)
  141.         pathname = ':' + elements[1]
  142.         return os.path.join(new_root, pathname)
  143.     os.name == 'mac'
  144.     raise DistutilsPlatformError, "nothing known about platform '%s'" % os.name
  145.  
  146. _environ_checked = 0
  147.  
  148. def check_environ():
  149.     global _environ_checked
  150.     if _environ_checked:
  151.         return None
  152.     if os.name == 'posix' and 'HOME' not in os.environ:
  153.         import pwd
  154.         os.environ['HOME'] = pwd.getpwuid(os.getuid())[5]
  155.     
  156.     if 'PLAT' not in os.environ:
  157.         os.environ['PLAT'] = get_platform()
  158.     
  159.     _environ_checked = 1
  160.  
  161.  
  162. def subst_vars(s, local_vars):
  163.     check_environ()
  164.     
  165.     def _subst(match, local_vars = local_vars):
  166.         var_name = match.group(1)
  167.         if var_name in local_vars:
  168.             return str(local_vars[var_name])
  169.         return os.environ[var_name]
  170.  
  171.     
  172.     try:
  173.         return re.sub('\\$([a-zA-Z_][a-zA-Z_0-9]*)', _subst, s)
  174.     except KeyError:
  175.         var = None
  176.         raise ValueError, "invalid variable '$%s'" % var
  177.  
  178.  
  179.  
  180. def grok_environment_error(exc, prefix = 'error: '):
  181.     if hasattr(exc, 'filename') and hasattr(exc, 'strerror'):
  182.         if exc.filename:
  183.             error = prefix + '%s: %s' % (exc.filename, exc.strerror)
  184.         else:
  185.             error = prefix + '%s' % exc.strerror
  186.     else:
  187.         error = prefix + str(exc[-1])
  188.     return error
  189.  
  190. _wordchars_re = None
  191. _squote_re = None
  192. _dquote_re = None
  193.  
  194. def _init_regex():
  195.     global _wordchars_re, _squote_re, _dquote_re
  196.     _wordchars_re = re.compile('[^\\\\\\\'\\"%s ]*' % string.whitespace)
  197.     _squote_re = re.compile("'(?:[^'\\\\]|\\\\.)*'")
  198.     _dquote_re = re.compile('"(?:[^"\\\\]|\\\\.)*"')
  199.  
  200.  
  201. def split_quoted(s):
  202.     if _wordchars_re is None:
  203.         _init_regex()
  204.     
  205.     s = string.strip(s)
  206.     words = []
  207.     pos = 0
  208.     while s:
  209.         m = _wordchars_re.match(s, pos)
  210.         end = m.end()
  211.         if end == len(s):
  212.             words.append(s[:end])
  213.             break
  214.         
  215.         if s[end] in string.whitespace:
  216.             words.append(s[:end])
  217.             s = string.lstrip(s[end:])
  218.             pos = 0
  219.         elif s[end] == '\\':
  220.             s = s[:end] + s[end + 1:]
  221.             pos = end + 1
  222.         elif s[end] == "'":
  223.             m = _squote_re.match(s, end)
  224.         elif s[end] == '"':
  225.             m = _dquote_re.match(s, end)
  226.         else:
  227.             raise RuntimeError, "this can't happen (bad char '%c')" % s[end]
  228.         if s[end] in string.whitespace is None:
  229.             raise ValueError, 'bad string (mismatched %s quotes?)' % s[end]
  230.         s[end] in string.whitespace is None
  231.         (beg, end) = m.span()
  232.         s = s[:beg] + s[beg + 1:end - 1] + s[end:]
  233.         pos = m.end() - 2
  234.         if pos >= len(s):
  235.             words.append(s)
  236.             break
  237.             continue
  238.     return words
  239.  
  240.  
  241. def execute(func, args, msg = None, verbose = 0, dry_run = 0):
  242.     if msg is None:
  243.         msg = '%s%r' % (func.__name__, args)
  244.         if msg[-2:] == ',)':
  245.             msg = msg[0:-2] + ')'
  246.         
  247.     
  248.     log.info(msg)
  249.     if not dry_run:
  250.         apply(func, args)
  251.     
  252.  
  253.  
  254. def strtobool(val):
  255.     val = string.lower(val)
  256.     if val in ('y', 'yes', 't', 'true', 'on', '1'):
  257.         return 1
  258.     if val in ('n', 'no', 'f', 'false', 'off', '0'):
  259.         return 0
  260.     raise ValueError, 'invalid truth value %r' % (val,)
  261.  
  262.  
  263. def byte_compile(py_files, optimize = 0, force = 0, prefix = None, base_dir = None, verbose = 1, dry_run = 0, direct = None):
  264.     if direct is None:
  265.         if __debug__:
  266.             pass
  267.         direct = optimize == 0
  268.     
  269.     if not direct:
  270.         
  271.         try:
  272.             mkstemp = mkstemp
  273.             import tempfile
  274.             (script_fd, script_name) = mkstemp('.py')
  275.         except ImportError:
  276.             mktemp = mktemp
  277.             import tempfile
  278.             script_fd = None
  279.             script_name = mktemp('.py')
  280.  
  281.         log.info("writing byte-compilation script '%s'", script_name)
  282.         if not dry_run:
  283.             if script_fd is not None:
  284.                 script = os.fdopen(script_fd, 'w')
  285.             else:
  286.                 script = open(script_name, 'w')
  287.             script.write('from distutils.util import byte_compile\nfiles = [\n')
  288.             script.write(string.join(map(repr, py_files), ',\n') + ']\n')
  289.             script.write('\nbyte_compile(files, optimize=%r, force=%r,\n             prefix=%r, base_dir=%r,\n             verbose=%r, dry_run=0,\n             direct=1)\n' % (optimize, force, prefix, base_dir, verbose))
  290.             script.close()
  291.         
  292.         cmd = [
  293.             sys.executable,
  294.             script_name]
  295.         if optimize == 1:
  296.             cmd.insert(1, '-O')
  297.         elif optimize == 2:
  298.             cmd.insert(1, '-OO')
  299.         
  300.         spawn(cmd, dry_run = dry_run)
  301.         execute(os.remove, (script_name,), 'removing %s' % script_name, dry_run = dry_run)
  302.     else:
  303.         compile = compile
  304.         import py_compile
  305.         for file in py_files:
  306.             if file[-3:] != '.py':
  307.                 continue
  308.             
  309.             if not __debug__ or 'c':
  310.                 pass
  311.             cfile = file + 'o'
  312.             dfile = file
  313.             if prefix:
  314.                 if file[:len(prefix)] != prefix:
  315.                     raise ValueError, "invalid prefix: filename %r doesn't start with %r" % (file, prefix)
  316.                 file[:len(prefix)] != prefix
  317.                 dfile = dfile[len(prefix):]
  318.             
  319.             if base_dir:
  320.                 dfile = os.path.join(base_dir, dfile)
  321.             
  322.             cfile_base = os.path.basename(cfile)
  323.             if direct:
  324.                 if force or newer(file, cfile):
  325.                     log.info('byte-compiling %s to %s', file, cfile_base)
  326.                     if not dry_run:
  327.                         compile(file, cfile, dfile)
  328.                     
  329.                 else:
  330.                     log.debug('skipping byte-compilation of %s to %s', file, cfile_base)
  331.             newer(file, cfile)
  332.         
  333.  
  334.  
  335. def rfc822_escape(header):
  336.     lines = string.split(header, '\n')
  337.     lines = map(string.strip, lines)
  338.     header = string.join(lines, '\n' + '        ')
  339.     return header
  340.  
  341.