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


Python util.strtobool方法代码示例

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


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

示例1: __add_checks__

# 需要导入模块: from distutils import util [as 别名]
# 或者: from distutils.util import strtobool [as 别名]
def __add_checks__(self, appconfig, result):
        checks = []
        unwanted = []
        for checker in appconfig.sections():
            if "checker" in checker.lower() or "collector" in checker.lower():
                try: 
                    enabled=not strtobool(appconfig.get(checker, 'disabled'))
                except NoOptionError:
                    enabled=True
                try: 
                    enabled=strtobool(appconfig.get(checker, 'enabled'))
                except NoOptionError:
                    enabled=True
                if enabled:
                    checks.append(checker)
                else:
                    unwanted.append(checker)
        result['checks'] = checks
        result['unwanted'] = unwanted 
开发者ID:koenbuyens,项目名称:securityheaders,代码行数:21,代码来源:optionparser.py

示例2: bypass_loggregator

# 需要导入模块: from distutils import util [as 别名]
# 或者: from distutils.util import strtobool [as 别名]
def bypass_loggregator():
    env_var = os.getenv("BYPASS_LOGGREGATOR", "False")
    # Throws a useful message if you put in a nonsensical value.
    # Necessary since we store these in cloud portal as strings.
    try:
        bypass = strtobool(env_var)
    except ValueError as _:
        logging.warning(
            "Bypass loggregator has a nonsensical value: %s. "
            "Falling back to old loggregator-based metric reporting.",
            env_var,
        )
        return False

    if bypass:
        if os.getenv("TRENDS_STORAGE_URL"):
            return True
        else:
            logging.warning(
                "BYPASS_LOGGREGATOR is set to true, but no metrics URL is "
                "set. Falling back to old loggregator-based metric reporting."
            )
            return False
    return False 
开发者ID:mendix,项目名称:cf-mendix-buildpack,代码行数:26,代码来源:util.py

示例3: __init__

# 需要导入模块: from distutils import util [as 别名]
# 或者: from distutils.util import strtobool [as 别名]
def __init__(self, options,inp_dim):
        super(RNN_cudnn, self).__init__()
        
        self.input_dim=inp_dim
        self.hidden_size=int(options['hidden_size'])
        self.num_layers=int(options['num_layers'])
        self.nonlinearity=options['nonlinearity']
        self.bias=bool(strtobool(options['bias']))
        self.batch_first=bool(strtobool(options['batch_first']))
        self.dropout=float(options['dropout'])
        self.bidirectional=bool(strtobool(options['bidirectional']))
        
        self.rnn = nn.ModuleList([nn.RNN(self.input_dim, self.hidden_size, self.num_layers, 
                            nonlinearity=self.nonlinearity,bias=self.bias,dropout=self.dropout,bidirectional=self.bidirectional)])
         
        self.out_dim=self.hidden_size+self.bidirectional*self.hidden_size 
开发者ID:santi-pdp,项目名称:pase,代码行数:18,代码来源:neural_networks.py

示例4: search_factory_literature

# 需要导入模块: from distutils import util [as 别名]
# 或者: from distutils.util import strtobool [as 别名]
def search_factory_literature(self, search):
    """Search factory for literature (series and documents)."""
    def filter_periodical_issues(search, query_string=None):
        """Filter periodical issues unless include_all is specified."""
        from distutils.util import strtobool
        from flask import request

        include_all = request.values.get("include_all", "no")
        if include_all == "":
            include_all = "yes"

        if not strtobool(include_all):
            issue_query_string = "NOT document_type:PERIODICAL_ISSUE"
            if query_string:
                query_string = "{} AND {}".format(
                    query_string,
                    issue_query_string
                )
            else:
                query_string = issue_query_string
        return search, query_string

    return _ils_search_factory(self, search, filter_periodical_issues) 
开发者ID:inveniosoftware,项目名称:invenio-app-ils,代码行数:25,代码来源:search.py

示例5: handle

# 需要导入模块: from distutils import util [as 别名]
# 或者: from distutils.util import strtobool [as 别名]
def handle(self):
        from poetry.utils.shell import Shell

        # Check if it's already activated or doesn't exist and won't be created
        venv_activated = strtobool(environ.get("POETRY_ACTIVE", "0")) or getattr(
            sys, "real_prefix", sys.prefix
        ) == str(self.env.path)
        if venv_activated:
            self.line(
                "Virtual environment already activated: "
                "<info>{}</>".format(self.env.path)
            )

            return

        self.line("Spawning shell within <info>{}</>".format(self.env.path))

        # Setting this to avoid spawning unnecessary nested shells
        environ["POETRY_ACTIVE"] = "1"
        shell = Shell.get()
        shell.activate(self.env)
        environ.pop("POETRY_ACTIVE") 
开发者ID:python-poetry,项目名称:poetry,代码行数:24,代码来源:shell.py

示例6: user_prompt

# 需要导入模块: from distutils import util [as 别名]
# 或者: from distutils.util import strtobool [as 别名]
def user_prompt(question):
    """ Prompt the yes/no-*question* to the user. """
    from distutils.util import strtobool

    while True:
        try:
            if IS_PY3:
                user_input = input(question + " [y/n]: ").lower()
            else:
                user_input = raw_input(question + " [y/n]: ").lower()
            result = strtobool(user_input)
            return result
        except ValueError:
            print("Please use y/n or yes/no.\n")
        except KeyboardInterrupt:
            print("Ctrl-c keyboard interrupt, shutting down...")
            sys.exit(0) 
开发者ID:shirosaidev,项目名称:diskover,代码行数:19,代码来源:diskover.py

示例7: toggle_enforce_admin

# 需要导入模块: from distutils import util [as 别名]
# 或者: from distutils.util import strtobool [as 别名]
def toggle_enforce_admin(options):
    access_token, owner, repo_name, branch_name, retries, github_repository = options.access_token, options.owner, options.repo, options.branch, int(options.retries), options.github_repository
    if not owner and not repo_name and github_repository and "/" in github_repository:
        owner = github_repository.split("/")[0]
        repo_name = github_repository.split("/")[1]

    if owner == '' or repo_name == '':
        print('Owner and repo or GITHUB_REPOSITORY not set')
        raise RuntimeError
    enforce_admins = bool(strtobool(options.enforce_admins)) if options.enforce_admins is not None and not options.enforce_admins == '' else None
    # or using an access token
    print(f"Getting branch protection settings for {owner}/{repo_name}")
    protection = get_protection(access_token, branch_name, owner, repo_name)
    print(f"Enforce admins branch protection enabled? {protection.enforce_admins.enabled}")
    print(f"Setting enforce admins branch protection to {enforce_admins if enforce_admins is not None else not protection.enforce_admins.enabled}")
    for i in range(retries):
        try:
            if enforce_admins is False:
                disable(protection)
                return
            elif enforce_admins is True:
                enable(protection)
                return
            elif protection.enforce_admins.enabled:
                disable(protection)
                return
            elif not protection.enforce_admins.enabled:
                enable(protection)
                return
        except GitHubException:
            print(f"Failed to set enforce admins to {not protection.enforce_admins.enabled}. Retrying...")
            sleep(i ** 2)  # Exponential back-off

    print(f"Failed to set enforce admins to {not protection.enforce_admins.enabled}.")
    exit(1) 
开发者ID:benjefferies,项目名称:branch-protection-bot,代码行数:37,代码来源:run.py

示例8: __init__

# 需要导入模块: from distutils import util [as 别名]
# 或者: from distutils.util import strtobool [as 别名]
def __init__(self, pywren_config, internal_storage):
        self.config = pywren_config
        self.rabbitmq_monitor = self.config['pywren'].get('rabbitmq_monitor', False)
        self.store_status = strtobool(os.environ.get('__PW_STORE_STATUS', 'True'))
        self.internal_storage = internal_storage
        self.response = {'exception': False} 
开发者ID:pywren,项目名称:pywren-ibm-cloud,代码行数:8,代码来源:handler.py

示例9: _confirm

# 需要导入模块: from distutils import util [as 别名]
# 或者: from distutils.util import strtobool [as 别名]
def _confirm(prompt):
    while True:
        try:
            answer = strtobool(input(prompt))
        except ValueError:
            continue
        except EOFError:
            sys.exit(1)
        else:
            break
    return answer 
开发者ID:cloudblue,项目名称:apsconnect-cli,代码行数:13,代码来源:apsconnect.py

示例10: user_input_query

# 需要导入模块: from distutils import util [as 别名]
# 或者: from distutils.util import strtobool [as 别名]
def user_input_query(question):
    sys.stdout.write('%s [y/n]\n' % question)
    while True:
        try:
            return strtobool(raw_input().lower())
        except ValueError:
            sys.stdout.write('Please respond with \'y\' or \'n\'.\n') 
开发者ID:HaifeiLi,项目名称:HardenFlash,代码行数:9,代码来源:HardenFlash-deploy.py

示例11: launch_test_slogging_main

# 需要导入模块: from distutils import util [as 别名]
# 或者: from distutils.util import strtobool [as 别名]
def launch_test_slogging_main(self, level: str, structured: bool, config_path: str
                                  ) -> Tuple[str, bool, str]:
        args = [sys.executable, __file__]
        if config_path:
            args.extend(["--log-config", config_path])
        if structured:
            args.append("--log-structured")
        if level:
            args.extend(["--log-level", level])
        patched_env = os.environ.copy()
        patched_env[ARGPARSE_TEST] = "1"
        result = subprocess.check_output(args, env=patched_env).decode().splitlines()
        result[1] = strtobool(result[1])
        return tuple(result) 
开发者ID:src-d,项目名称:modelforge,代码行数:16,代码来源:test_logs.py

示例12: validate

# 需要导入模块: from distutils import util [as 别名]
# 或者: from distutils.util import strtobool [as 别名]
def validate(self, value, row_number=None, source="", node=None, nodeid=None):
        errors = []
        try:
            if value is not None:
                type(bool(util.strtobool(str(value)))) is True
        except Exception:
            errors.append({"type": "ERROR", "message": "{0} is not of type boolean. This data was not imported.".format(value)})

        return errors 
开发者ID:archesproject,项目名称:arches,代码行数:11,代码来源:datatypes.py

示例13: transform_value_for_tile

# 需要导入模块: from distutils import util [as 别名]
# 或者: from distutils.util import strtobool [as 别名]
def transform_value_for_tile(self, value, **kwargs):
        return bool(util.strtobool(str(value))) 
开发者ID:archesproject,项目名称:arches,代码行数:4,代码来源:datatypes.py

示例14: str2bool

# 需要导入模块: from distutils import util [as 别名]
# 或者: from distutils.util import strtobool [as 别名]
def str2bool(s):
    if is_string(s):
        return strtobool(s)
    return bool(s) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:6,代码来源:__init__.py

示例15: to_option

# 需要导入模块: from distutils import util [as 别名]
# 或者: from distutils.util import strtobool [as 别名]
def to_option(self, value):
        return strtobool(value) 
开发者ID:iris-edu,项目名称:pyweed,代码行数:4,代码来源:options.py


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