• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python shlex.shsplit函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中shlex.shsplit函数的典型用法代码示例。如果您正苦于以下问题:Python shsplit函数的具体用法?Python shsplit怎么用?Python shsplit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了shsplit函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: ms_to_hscan

def ms_to_hscan(msout, focalpos, local=False):
    '''Use ms output to run H-scan.
        msout: ms output (e.g. from subpop ms)
        focalpos: Focal position of SNP on 1mb chrom.
             NOTE: Should multiply ms position by 1 million
                    and round to nearest integer.
    '''
    # Write msout to temporary file
    temp = os.getcwd()+'/temp.'+str(randint(1e8, 999999999))+'.txt'
    f = open(temp,'w')
    f.write(msout)
    f.close()
    # Run H-scan and collect output
    hformat = '/'.join(os.getcwd().split('/')[:-1])+'/bin/H-scan '

    if local:
        hformat = 'H-scan'
    args1 = shsplit(hformat+' -m -i '+temp+' -l '+str(focalpos)+' -r '+str(focalpos))
    args2 = shsplit('tail -n1')
    p1 = Popen(args1, stdout=PIPE, stderr=PIPE)
    p2 = Popen(args2, stdin = p1.stdout, stdout=PIPE, stderr=PIPE)
    p1.stdout.close()
    p1.stderr.close() #This stderr from H-scan
    hout, herr = p2.communicate()
    os.remove(temp)
    return hout.split('\t'), herr #(pos, H), error
开发者ID:ajsams,项目名称:OAS-NLS-sims-dist,代码行数:26,代码来源:nea_haps_sims.py


示例2: fromLine

 def fromLine(cls, commandStr, flagsStr):
     commandParts = shsplit(commandStr)
     flags = shsplit(flagsStr)
     env = {}
     while commandParts:
         if "=" in commandParts[0]:
             name, value = commandParts[0].split("=", 1)
             del commandParts[0]
             env[name] = value
         else:
             return cls(env, commandParts[0], list(fixArgs(commandParts[1:] + flags)))
     else:
         raise ValueError('No command specified in "%s"' % commandStr)
开发者ID:nitrofurano,项目名称:openMSX,代码行数:13,代码来源:compilers.py


示例3: send_sequences

    def send_sequences(self):
        # Send the sequence files by directory
        unique_dirs = set()
        for f in self.sequence_files:
            basedir, filename = split(f)
            unique_dirs.add(basedir)

        # Set the ASCP password to the one in the Qiita config, but remember
        # the old pass so that we can politely reset it
        old_ascp_pass = environ.get('ASPERA_SCP_PASS', '')
        environ['ASPERA_SCP_PASS'] = qiita_config.ebi_seq_xfer_pass

        for unique_dir in unique_dirs:
            # Get the list of FASTQ files to submit
            fastqs = glob(join(unique_dir, '*.fastq.gz'))

            ascp_command = 'ascp -QT -k2 -L- {0} {1}@{2}:/.'.format(
                ' '.join(fastqs), qiita_config.ebi_seq_xfer_user,
                qiita_config.ebi_seq_xfer_url)

            # Generate the command using shlex.split so that we don't have to
            # pass shell=True to subprocess.call
            ascp_command_parts = shsplit(ascp_command)

            # Don't leave the password lingering in the environment if there
            # is any error
            try:
                call(ascp_command_parts)
            finally:
                environ['ASPERA_SCP_PASS'] = old_ascp_pass
开发者ID:Jorge-C,项目名称:qiita,代码行数:30,代码来源:ebi.py


示例4: notify_post_build

    def notify_post_build(self):
        """
        Get notified that the post build stage of the topology build was
        reached.
        """
        super(OpenvSwitchNode, self).notify_post_build()

        # FIXME: this is a workaround
        self._docker_exec(
            "sed -i -e 's/port = 9001/port = 127.0.0.1:9001/g' "
            "-e 's/nodaemon=true/nodaemon=false/g' "
            "/etc/supervisord.conf"
        )

        self._supervisord = Popen(shsplit(
            'docker exec {} supervisord'.format(self.container_id)
        ))

        # Wait for the configure-ovs script to exit by polling supervisorctl
        config_timeout = 100
        i = 0
        while i < config_timeout:
            config_status = self._docker_exec(
                'supervisorctl status configure-ovs'
            )

            if 'EXITED' not in config_status:
                sleep(0.1)
            else:
                break
            i += 1

        if i == config_timeout:
            raise RuntimeError('configure-ovs did not exit!')
开发者ID:HPENetworking,项目名称:topology_docker_openvswitch,代码行数:34,代码来源:openvswitch.py


