當前位置: 首頁>>代碼示例>>Python>>正文


Python os.spawnvpe方法代碼示例

本文整理匯總了Python中os.spawnvpe方法的典型用法代碼示例。如果您正苦於以下問題:Python os.spawnvpe方法的具體用法?Python os.spawnvpe怎麽用?Python os.spawnvpe使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在os的用法示例。


在下文中一共展示了os.spawnvpe方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: winexe

# 需要導入模塊: import os [as 別名]
# 或者: from os import spawnvpe [as 別名]
def winexe(cmd):
	check_tool('winexe')
	creds = '%s/%s%%%s' % (CONF['smb_domain'], CONF['smb_user'], CONF['smb_pass'])

	run = []
	run.append(TOOLS['winexe'])
	if CONF['system']:
		run.append('--system')
	run.append('--uninstall')
	run.append('--interactive=0')
	run.append('-U')
	run.append(creds)
	run.append('//'+ CONF['smb_ip'])
	run.append(cmd)

	if not cmd.lower().startswith('cmd'):
		process = subprocess.Popen(run, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.STDOUT)

		ret = process.stdout.read()
		ret = ret.replace('\x00', '')
		return ret.strip()

	# For an interactive command line, don't use popen
	os.spawnvpe(os.P_WAIT, run[0], run, os.environ)
	return '' 
開發者ID:jrmdev,項目名稱:smbwrapper,代碼行數:27,代碼來源:smb.py

示例2: open_text_editor

# 需要導入模塊: import os [as 別名]
# 或者: from os import spawnvpe [as 別名]
def open_text_editor(data):
    if data is None:
        data = ""

    fd, path = tempfile.mkstemp()
    os.close(fd)

    with open(path, 'w') as output:
        output.write(data)

    # Get modified time before calling editor.
    orig_mtime = os.path.getmtime(path)

    editor = os.environ.get("EDITOR", "vim")
    os.spawnvpe(os.P_WAIT, editor, [editor, path], os.environ)

    with open(path, 'r') as source:
        data = source.read()

    # Check if the file has been modified, and if it has, send the update.
    new_mtime = os.path.getmtime(path)
    if new_mtime == orig_mtime:
        data = None

    os.remove(path)
    return data 
開發者ID:ParadropLabs,項目名稱:Paradrop,代碼行數:28,代碼來源:util.py

示例3: open_yaml_editor

# 需要導入模塊: import os [as 別名]
# 或者: from os import spawnvpe [as 別名]
def open_yaml_editor(data, description):
    if data is None:
        data = {}

    fd, path = tempfile.mkstemp()
    os.close(fd)

    with open(path, 'w') as output:
        if len(data) > 0:
            output.write(yaml.safe_dump(data, default_flow_style=False))
        output.write("\n")
        output.write("# You are editing the configuration for the {}.\n".format(description))
        output.write("# Blank lines and lines starting with '#' will be ignored.\n")
        output.write("# Save and exit to apply changes; exit without saving to discard.\n")

    # Get modified time before calling editor.
    orig_mtime = os.path.getmtime(path)

    editor = os.environ.get("EDITOR", "vim")
    os.spawnvpe(os.P_WAIT, editor, [editor, path], os.environ)

    with open(path, 'r') as source:
        data = source.read()
        new_data = yaml.safe_load(data)

    # If result is null, convert to an empty dict before sending to router.
    if new_data is None:
        new_data = {}

    # Check if the file has been modified.
    new_mtime = os.path.getmtime(path)
    changed = (new_mtime != orig_mtime)

    os.remove(path)
    return new_data, changed 
開發者ID:ParadropLabs,項目名稱:Paradrop,代碼行數:37,代碼來源:util.py

示例4: shell

# 需要導入模塊: import os [as 別名]
# 或者: from os import spawnvpe [as 別名]
def shell(ctx):
    """
    Open a shell inside a chute.

    This requires you to have enabled SSH access to the device and installed
    bash inside your chute.
    """
    cmd = ["ssh", "-t", "paradrop@{}".format(ctx.obj['address']), "sudo", "docker",
            "exec", "-it", ctx.obj['chute'], "/bin/bash"]
    os.spawnvpe(os.P_WAIT, "ssh", cmd, os.environ) 
