home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- import subprocess
- from subprocess import PIPE
- import sys
- import os
- import types
-
- try:
- from subprocess import CalledProcessError
- except ImportError:
-
- class CalledProcessError(Exception):
-
- def __init__(self, returncode, cmd):
- self.returncode = returncode
- self.cmd = cmd
-
-
- def __str__(self):
- return "Command '%s' returned non-zero exit status %d" % (self.cmd, self.returncode)
-
-
-
- mswindows = sys.platform == 'win32'
- skip = False
- if mswindows:
- import platform
- if platform.uname()[3] == '' or platform.uname()[3] > '6.0.6000':
- skip = True
- else:
- import winprocess
- else:
- import signal
- if not mswindows:
-
- def DoNothing(*args):
- pass
-
-
- if skip:
- Popen = subprocess.Popen
- else:
-
- class Popen(subprocess.Popen):
- if not mswindows:
-
- def __init__(self, *args, **kwargs):
- if len(args) >= 7:
- raise Exception('Arguments preexec_fn and after must be passed by keyword.')
- len(args) >= 7
- real_preexec_fn = kwargs.pop('preexec_fn', None)
-
- def setpgid_preexec_fn():
- os.setpgid(0, 0)
- if real_preexec_fn:
- apply(real_preexec_fn)
-
-
- kwargs['preexec_fn'] = setpgid_preexec_fn
- subprocess.Popen.__init__(self, *args, **kwargs)
-
-
- if mswindows:
-
- def _execute_child(self, args, executable, preexec_fn, close_fds, cwd, env, universal_newlines, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite):
- if not isinstance(args, types.StringTypes):
- args = subprocess.list2cmdline(args)
-
- if startupinfo is None:
- startupinfo = winprocess.STARTUPINFO()
-
- if None not in (p2cread, c2pwrite, errwrite):
- startupinfo.dwFlags |= winprocess.STARTF_USESTDHANDLES
- startupinfo.hStdInput = int(p2cread)
- startupinfo.hStdOutput = int(c2pwrite)
- startupinfo.hStdError = int(errwrite)
-
- if shell:
- startupinfo.dwFlags |= winprocess.STARTF_USESHOWWINDOW
- startupinfo.wShowWindow = winprocess.SW_HIDE
- comspec = os.environ.get('COMSPEC', 'cmd.exe')
- args = comspec + ' /c ' + args
-
- self._job = winprocess.CreateJobObject()
- creationflags |= winprocess.CREATE_SUSPENDED
- creationflags |= winprocess.CREATE_UNICODE_ENVIRONMENT
- (hp, ht, pid, tid) = winprocess.CreateProcess(executable, args, None, None, 1, creationflags, winprocess.EnvironmentBlock(env), cwd, startupinfo)
- self._child_created = True
- self._handle = hp
- self._thread = ht
- self.pid = pid
-
- try:
- winprocess.AssignProcessToJobObject(self._job, hp)
- except WindowsError:
- pass
-
- winprocess.ResumeThread(ht)
- if p2cread is not None:
- p2cread.Close()
-
- if c2pwrite is not None:
- c2pwrite.Close()
-
- if errwrite is not None:
- errwrite.Close()
-
-
-
-
- def kill(self, group = True):
- if mswindows:
- if group:
- winprocess.TerminateJobObject(self._job, 127)
- else:
- winprocess.TerminateProcess(self._handle, 127)
- self.returncode = 127
- elif group:
- os.killpg(self.pid, signal.SIGKILL)
- else:
- os.kill(self.pid, signal.SIGKILL)
- self.returncode = -9
-
-
-