示例5: captureStdout

def captureStdout(log, commandLine):
	'''Run a command and capture what it writes to stdout.
	If the command fails or writes something to stderr, that is logged.
	Returns the captured string, or None if the command failed.
	'''
	# TODO: This is a modified copy-paste from compilers._Command.
	commandParts = shsplit(commandLine)
	env = dict(environ)
	while commandParts:
		if '=' in commandParts[0]:
			name, value = commandParts[0].split('=', 1)
			del commandParts[0]
			env[name] = value
		else:
			break
	else:
		raise ValueError(
			'No command specified in "%s"' % commandLine
			)

	if msysActive() and commandParts[0] != 'sh':
		commandParts = [
			msysShell(), '-c', shjoin(commandParts)
			]

	try:
		proc = Popen(
			commandParts, bufsize = -1, env = env,
			stdin = None, stdout = PIPE, stderr = PIPE,
			)
	except OSError, ex:
		print >> log, 'Failed to execute "%s": %s' % (commandLine, ex)
		return None
开发者ID:SaifBoras,项目名称:openMSX,代码行数:33,代码来源:executils.py


示例6: cmd_prefix

def cmd_prefix():
    """
    Determine if the current user can run privileged commands and thus
    determines the command prefix to use.

    :rtype: str
    :return: The prefix to use for privileged commands.
    """

    # Return cache if set
    if hasattr(cmd_prefix, 'prefix'):
        return cmd_prefix.prefix

    if getuid() == 0:
        # We better do not allow root
        raise RuntimeError(
            'Please do not run as root. '
            'Please configure the ip command for root execution.'
        )
        # cmd_prefix.prefix = ''
        # return cmd_prefix.prefix

    with open(devnull, 'w') as f:
        cmd = shsplit('sudo --non-interactive ip link show')
        if call(cmd, stdout=f, stderr=f) != 0:
            raise RuntimeError(
                'Please configure the ip command for root execution.'
            )

    cmd_prefix.prefix = 'sudo --non-interactive '
    return cmd_prefix.prefix
开发者ID:HPENetworking,项目名称:topology_docker,代码行数:31,代码来源:utils.py


示例7: complete_cd

 def complete_cd(self, text, line, begidx, endidx):
     args = shsplit(line)
     if len(args) >= 3:
         return []
     else:
         cand = self._complete(text)
         cand = [e for e in cand if e.endswith("/")]
         return cand
开发者ID:10sr,项目名称:archsh_py,代码行数:8,代码来源:archcmd.py


示例8: run_macs2ms

def run_macs2ms(input, local=False):
    '''Run ms 'input' in the shell and gather input.
        input: macs command line string.
        local: Specifies if local machine has msformatter
            in path (True) or in directory (False).
    '''
    msformat = '/'.join(os.getcwd().split('/')[:-1])+'/bin/msformatter '

    if local:
        msformat = 'msformatter'
    args = shsplit(input)
    args2 = shsplit(msformat)
    p1 = Popen(args, stdout=PIPE, stderr=PIPE)
    p2 = Popen(args2, stdin = p1.stdout, stdout=PIPE, stderr=PIPE)
    p1.stdout.close()
    p1.stderr.close() #This stderr is the error output from macs, which gives the trees.
    msout, mserr = p2.communicate()
    return msout, mserr
开发者ID:ajsams,项目名称:OAS-NLS-sims-dist,代码行数:18,代码来源:nea_haps_sims.py


示例9: _docker_exec

    def _docker_exec(self, command):
        """
        Execute a command inside the docker.

        :param str command: The command to execute.
        """
        return check_output(shsplit(
            'docker exec {container_id} {command}'.format(
                container_id=self.container_id, command=command.strip()
            )
        )).decode('utf8')
开发者ID:josedvq,项目名称:topology_docker,代码行数:11,代码来源:node.py


示例10: _parse_line

 def _parse_line(self, line):
     args = shsplit(line)
     eargs = []
     children = self._env.get_current_list()[0]
     for e in args:
         m = fnmatch.filter(children, e)
         if len(m) == 0:
             # if e does not match any file, use without change
             eargs.append(e)
         else:
             eargs.extend(m)
     return eargs
开发者ID:10sr,项目名称:archsh_py,代码行数:12,代码来源:archcmd.py


示例11: parse_input

    def parse_input(self):
        if self.s == "":
            self.r = []
            return

        args = shsplit(self.s)
        eargs = [args[0]]
        for a in args[1:]:
            g = glob(a)
            if len(g) == 0:
                eargs.extend([a])
            else:
                eargs.extend(g)
        self.r = eargs
        return
