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


Python shlex.split方法代码示例

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


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

示例1: _get_terminal_size_tput

# 需要导入模块: import shlex [as 别名]
# 或者: from shlex import split [as 别名]
def _get_terminal_size_tput(self):
        # get terminal width
        # src: http://stackoverflow.com/questions/263890/how-do-i-find-the-width-height-of-a-terminal-window
        try:
            cols = int(
                subprocess.check_output(
                    shlex.split("tput cols"), stderr=subprocess.STDOUT
                )
            )
            rows = int(
                subprocess.check_output(
                    shlex.split("tput lines"), stderr=subprocess.STDOUT
                )
            )

            return (cols, rows)
        except:
            pass 
开发者ID:sdispater,项目名称:clikit,代码行数:20,代码来源:terminal.py

示例2: find_executable

# 需要导入模块: import shlex [as 别名]
# 或者: from shlex import split [as 别名]
def find_executable(name) -> str:
    is_windows = os.name == 'nt'
    windows_exts = os.environ['PATHEXT'].split(ENV_PATH_SEP) if is_windows else None
    path_dirs = os.environ['PATH'].split(ENV_PATH_SEP)

    search_dirs = path_dirs + [os.getcwd()] # cwd is last in the list

    for dir in search_dirs:
        path = os.path.join(dir, name)

        if is_windows:
            for extension in windows_exts:
                path_with_ext = path + extension

                if os.path.isfile(path_with_ext) and os.access(path_with_ext, os.X_OK):
                    return path_with_ext
        else:
            if os.path.isfile(path) and os.access(path, os.X_OK):
                return path

    return '' 
开发者ID:godotengine,项目名称:godot-mono-builds,代码行数:23,代码来源:os_utils.py

示例3: get_one_hot_C

# 需要导入模块: import shlex [as 别名]
# 或者: from shlex import split [as 别名]
def get_one_hot_C(sequence, region_dict  ):
    #also replace non excisting nucleos with 0
    repl='TGAN'
    seq_Cmeth_new=""
    seq_C_new=""

    for nucl in repl:
        sequence=sequence.replace(nucl, '0')
    # split the Cs in C meth and C unmeth
    for dict_key in sorted(region_dict):
        meth_true=region_dict[dict_key][2]
        start_meth=int(region_dict[dict_key][0])
        end_meth=int(region_dict[dict_key][1])
        if meth_true==1:
            seqsnip_Cmeth=sequence[start_meth:end_meth+1].replace("C", '1')
            seqsnip_C=sequence[start_meth:end_meth+1].replace("C", '0')
        else:
            seqsnip_Cmeth=sequence[start_meth:end_meth+1].replace("C", '0')
            seqsnip_C=sequence[start_meth:end_meth+1].replace("C", '1')
        seq_C_new=seq_C_new + seqsnip_C
        seq_Cmeth_new=seq_Cmeth_new+seqsnip_Cmeth

    return seq_C_new, seq_Cmeth_new 
开发者ID:kipoi,项目名称:models,代码行数:25,代码来源:dataloader.py

示例4: parse_messages_kafka

# 需要导入模块: import shlex [as 别名]
# 或者: from shlex import split [as 别名]
def parse_messages_kafka(consumer):
    logger.info('Reading messages')
    for message in consumer:
        try:
            logger.debug('Message received')
            logger.debug(message.value)
            if 'JSON' in agent_config_vars['data_format']:
                parse_json_message(json.loads(str(message.value)))
            elif 'CSV' in agent_config_vars['data_format']:
                parse_json_message(label_message(message.value.split(',')))
            else:
                parse_raw_message(message.value)
        except Exception as e:
            logger.warn('Error when parsing message')
            logger.warn(e)
            continue 
开发者ID:insightfinder,项目名称:InsightAgent,代码行数:18,代码来源:getmessages_kafka2.py

示例5: parse_json_message

