Python distutils.spawn() Examples
The following are 11
code examples of distutils.spawn().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
distutils
, or try the search function
.
Example #1
Source File: test_mpiActions.py From armi with Apache License 2.0 | 6 votes |
def testDistribute(self): """ Calls a subprocess to spawn new tests. The subprocess is redirected to dev/null (windows <any-dir>\\NUL), to prevent excessive output. In order to debug, this test you will likely need to modify this code. """ args = ["mpiexec", "-n", "2", "python", "-m", "unittest"] args += ["armi.tests.test_mpiActions.MpiDistributeStateTests"] with open(os.devnull, "w") as null: # check_call needed because call will just keep going in the event # of failures. subprocess.check_call(args, stdout=null, stderr=subprocess.STDOUT) # these two must be defined up here so that they can be pickled
Example #2
Source File: client.py From ATX with Apache License 2.0 | 6 votes |
def adb_path(cls): """return adb binary full path""" if cls.__adb_cmd is None: if "ANDROID_HOME" in os.environ: filename = "adb.exe" if os.name == 'nt' else "adb" adb_dir = os.path.join(os.environ["ANDROID_HOME"], "platform-tools") adb_cmd = os.path.join(adb_dir, filename) if not os.path.exists(adb_cmd): raise EnvironmentError( "Adb not found in $ANDROID_HOME/platform-tools path: %s." % adb_dir) else: import distutils if "spawn" not in dir(distutils): import distutils.spawn adb_cmd = distutils.spawn.find_executable("adb") if adb_cmd: adb_cmd = os.path.realpath(adb_cmd) else: raise EnvironmentError("$ANDROID_HOME environment not set.") cls.__adb_cmd = adb_cmd return cls.__adb_cmd
Example #3
Source File: adb_old.py From ATX with Apache License 2.0 | 6 votes |
def adb(cls): """return adb binary full path""" if cls.__adb_cmd is None: if "ANDROID_HOME" in os.environ: filename = "adb.exe" if os.name == 'nt' else "adb" adb_cmd = os.path.join(os.environ["ANDROID_HOME"], "platform-tools", filename) if not os.path.exists(adb_cmd): raise EnvironmentError( "Adb not found in $ANDROID_HOME path: %s." % os.environ["ANDROID_HOME"]) else: import distutils if "spawn" not in dir(distutils): import distutils.spawn adb_cmd = distutils.spawn.find_executable("adb") if adb_cmd: adb_cmd = os.path.realpath(adb_cmd) else: raise EnvironmentError("$ANDROID_HOME environment not set.") cls.__adb_cmd = adb_cmd return cls.__adb_cmd
Example #4
Source File: test_JobRunner.py From civet with Apache License 2.0 | 5 votes |
def test_kill_job(self): with JobRunner.temp_file() as script: script.write(b"sleep 30") script.close() with open(os.devnull, "wb") as devnull: r = self.create_runner() proc = r.create_process(script.name, {}, devnull) r.kill_job(proc) self.assertEqual(proc.poll(), -15) # SIGTERM proc.wait() # get some coverage when the proc is already dead r.kill_job(proc) # the kill path for windows is different, just get some # coverage because we don't currently have a windows box # to test on with patch.object(platform, 'system') as mock_system: mock_system.side_effect = ["linux", "Windows"] proc = r.create_process(script.name, {}, devnull) r.kill_job(proc) with patch.object(spawn, 'find_executable') as mock_find: mock_system.side_effect = ["Windows"] mock_find.return_value = True r.kill_job(proc) # mimic not being able to kill the job with patch.object(subprocess.Popen, 'poll') as mock_poll, patch.object(subprocess.Popen, 'kill') as mock_kill: mock_poll.side_effect = [True, None, None] mock_kill.return_value = False proc = r.create_process(script.name, {}, devnull) r.kill_job(proc)
Example #5
Source File: sync_client.py From ray with Apache License 2.0 | 5 votes |
def get_cloud_sync_client(remote_path): """Returns a CommandBasedClient that can sync to/from remote storage. Args: remote_path (str): Path to remote storage (S3 or GS). Raises: ValueError if malformed remote_dir. """ if remote_path.startswith(S3_PREFIX): if not distutils.spawn.find_executable("aws"): raise ValueError( "Upload uri starting with '{}' requires awscli tool" " to be installed".format(S3_PREFIX)) template = "aws s3 sync {source} {target} --only-show-errors" delete_template = "aws s3 rm {target} --recursive --only-show-errors" elif remote_path.startswith(GS_PREFIX): if not distutils.spawn.find_executable("gsutil"): raise ValueError( "Upload uri starting with '{}' requires gsutil tool" " to be installed".format(GS_PREFIX)) template = "gsutil rsync -r {source} {target}" delete_template = "gsutil rm -r {target}" else: raise ValueError("Upload uri must start with one of: {}" "".format(ALLOWED_REMOTE_PREFIXES)) return CommandBasedClient(template, template, delete_template)
Example #6
Source File: test_job.py From pycondor with MIT License | 5 votes |
def monkeypatch_condor_submit(monkeypatch): # Want to monkeypatch shutil.which to mimic condor_submit existing version_major = sys.version_info.major version_minor = sys.version_info.minor if (version_major, version_minor) >= (3, 3): monkeypatch.setattr(shutil, 'which', lambda x: 'submit_exists.exe') else: monkeypatch.setattr(spawn, 'find_executable', lambda x: 'submit_exists.exe')
Example #7
Source File: subprocess.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def _setup_platform(): """Setup the shell command and the command line argument escape function depending on the underlying platform """ global _cmdline2listimpl, _escape_args, _shell_command if os._name in _win_oses: _cmdline2listimpl = _cmdline2list _escape_args = lambda args: [list2cmdline([arg]) for arg in args] else: _cmdline2listimpl = lambda args: [args] _escape_args = lambda args: args for shell_command in os._get_shell_commands(): executable = shell_command[0] if not os.path.isabs(executable): import distutils.spawn executable = distutils.spawn.find_executable(executable) if not executable or not os.path.exists(executable): continue shell_command[0] = executable _shell_command = shell_command return if not _shell_command: import warnings warnings.warn('Unable to determine _shell_command for ' 'underlying os: %s' % os._name, RuntimeWarning, 3)
Example #8
Source File: subprocess.py From medicare-demo with Apache License 2.0 | 4 votes |
def _setup_platform(): """Setup the shell command and the command line argument escape function depending on the underlying platform """ global _cmdline2listimpl, _escape_args, _shell_command if os._name in _win_oses: _cmdline2listimpl = _cmdline2list _escape_args = lambda args: [list2cmdline([arg]) for arg in args] else: _cmdline2listimpl = lambda args: [args] _escape_args = lambda args: args for shell_command in os._get_shell_commands(): executable = shell_command[0] if not os.path.isabs(executable): import distutils.spawn executable = distutils.spawn.find_executable(executable) if not executable or not os.path.exists(executable): continue shell_command[0] = executable _shell_command = shell_command return if not _shell_command: import warnings warnings.warn('Unable to determine _shell_command for ' 'underlying os: %s' % os._name, RuntimeWarning, 3)
Example #9
Source File: subprocess.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 4 votes |
def _setup_platform(): """Setup the shell command and the command line argument escape function depending on the underlying platform """ global _cmdline2listimpl, _escape_args, _shell_command if os._name in _win_oses: _cmdline2listimpl = _cmdline2list _escape_args = lambda args: [list2cmdline([arg]) for arg in args] else: _cmdline2listimpl = lambda args: [args] _escape_args = lambda args: args for shell_command in os._get_shell_commands(): executable = shell_command[0] if not os.path.isabs(executable): import distutils.spawn executable = distutils.spawn.find_executable(executable) if not executable or not os.path.exists(executable): continue shell_command[0] = executable _shell_command = shell_command return if not _shell_command: import warnings warnings.warn('Unable to determine _shell_command for ' 'underlying os: %s' % os._name, RuntimeWarning, 3)
Example #10
Source File: subprocess.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 4 votes |
def _setup_platform(): """Setup the shell command and the command line argument escape function depending on the underlying platform """ global _cmdline2listimpl, _escape_args, _shell_command if os._name in _win_oses: _cmdline2listimpl = _cmdline2list _escape_args = lambda args: [list2cmdline([arg]) for arg in args] else: _cmdline2listimpl = lambda args: [args] _escape_args = lambda args: args for shell_command in os._get_shell_commands(): executable = shell_command[0] if not os.path.isabs(executable): import distutils.spawn executable = distutils.spawn.find_executable(executable) if not executable or not os.path.exists(executable): continue shell_command[0] = executable _shell_command = shell_command return if not _shell_command: import warnings warnings.warn('Unable to determine _shell_command for ' 'underlying os: %s' % os._name, RuntimeWarning, 3)
Example #11
Source File: subprocess.py From CTFCrackTools with GNU General Public License v3.0 | 4 votes |
def _setup_platform(): """Setup the shell command and the command line argument escape function depending on the underlying platform """ global _cmdline2listimpl, _escape_args, _shell_command if os._name in _win_oses: _cmdline2listimpl = _cmdline2list _escape_args = lambda args: [list2cmdline([arg]) for arg in args] else: _cmdline2listimpl = lambda args: [args] _escape_args = lambda args: args for shell_command in os._get_shell_commands(): executable = shell_command[0] if not os.path.isabs(executable): import distutils.spawn executable = distutils.spawn.find_executable(executable) if not executable or not os.path.exists(executable): continue shell_command[0] = executable _shell_command = shell_command return if not _shell_command: import warnings warnings.warn('Unable to determine _shell_command for ' 'underlying os: %s' % os._name, RuntimeWarning, 3)