开发者ID:10sr,项目名称:script,代码行数:15,代码来源:play_prompt.py


示例12: py_import

def py_import():
    # args are the same as for the :edit command
    args = shsplit(vim.eval('a:args'))
    import_path = args.pop()
    text = 'import %s' % import_path
    scr = jedi.Script(text, 1, len(text), '')
    try:
        completion = scr.goto_assignments()[0]
    except IndexError:
        echo_highlight('Cannot find %s in sys.path!' % import_path)
    else:
        if completion.in_builtin_module():
            echo_highlight('%s is a builtin module.' % import_path)
        else:
            cmd_args = ' '.join([a.replace(' ', '\\ ') for a in args])
            new_buffer(completion.module_path, cmd_args)
开发者ID:evpo,项目名称:vim-config,代码行数:16,代码来源:jedi_vim.py


示例13: py_import

def py_import():
    # args are the same as for the :edit command
    args = shsplit(vim.eval("a:args"))
    import_path = args.pop()
    text = "import %s" % import_path
    scr = jedi.Script(text, 1, len(text), "")
    try:
        completion = scr.goto_assignments()[0]
    except IndexError:
        echo_highlight("Cannot find %s in sys.path!" % import_path)
    else:
        if completion.in_builtin_module():
            echo_highlight("%s is a builtin module." % import_path)
        else:
            cmd_args = " ".join([a.replace(" ", "\\ ") for a in args])
            new_buffer(completion.module_path, cmd_args)
开发者ID:tsaridas,项目名称:dotfiles,代码行数:16,代码来源:jedi_vim.py


示例14: _setup_system

    def _setup_system(self):
        """
        Setup the P4 image for testing.

        #. Create the CPU virtual eth pair used by the P4 switch
        #. Bring up the interfaces required to run the switch
        #. Run the switch program
        """

        if self.metadata.get('autostart', True):

            self._docker_exec(
                'ip link add name veth250 type veth peer name veth251'
            )
            self._docker_exec('ip link set dev veth250 up')
            self._docker_exec('ip link set dev veth251 up')

            # Bring up all interfaces
            # FIXME: attach only interfaces brought up by the user
            for portlbl in self.ports:
                self.set_port_state(portlbl, True)

            args = [
                '/p4factory/targets/switch/behavioral-model',
                '--no-veth',
                '--no-pcap'
            ]

            # set openflow controller IP if necessary
            if self.metadata.get('ofip', None) is not None:
                args.extend(['--of-ip', self._ofip])

            # ifaces are ready in post_build
            # start the switch program with options:
            #  -i 1 -i 2 -i 3 -i 4 ...
            for iface in self.ports.values():
                args.extend(['-i', iface])

            # redirect stdout & stderr to log file
            # run in background
            args.extend(['&>/tmp/switch.log', '&'])

            # run command
            # TODO: check for posible error code
            self._bm_daemon = Popen(shsplit(
                'docker exec {} '.format(self.container_id) + ' '.join(args)
            ))
开发者ID:HPENetworking,项目名称:topology_docker_p4switch,代码行数:47,代码来源:p4switch.py


示例15: send_xml

    def send_xml(self):
        # Send the XML files
        curl_command = self.generate_curl_command()
        curl_command_parts = shsplit(curl_command)
        temp_fd, temp_fp = mkstemp()
        call(curl_command_parts, stdout=temp_fd)
        close(temp_fd)

        with open(temp_fp, 'U') as curl_output_f:
            curl_result = curl_output_f.read()

        study_accession = None
        submission_accession = None

        if 'success="true"' in curl_result:
            LogEntry.create('Runtime', curl_result)

            print curl_result
            print "SUCCESS"

            accessions = search('<STUDY accession="(?P<study>.+?)".*?'
                                '<SUBMISSION accession="(?P<submission>.+?)"',
                                curl_result)
            if accessions is not None:
                study_accession = accessions.group('study')
                submission_accession = accessions.group('submission')

                LogEntry.create('Runtime', "Study accession:\t%s" %
                                study_accession)
                LogEntry.create('Runtime', "Submission accession:\t%s" %
                                submission_accession)

                print "Study accession:\t", study_accession
                print "Submission accession:\t", submission_accession
            else:
                LogEntry.create('Runtime', ("However, the accession numbers "
                                            "could not be found in the output "
                                            "above."))
                print ("However, the accession numbers could not be found in "
                       "the output above.")
        else:
            LogEntry.create('Fatal', curl_result)
            print curl_result
            print "FAILED"

        return (study_accession, submission_accession)