# 需要导入模块: import shlex [as 别名]
# 或者: from shlex import split [as 别名]
def parse_json_message(messages):
    if len(agent_config_vars['json_top_level']) != 0:
        if agent_config_vars['json_top_level'] == '[]' and isinstance(messages, (list, set, tuple)):
            for message in messages:
                parse_json_message_single(message)
        else:
            top_level = _get_json_field_helper(
                messages,
                agent_config_vars['json_top_level'].split(JSON_LEVEL_DELIM),
                allow_list=True)
            if isinstance(top_level, (list, set, tuple)):
                for message in top_level:
                    parse_json_message_single(message)
            else:
                parse_json_message_single(top_level)
    elif isinstance(messages, (list, set, tuple)):
        for message_single in messages:
            parse_json_message_single(message_single)
    else:
        parse_json_message_single(messages) 
开发者ID:insightfinder,项目名称:InsightAgent,代码行数:22,代码来源:getmessages_kafka2.py

示例6: update_state

# 需要导入模块: import shlex [as 别名]
# 或者: from shlex import split [as 别名]
def update_state(setting, value, append=False, write=False):
    # update in-mem
    if append:
        current = ','.join(agent_config_vars['state'][setting])
        value = '{},{}'.format(current, value) if current else value
        agent_config_vars['state'][setting] = value.split(',')
    else:
        agent_config_vars['state'][setting] = value
    logger.debug('setting {} to {}'.format(setting, value))
    # update config file
    if write and not cli_config_vars['testing']:
        config_ini = config_ini_path()
        if os.path.exists(config_ini):
            config_parser = ConfigParser.SafeConfigParser()
            config_parser.read(config_ini)
            config_parser.set('state', setting, str(value))
            with open(config_ini, 'w') as config_file:
                config_parser.write(config_file)
    # return new value (if append)
    return value 
开发者ID:insightfinder,项目名称:InsightAgent,代码行数:22,代码来源:getlogs_servicenow.py

示例7: parse_json_message

# 需要导入模块: import shlex [as 别名]
# 或者: from shlex import split [as 别名]
def parse_json_message(messages):
    if isinstance(messages, (list, set, tuple)):
        for message in messages:
            parse_json_message(message)
    else:
        if len(agent_config_vars['json_top_level']) == 0:
            parse_json_message_single(messages)
        else:
            top_level = _get_json_field_helper(
                    messages,
                    agent_config_vars['json_top_level'].split(JSON_LEVEL_DELIM),
                    allow_list=True)
            if isinstance(top_level, (list, set, tuple)):
                for message in top_level:
                    parse_json_message_single(message)
            else:
                parse_json_message_single(top_level) 
开发者ID:insightfinder,项目名称:InsightAgent,代码行数:19,代码来源:getlogs_servicenow.py

示例8: update_state

# 需要导入模块: import shlex [as 别名]
# 或者: from shlex import split [as 别名]
def update_state(setting, value, append=False):
    # update in-mem
    if append:
        current = ','.join(agent_config_vars['state'][setting])
        value = '{},{}'.format(current, value) if current else value
        agent_config_vars['state'][setting] = value.split(',')
    else:
        agent_config_vars['state'][setting] = value
    logger.debug('setting {} to {}'.format(setting, value))
    # update config file
    if 'TAIL' in agent_config_vars['data_format']:
        config_ini = config_ini_path()
        if os.path.exists(config_ini):
            config_parser = ConfigParser.SafeConfigParser()
            config_parser.read(config_ini)
            config_parser.set('state', setting, str(value))
            with open(config_ini, 'w') as config_file:
                config_parser.write(config_file)
    # return new value (if append)
    return value 
开发者ID:insightfinder,项目名称:InsightAgent,代码行数:22,代码来源:getmessages_file_replay.py

示例9: parse_json_message

# 需要导入模块: import shlex [as 别名]
# 或者: from shlex import split [as 别名]
def parse_json_message(messages):
    if len(agent_config_vars['json_top_level']) != 0:
        if agent_config_vars['json_top_level'] == '[]' and isinstance(messages, (list, set, tuple)):
            for message in messages:
                parse_json_message_single(message)
        else:
            top_level = _get_json_field_helper(
                    messages,
                    agent_config_vars['json_top_level'].split(JSON_LEVEL_DELIM),
                    allow_list=True)
            if isinstance(top_level, (list, set, tuple)):
                for message in top_level:
                    parse_json_message_single(message)
            else:
                parse_json_message_single(top_level)
    elif isinstance(messages, (list, set, tuple)):
        for message_single in messages:
            parse_json_message_single(message_single)
    else:
        parse_json_message_single(messages) 