開發者ID:ParadropLabs,項目名稱:Paradrop,代碼行數:12,代碼來源:device.py

示例5: edit

# 需要導入模塊: import os [as 別名]
# 或者: from os import spawnvpe [as 別名]
def edit(ctx):
    """
    Interactively edit the host configuration.
    """
    url = ctx.obj['base_url'] + "/config/hostconfig"
    req = router_request("GET", url, dump=False)
    config = req.json()

    fd, path = tempfile.mkstemp()
    os.close(fd)

    with open(path, 'w') as output:
        output.write(yaml.safe_dump(config, default_flow_style=False))

    # Get modified time before calling editor.
    orig_mtime = os.path.getmtime(path)

    editor = os.environ.get("EDITOR", "vim")
    os.spawnvpe(os.P_WAIT, editor, [editor, path], os.environ)

    with open(path, 'r') as source:
        data = source.read()
        config = yaml.safe_load(data)

    # Check if the file has been modified, and if it has, send the update.
    new_mtime = os.path.getmtime(path)
    if new_mtime != orig_mtime:
        data = {
            'config': config
        }
        res = router_request("PUT", url, json=data)
        result = res.json()
        ctx.invoke(watch, change_id=result['change_id'])

    os.remove(path) 
開發者ID:ParadropLabs,項目名稱:Paradrop,代碼行數:37,代碼來源:device.py

示例6: test_spawnvpe_invalid_env

# 需要導入模塊: import os [as 別名]
# 或者: from os import spawnvpe [as 別名]
def test_spawnvpe_invalid_env(self):
        self._test_invalid_env(os.spawnvpe) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:4,代碼來源:test_os.py

示例7: exec_spawnvpe

# 需要導入模塊: import os [as 別名]
# 或者: from os import spawnvpe [as 別名]
def exec_spawnvpe(l, env):
    stat = os.spawnvpe(os.P_WAIT, l[0], l, env)
    # os.spawnvpe() returns the actual exit code, not the encoding
    # returned by os.waitpid() or os.system().
    return stat 
開發者ID:coin3d,項目名稱:pivy,代碼行數:7,代碼來源:posix.py

示例8: create_spawnve

# 需要導入模塊: import os [as 別名]
# 或者: from os import spawnvpe [as 別名]
def create_spawnve(original_name):
    """
    os.spawnve(mode, path, args, env)
    os.spawnvpe(mode, file, args, env)
    """

    def new_spawnve(mode, path, args, env):
        if _get_apply_arg_patching():
            args = patch_args(args)
            send_process_created_message()

        return getattr(os, original_name)(mode, path, args, env)

    return new_spawnve 
開發者ID:fabioz,項目名稱:PyDev.Debugger,代碼行數:16,代碼來源:pydev_monkey.py

示例9: patch_new_process_functions_with_warning

# 需要導入模塊: import os [as 別名]
# 或者: from os import spawnvpe [as 別名]
def patch_new_process_functions_with_warning():
    monkey_patch_os('execl', create_warn_multiproc)
    monkey_patch_os('execle', create_warn_multiproc)
    monkey_patch_os('execlp', create_warn_multiproc)
    monkey_patch_os('execlpe', create_warn_multiproc)
    monkey_patch_os('execv', create_warn_multiproc)
    monkey_patch_os('execve', create_warn_multiproc)
    monkey_patch_os('execvp', create_warn_multiproc)
    monkey_patch_os('execvpe', create_warn_multiproc)
    monkey_patch_os('spawnl', create_warn_multiproc)
    monkey_patch_os('spawnle', create_warn_multiproc)
    monkey_patch_os('spawnlp', create_warn_multiproc)
    monkey_patch_os('spawnlpe', create_warn_multiproc)
    monkey_patch_os('spawnv', create_warn_multiproc)
    monkey_patch_os('spawnve', create_warn_multiproc)
    monkey_patch_os('spawnvp', create_warn_multiproc)
    monkey_patch_os('spawnvpe', create_warn_multiproc)
    monkey_patch_os('posix_spawn', create_warn_multiproc)

    if not IS_JYTHON:
        if not IS_WINDOWS:
            monkey_patch_os('fork', create_warn_multiproc)
            try:
                import _posixsubprocess
                monkey_patch_module(_posixsubprocess, 'fork_exec', create_warn_fork_exec)
            except ImportError:
                pass
        else:
            # Windows
            try:
                import _subprocess
            except ImportError:
                import _winapi as _subprocess
            monkey_patch_module(_subprocess, 'CreateProcess', create_CreateProcessWarnMultiproc) 
開發者ID:fabioz,項目名稱:PyDev.Debugger,代碼行數:36,代碼來源:pydev_monkey.py

示例10: execve_from

# 需要導入模塊: import os [as 別名]
# 或者: from os import spawnvpe [as 別名]
def execve_from(self, conf, cmd, env):
        """ this code is commonly run in a child process // returns exit-code"""
        runs = conf.get("Service", "Type", "simple").lower()
        logg.debug("%s process for %s", runs, conf.filename())
        inp = open("/dev/zero")
        out = self.open_journal_log(conf)
        os.dup2(inp.fileno(), sys.stdin.fileno())
        os.dup2(out.fileno(), sys.stdout.fileno())
        os.dup2(out.fileno(), sys.stderr.fileno())
        runuser = self.expand_special(conf.get("Service", "User", ""), conf)
        rungroup = self.expand_special(conf.get("Service", "Group", ""), conf)
        envs = shutil_setuid(runuser, rungroup)
        badpath = self.chdir_workingdir(conf) # some dirs need setuid before
        if badpath:
            logg.error("(%s): bad workingdir: '%s'", shell_cmd(cmd), badpath)
            sys.exit(1)
        env = self.extend_exec_env(env)
        env.update(envs) # set $HOME to ~$USER
        try:
            if "spawn" in COVERAGE:
                os.spawnvpe(os.P_WAIT, cmd[0], cmd, env)
                sys.exit(0)
            else: # pragma: nocover
                os.execve(cmd[0], cmd, env)
        except Exception as e:
            logg.error("(%s): %s", shell_cmd(cmd), e)
            sys.exit(1) 
開發者ID:vanilla,項目名稱:vanilla-docker,代碼行數:29,代碼來源:systemctl3.py

示例11: execute_command

# 需要導入模塊: import os [as 別名]
# 或者: from os import spawnvpe [as 別名]
def execute_command(self, parts, dry_run):
        """
        Execute a command.

        Parameters
        ----------
        parts : list
            Sequence of strings constituting a command.
        dry_run : bool
            Whether to just log the command instead of executing it.

        Returns
        -------
        status : int
            Status code of the executed command or 0 if `dry_run` is `True`.
        """
        if dry_run:
            self.logger.info("dry-run command '%s'", " ".join(map(str, parts)))
            return 0
        else:  # pragma: no cover
            self.logger.debug("executing command '%s'", " ".join(map(str, parts)))
            status_code = os.spawnvpe(os.P_WAIT, parts[0], parts, os.environ)
            if status_code:
                self.logger.warning("command '%s' returned status code %d",
                                    " ".join(map(str, parts)), status_code)
            return status_code 
開發者ID:spotify,項目名稱:docker_interface,代碼行數:28,代碼來源:base.py

示例12: test_spawnvpe_invalid_env

# 需要導入模塊: import os [as 別名]
# 或者: from os import spawnvpe [as 別名]
def test_spawnvpe_invalid_env(self):
        self._test_invalid_env(os.spawnvpe)


# The introduction of this TestCase caused at least two different errors on
# *nix buildbots. Temporarily skip this to let the buildbots move along. 
開發者ID:ShikyoKira,項目名稱:Project-New-Reign---Nemesis-Main,代碼行數:8,代碼來源:test_os.py

示例13: create_spawnve

# 需要導入模塊: import os [as 別名]
# 或者: from os import spawnvpe [as 別名]
def create_spawnve(original_name):
    """
    os.spawnve(mode, path, args, env)
    os.spawnvpe(mode, file, args, env)
    """
    def new_spawnve(mode, path, args, env):
        import os
        return getattr(os, original_name)(mode, path, patch_args(args), env)
    return new_spawnve 
開發者ID:mrknow,項目名稱:filmkodi,代碼行數:11,代碼來源:pydev_monkey.py

示例14: patch_new_process_functions_with_warning

# 需要導入模塊: import os [as 別名]
# 或者: from os import spawnvpe [as 別名]
def patch_new_process_functions_with_warning():
    monkey_patch_os('execl', create_warn_multiproc)
    monkey_patch_os('execle', create_warn_multiproc)
    monkey_patch_os('execlp', create_warn_multiproc)
    monkey_patch_os('execlpe', create_warn_multiproc)
    monkey_patch_os('execv', create_warn_multiproc)
    monkey_patch_os('execve', create_warn_multiproc)
    monkey_patch_os('execvp', create_warn_multiproc)
    monkey_patch_os('execvpe', create_warn_multiproc)
    monkey_patch_os('spawnl', create_warn_multiproc)
    monkey_patch_os('spawnle', create_warn_multiproc)
    monkey_patch_os('spawnlp', create_warn_multiproc)
    monkey_patch_os('spawnlpe', create_warn_multiproc)
    monkey_patch_os('spawnv', create_warn_multiproc)
    monkey_patch_os('spawnve', create_warn_multiproc)
    monkey_patch_os('spawnvp', create_warn_multiproc)
    monkey_patch_os('spawnvpe', create_warn_multiproc)

    if sys.platform != 'win32':
        monkey_patch_os('fork', create_warn_multiproc)
        try:
            import _posixsubprocess
            monkey_patch_module(_posixsubprocess, 'fork_exec', create_warn_fork_exec)
        except ImportError:
            pass
    else:
        # Windows
        try:
            import _subprocess
        except ImportError:
            import _winapi as _subprocess
        monkey_patch_module(_subprocess, 'CreateProcess', create_CreateProcessWarnMultiproc) 
開發者ID:mrknow,項目名稱:filmkodi,代碼行數:34,代碼來源:pydev_monkey.py

示例15: edit_environment

# 需要導入模塊: import os [as 別名]
# 或者: from os import spawnvpe [as 別名]
def edit_environment(ctx):
    """
    Interactively edit the chute environment vairables.
    """
    req = router_request("GET", ctx.obj['chute_url'], dump=False)
    info = req.json()
    old_environ = info.get('environment', None)
    if old_environ is None:
        old_environ = {}

    fd, path = tempfile.mkstemp()
    os.close(fd)

    with open(path, 'w') as output:
        if len(old_environ) > 0:
            output.write(yaml.safe_dump(old_environ, default_flow_style=False))
        output.write("\n")
        output.write("# You are editing the environment variables for the chute {}.\n"
                .format(ctx.obj['chute']))
        output.write("# Blank lines and lines starting with '#' will be ignored.\n")
        output.write("# Put each variable on a line with a colon separator, e.g. 'VARIABLE: VALUE'\n")
        output.write("# Save and exit to apply changes; exit without saving to discard.\n")

    # Get modified time before calling editor.
    orig_mtime = os.path.getmtime(path)

    editor = os.environ.get("EDITOR", "vim")
    os.spawnvpe(os.P_WAIT, editor, [editor, path], os.environ)

    with open(path, 'r') as source:
        data = source.read()
        new_environ = yaml.safe_load(data)

    # If result is null, convert to an empty dict before sending to router.
    if new_environ is None:
        new_environ = {}

    # Check if the file has been modified, and if it has, send the update.
    new_mtime = os.path.getmtime(path)
    if new_mtime != orig_mtime:
        data = {
            'environment': new_environ
        }
        url = ctx.obj['chute_url'] + "/restart"
        res = router_request("POST", url, json=data)
        data = res.json()
        ctx.invoke(watch, change_id=data['change_id'])

    os.remove(path) 
開發者ID:ParadropLabs,項目名稱:Paradrop,代碼行數:51,代碼來源:device.py


注:本文中的os.spawnvpe方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。