开发者ID:BrindhaBioinfo,项目名称:qiita,代码行数:46,代码来源:ebi.py


示例16: _execute

def _execute(command):
    """
    Execute a command safely and returns its output as ``utf-8``.
    """
    try:
        p = Popen(
            shsplit(command),
            stdin=DEVNULL,
            stderr=DEVNULL,
            stdout=PIPE,
            env={'LC_ALL': 'C', 'LANG': 'C'}
        )
        pstdout, _ = p.communicate()
    except OSError:  # E.g. command not found
        log.debug(format_exc())
        return None
    return pstdout.decode('utf-8')
开发者ID:carlos-jenkins,项目名称:libfinder,代码行数:17,代码来源:posix.py


示例17: _setup_system

    def _setup_system(self):
        """
        Setup the controller image for testing.

        #. Bring up the ports connecting to the datapaths
        #. Run ryu-manager
        """

        # Ryu should be started by Topology
        if self.metadata.get('autostart', True):

            # Get the app file (or default)
            if self.app_name is not None:
                app_path = '/tmp/' + path.basename(self.app_name)
            else:
                app_path = '/root/ryu-master/ryu/app/simple_switch.py'

            # run ryu app using ryu-manager
            self._supervisord = Popen(shsplit(
                'docker exec {} '
                'sh -c "RYU_COMMAND=\'/root/ryu-master/bin/ryu-manager {} '
                '--verbose\' supervisord"'.format(
                    self.container_id,
                    app_path
                )
            ))

            # Wait for ryu-manager to start
            config_timeout = 100
            i = 0
            while i < config_timeout:
                config_status = self._docker_exec(
                    'supervisorctl status ryu-manager'
                )

                if 'RUNNING' not in config_status:
                    sleep(0.1)
                else:
                    break
                i += 1

            if i == config_timeout:
                raise RuntimeError(
                    'ryu-manager did not reach RUNNING state on supervisor!'
                )
开发者ID:agustin-meneses-fuentes,项目名称:topology_docker,代码行数:45,代码来源:ryu.py


示例18: privileged_cmd

def privileged_cmd(commands_tpl, **kwargs):
    """
    Run a privileged command.

    This function will replace the tokens in the template with the provided
    keyword arguments, then it will split the lines of the template, strip
    them and execute them using the prefix for privileged commands, checking
    that the command returns 0.

    :param str commands_tpl: Single line or multiline template for commands.
    :param dict kwargs: Replacement tokens.
    """
    prefix = cmd_prefix()

    for command in commands_tpl.format(**kwargs).splitlines():
        command = command.strip()
        if command:
            check_call(shsplit(prefix + command))
开发者ID:HPENetworking,项目名称:topology_docker,代码行数:18,代码来源:utils.py


示例19: _docker_exec

    def _docker_exec(self, command):
        """
        Execute a command inside the docker.

        :param str command: The command to execute.
        """
        log.debug(
            '[{}]._docker_exec({}) ::'.format(self.container_id, command)
        )

        response = check_output(shsplit(
            'docker exec {container_id} {command}'.format(
                container_id=self.container_id, command=command.strip()
            )
        )).decode('utf8')

        log.debug(response)
        return response
开发者ID:laurent-albert,项目名称:topology_docker,代码行数:18,代码来源:node.py


示例20: _setup_system

    def _setup_system(self):
        """
        Setup the controller image for testing.

        #. Bring up the ports connecting to the datapaths
        #. Run ryu-manager
        """

        # Check if ryu should be started by Topology
        if not self._autostart:
            return

        # run ryu app using ryu-manager
        self._supervisord = Popen(shsplit(
            'docker exec {} '
            'sh -c "RYU_COMMAND=\'/root/ryu-master/bin/ryu-manager {} '
            '--verbose\' supervisord"'.format(
                self.container_id,
                self.app
            )
        ))

        # Wait for ryu-manager to start
        config_timeout = 100
        i = 0
        while i < config_timeout:
            config_status = self._docker_exec(
                'supervisorctl status ryu-manager'
            )

            if 'RUNNING' not in config_status:
                sleep(0.1)
            else:
                break
            i += 1

        if i == config_timeout:
            raise RuntimeError(
                'ryu-manager did not reach RUNNING state on supervisor!'
            )
开发者ID:HPENetworking,项目名称:topology_docker_ryu,代码行数:40,代码来源:ryu.py



注:本文中的shlex.shsplit函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python shlex.split函数代码示例发布时间:2022-05-27
下一篇:
Python shlex.shlex_split函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap