當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。