home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1800 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  4.2 KB  |  127 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import subprocess
  5. from subprocess import PIPE
  6. import sys
  7. import os
  8. import types
  9.  
  10. try:
  11.     from subprocess import CalledProcessError
  12. except ImportError:
  13.     
  14.     class CalledProcessError(Exception):
  15.         
  16.         def __init__(self, returncode, cmd):
  17.             self.returncode = returncode
  18.             self.cmd = cmd
  19.  
  20.         
  21.         def __str__(self):
  22.             return "Command '%s' returned non-zero exit status %d" % (self.cmd, self.returncode)
  23.  
  24.  
  25.  
  26. mswindows = sys.platform == 'win32'
  27. skip = False
  28. if mswindows:
  29.     import platform
  30.     if platform.uname()[3] == '' or platform.uname()[3] > '6.0.6000':
  31.         skip = True
  32.     else:
  33.         import winprocess
  34. else:
  35.     import signal
  36. if not mswindows:
  37.     
  38.     def DoNothing(*args):
  39.         pass
  40.  
  41.  
  42. if skip:
  43.     Popen = subprocess.Popen
  44. else:
  45.     
  46.     class Popen(subprocess.Popen):
  47.         if not mswindows:
  48.             
  49.             def __init__(self, *args, **kwargs):
  50.                 if len(args) >= 7:
  51.                     raise Exception('Arguments preexec_fn and after must be passed by keyword.')
  52.                 len(args) >= 7
  53.                 real_preexec_fn = kwargs.pop('preexec_fn', None)
  54.                 
  55.                 def setpgid_preexec_fn():
  56.                     os.setpgid(0, 0)
  57.                     if real_preexec_fn:
  58.                         apply(real_preexec_fn)
  59.                     
  60.  
  61.                 kwargs['preexec_fn'] = setpgid_preexec_fn
  62.                 subprocess.Popen.__init__(self, *args, **kwargs)
  63.  
  64.         
  65.         if mswindows:
  66.             
  67.             def _execute_child(self, args, executable, preexec_fn, close_fds, cwd, env, universal_newlines, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite):
  68.                 if not isinstance(args, types.StringTypes):
  69.                     args = subprocess.list2cmdline(args)
  70.                 
  71.                 if startupinfo is None:
  72.                     startupinfo = winprocess.STARTUPINFO()
  73.                 
  74.                 if None not in (p2cread, c2pwrite, errwrite):
  75.                     startupinfo.dwFlags |= winprocess.STARTF_USESTDHANDLES
  76.                     startupinfo.hStdInput = int(p2cread)
  77.                     startupinfo.hStdOutput = int(c2pwrite)
  78.                     startupinfo.hStdError = int(errwrite)
  79.                 
  80.                 if shell:
  81.                     startupinfo.dwFlags |= winprocess.STARTF_USESHOWWINDOW
  82.                     startupinfo.wShowWindow = winprocess.SW_HIDE
  83.                     comspec = os.environ.get('COMSPEC', 'cmd.exe')
  84.                     args = comspec + ' /c ' + args
  85.                 
  86.                 self._job = winprocess.CreateJobObject()
  87.                 creationflags |= winprocess.CREATE_SUSPENDED
  88.                 creationflags |= winprocess.CREATE_UNICODE_ENVIRONMENT
  89.                 (hp, ht, pid, tid) = winprocess.CreateProcess(executable, args, None, None, 1, creationflags, winprocess.EnvironmentBlock(env), cwd, startupinfo)
  90.                 self._child_created = True
  91.                 self._handle = hp
  92.                 self._thread = ht
  93.                 self.pid = pid
  94.                 
  95.                 try:
  96.                     winprocess.AssignProcessToJobObject(self._job, hp)
  97.                 except WindowsError:
  98.                     pass
  99.  
  100.                 winprocess.ResumeThread(ht)
  101.                 if p2cread is not None:
  102.                     p2cread.Close()
  103.                 
  104.                 if c2pwrite is not None:
  105.                     c2pwrite.Close()
  106.                 
  107.                 if errwrite is not None:
  108.                     errwrite.Close()
  109.                 
  110.  
  111.         
  112.         
  113.         def kill(self, group = True):
  114.             if mswindows:
  115.                 if group:
  116.                     winprocess.TerminateJobObject(self._job, 127)
  117.                 else:
  118.                     winprocess.TerminateProcess(self._handle, 127)
  119.                 self.returncode = 127
  120.             elif group:
  121.                 os.killpg(self.pid, signal.SIGKILL)
  122.             else:
  123.                 os.kill(self.pid, signal.SIGKILL)
  124.             self.returncode = -9
  125.  
  126.  
  127.