diff options
| author | Scott Gasch <[email protected]> | 2022-08-30 15:36:23 -0700 |
|---|---|---|
| committer | Scott Gasch <[email protected]> | 2022-08-30 15:36:23 -0700 |
| commit | 4d69e7bee5985ff744ef543f9c9f20bb37f4fd6d (patch) | |
| tree | 4f4670330005625ee63dbbc329822f4704b32930 /config.py | |
| parent | 119692e4487278e5d19c06cfe7dc062c2bd7efc5 (diff) | |
Changes towards splitting up the library and (maybe?) publishing on PyPi.
Diffstat (limited to 'config.py')
| -rw-r--r-- | config.py | 51 |
1 files changed, 46 insertions, 5 deletions
@@ -90,8 +90,6 @@ import re import sys from typing import Any, Dict, List, Optional, Tuple -import scott_secrets - # This module is commonly used by others in here and should avoid # taking any unnecessary dependencies back on them. @@ -330,6 +328,46 @@ class Config: env = env[1:] return var, env, chunks + @staticmethod + def _to_bool(in_str: str) -> bool: + """ + Args: + in_str: the string to convert to boolean + + Returns: + A boolean equivalent of the original string based on its contents. + All conversion is case insensitive. A positive boolean (True) is + returned if the string value is any of the following: + + * "true" + * "t" + * "1" + * "yes" + * "y" + * "on" + + Otherwise False is returned. + + >>> to_bool('True') + True + + >>> to_bool('1') + True + + >>> to_bool('yes') + True + + >>> to_bool('no') + False + + >>> to_bool('huh?') + False + + >>> to_bool('on') + True + """ + return in_str.lower() in ("true", "1", "yes", "y", "t", "on") + def _augment_sys_argv_from_environment_variables(self): """Internal. Look at the system environment for variables that match commandline arg names. This is done via some munging such that: @@ -366,9 +404,7 @@ class Config: self.saved_messages.append( f'Initialized from environment: {var} = {value}' ) - from string_utils import to_bool - - if len(chunks) == 1 and to_bool(value): + if len(chunks) == 1 and Config._to_bool(value): sys.argv.append(var) elif len(chunks) > 1: sys.argv.append(var) @@ -421,8 +457,11 @@ class Config: if loadfile[:3] == 'zk:': from kazoo.client import KazooClient + import scott_secrets + try: if self.zk is None: + self.zk = KazooClient( hosts=scott_secrets.ZOOKEEPER_NODES, use_ssl=True, @@ -545,6 +584,8 @@ class Config: if not self.zk: from kazoo.client import KazooClient + import scott_secrets + self.zk = KazooClient( hosts=scott_secrets.ZOOKEEPER_NODES, use_ssl=True, |
