当前位置: 首页>>代码示例>>Python>>正文


Python shlex.shsplit函数代码示例

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


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


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