开发者ID:insightfinder,项目名称:InsightAgent,代码行数:22,代码来源:getmessages_file_replay.py

示例10: parse_json_message

# 需要导入模块: import shlex [as 别名]
# 或者: from shlex import split [as 别名]
def parse_json_message(messages):
    if len(agent_config_vars['json_top_level']) != 0:
        if agent_config_vars['json_top_level'] == '[]' and isinstance(messages, (list, set, tuple)):
            for message in messages:
                parse_json_message_single(message)
        else:
            top_level = _get_json_field_helper(
                    messages,
                    agent_config_vars['json_top_level'].split(JSON_LEVEL_DELIM),
                    allow_list=True)
            if isinstance(top_level, (list, set, tuple)):
                for message in top_level:
                    parse_json_message_single(message)
            else:
                parse_json_message_single(top_level)
    else:
        parse_json_message_single(messages) 
开发者ID:insightfinder,项目名称:InsightAgent,代码行数:19,代码来源:getlogs_tcpdump.py

示例11: sendFile

# 需要导入模块: import shlex [as 别名]
# 或者: from shlex import split [as 别名]
def sendFile(clientSocket, parameters):
    request = clientSocket.recv(1024)
    logger.debug("Request: " + str(request))
    requestParts = shlex.split(request)
    if len(requestParts) >= 4:
        if requestParts[0] == 'CUSTOM':
            action = " ".join(requestParts[1:-3])
            userName = requestParts[len(requestParts) - 3]
            licenseKey = requestParts[len(requestParts) - 2]
            projectName = requestParts[len(requestParts) - 1]
        else:
            action = requestParts[0]
            userName = requestParts[1]
            licenseKey = requestParts[2]
            projectName = requestParts[3]
            if str(action).lower() == "cleandisk":
                action = "clean_disk.sh"
        command = os.path.join(parameters['homepath'], "script_runner", action)
        if verifyUser(userName, licenseKey, projectName):
            runCommand(command, clientSocket)
        else:
            clientSocket.send("Status: 500")
    else:
        clientSocket.send("Status: 500")
    clientSocket.close() 
开发者ID:insightfinder,项目名称:InsightAgent,代码行数:27,代码来源:script_runner.py

示例12: source

# 需要导入模块: import shlex [as 别名]
# 或者: from shlex import split [as 别名]
def source(script: str, cwd=None) -> dict:
    popen_args = {}
    if cwd is not None:
        popen_args['cwd'] = cwd

    import subprocess
    cmd = 'bash -c \'source %s; bash %s\'' % (script, print_env_sh_path)
    proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True, **popen_args)
    output = proc.communicate()[0]
    return dict(line.split('=', 1) for line in output.decode().split('\x00') if line)


# Creates the directory if no other file or directory with the same path exists 
开发者ID:godotengine,项目名称:godot-mono-builds,代码行数:15,代码来源:os_utils.py

示例13: get_clang_resource_dir

# 需要导入模块: import shlex [as 别名]
# 或者: from shlex import split [as 别名]
def get_clang_resource_dir(clang_command):
    import shlex
    from subprocess import check_output
    return check_output(shlex.split(clang_command) + ['-print-resource-dir']).strip().decode('utf-8') 
开发者ID:godotengine,项目名称:godot-mono-builds,代码行数:6,代码来源:os_utils.py

示例14: get_stdout

# 需要导入模块: import shlex [as 别名]
# 或者: from shlex import split [as 别名]
def get_stdout(command):
    log.debug('Running command: %s' % command)
    result = subprocess.check_output(shlex.split(command))
    return result.decode('utf8') 
开发者ID:pkkid,项目名称:pkmeter,代码行数:6,代码来源:utils.py

示例15: namespace

# 需要导入模块: import shlex [as 别名]
# 或者: from shlex import split [as 别名]
def namespace(module):
    if isinstance(module, str):
        return module
    return os.path.basename(module.__file__).split('.')[0] 
开发者ID:pkkid,项目名称:pkmeter,代码行数:6,代码来源:utils.py


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