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

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. __revision__ = '$Id: spawn.py 37828 2004-11-10 22:23:15Z loewis $'
  5. import sys
  6. import os
  7. import string
  8. from distutils.errors import *
  9. from distutils import log
  10.  
  11. def spawn(cmd, search_path = 1, verbose = 0, dry_run = 0):
  12.     if os.name == 'posix':
  13.         _spawn_posix(cmd, search_path, dry_run = dry_run)
  14.     elif os.name == 'nt':
  15.         _spawn_nt(cmd, search_path, dry_run = dry_run)
  16.     elif os.name == 'os2':
  17.         _spawn_os2(cmd, search_path, dry_run = dry_run)
  18.     else:
  19.         raise DistutilsPlatformError, "don't know how to spawn programs on platform '%s'" % os.name
  20.     return os.name == 'posix'
  21.  
  22.  
  23. def _nt_quote_args(args):
  24.     for i in range(len(args)):
  25.         if string.find(args[i], ' ') != -1:
  26.             args[i] = '"%s"' % args[i]
  27.             continue
  28.     
  29.     return args
  30.  
  31.  
  32. def _spawn_nt(cmd, search_path = 1, verbose = 0, dry_run = 0):
  33.     executable = cmd[0]
  34.     cmd = _nt_quote_args(cmd)
  35.     if search_path:
  36.         if not find_executable(executable):
  37.             pass
  38.         executable = executable
  39.     
  40.     log.info(string.join([
  41.         executable] + cmd[1:], ' '))
  42.     if not dry_run:
  43.         
  44.         try:
  45.             rc = os.spawnv(os.P_WAIT, executable, cmd)
  46.         except OSError:
  47.             exc = None
  48.             raise DistutilsExecError, "command '%s' failed: %s" % (cmd[0], exc[-1])
  49.  
  50.         if rc != 0:
  51.             raise DistutilsExecError, "command '%s' failed with exit status %d" % (cmd[0], rc)
  52.         rc != 0
  53.     
  54.  
  55.  
  56. def _spawn_os2(cmd, search_path = 1, verbose = 0, dry_run = 0):
  57.     executable = cmd[0]
  58.     if search_path:
  59.         if not find_executable(executable):
  60.             pass
  61.         executable = executable
  62.     
  63.     log.info(string.join([
  64.         executable] + cmd[1:], ' '))
  65.     if not dry_run:
  66.         
  67.         try:
  68.             rc = os.spawnv(os.P_WAIT, executable, cmd)
  69.         except OSError:
  70.             exc = None
  71.             raise DistutilsExecError, "command '%s' failed: %s" % (cmd[0], exc[-1])
  72.  
  73.         if rc != 0:
  74.             print "command '%s' failed with exit status %d" % (cmd[0], rc)
  75.             raise DistutilsExecError, "command '%s' failed with exit status %d" % (cmd[0], rc)
  76.         rc != 0
  77.     
  78.  
  79.  
  80. def _spawn_posix(cmd, search_path = 1, verbose = 0, dry_run = 0):
  81.     log.info(string.join(cmd, ' '))
  82.     if dry_run:
  83.         return None
  84.     if not search_path or os.execvp:
  85.         pass
  86.     exec_fn = os.execv
  87.     pid = os.fork()
  88.     if pid == 0:
  89.         
  90.         try:
  91.             exec_fn(cmd[0], cmd)
  92.         except OSError:
  93.             dry_run
  94.             e = dry_run
  95.             sys.stderr.write('unable to execute %s: %s\n' % (cmd[0], e.strerror))
  96.             os._exit(1)
  97.         except:
  98.             dry_run
  99.  
  100.         sys.stderr.write('unable to execute %s for unknown reasons' % cmd[0])
  101.         os._exit(1)
  102.     else:
  103.         while None:
  104.             
  105.             try:
  106.                 (pid, status) = os.waitpid(pid, 0)
  107.             except OSError:
  108.                 exc = None
  109.                 import errno
  110.                 if exc.errno == errno.EINTR:
  111.                     continue
  112.                 
  113.                 raise DistutilsExecError, "command '%s' failed: %s" % (cmd[0], exc[-1])
  114.  
  115.             if os.WIFSIGNALED(status):
  116.                 raise DistutilsExecError, "command '%s' terminated by signal %d" % (cmd[0], os.WTERMSIG(status))
  117.             if os.WIFEXITED(status):
  118.                 exit_status = os.WEXITSTATUS(status)
  119.                 if exit_status == 0:
  120.                     return None
  121.                 raise DistutilsExecError, "command '%s' failed with exit status %d" % (cmd[0], exit_status)
  122.             os.WIFEXITED(status)
  123.             if os.WIFSTOPPED(status):
  124.                 continue
  125.                 continue
  126.             raise DistutilsExecError, "unknown error executing '%s': termination status %d" % (cmd[0], status)
  127.             continue
  128.             return None
  129.  
  130.  
  131. def find_executable(executable, path = None):
  132.     if path is None:
  133.         path = os.environ['PATH']
  134.     
  135.     paths = string.split(path, os.pathsep)
  136.     (base, ext) = os.path.splitext(executable)
  137.     if (sys.platform == 'win32' or os.name == 'os2') and ext != '.exe':
  138.         executable = executable + '.exe'
  139.     
  140.     if not os.path.isfile(executable):
  141.         for p in paths:
  142.             f = os.path.join(p, executable)
  143.             if os.path.isfile(f):
  144.                 return f
  145.         
  146.         return None
  147.     return executable
  148.  
  149.