def load(filename=None): """ Loads a file and imports the settings :param filename: the file to import """ config = confuse.LazyConfig('Yatcobot', __name__) # Add default config when in egg (using this way because egg is breaking the default way) if len(config.sources) == 0: default_config_text = pkg_resources.resource_string("yatcobot.config", "config_default.yaml") default_config = confuse.ConfigSource(yaml.load(default_config_text, Loader=confuse.Loader), 'pkg/config/config_default.yaml', True) config.add(default_config) # Add user specified config if filename is not None and os.path.isfile(filename): config.set_file(filename) logger.info('Loading config files (From highest priority to lowest):') config.resolve() for i, config_source in enumerate(config.sources): logger.info(f'{i}: Path: {config_source.filename}') # Update template from plugins template = Config.get_template() Config._valid = config.get(template)
def __init__(self): self.MSEC = 1 self.SEC = self.MSEC * 1000 self.MIN = 60 * self.SEC self.HOUR = 60 * self.MIN self.DAY = 24 * self.HOUR self.new_records = [] self.stream_pointer = [] self.start_time = [] self.q = [] cwd = os.getcwd() logging.warning('Current Working Directory: {0}'.format(cwd)) try: if 'JOBMANAGER' in os.environ: self.appname = os.environ['JOBMANAGER'] logging.info('Job manager name: ' + self.appname) self.config = confuse.LazyConfig(self.appname) if self.config.keys() == []: logging.warn( 'No keys detected, please ensure that a configmap is configured.' ) self._debug_config() else: raise ValueError('Enviroment variable not set: JOBMANAGER') except ValueError as e: exit(e) filename = self.config['STREAM_LOG_DIR'].get() if os.path.exists(filename): logging.warning('Log File Detected!') # Intialize Redis Time Series Client self.rts, self.q = self._init_rts() self.frequency = self.config['FREQUENCY'].get()
def _setup_cfg(): """set up from configuration file(s) read parameters from ~/.config/bcedd/config.yaml otherwise from /path/to/package/cfg/config_default.yaml """ # set up configuration file try: # Read configuration file config_ = confuse.LazyConfig( 'bcedd', modname=bcedd.__pkg_cfg__) # Get a value from your YAML file # TODO check use of templates, # cf examples in https://github.com/beetbox/confuse/tree/c244db70c6c2e92b001ce02951cf60e1c8793f75 # set up default configuration file path pkg_path = Path(config_._package_path) config_.default_config_path = pkg_path / confuse.DEFAULT_FILENAME return config_ except Exception: logging.exception("Something goes wrong when loading config file.") raise # Throw exception again so calling code knows it happened
def main(): config = confuse.LazyConfig('ldapsync', __name__) parser = argparse.ArgumentParser(description='LDAP synchronization') parser.add_argument('--config', '-c', dest='config_file', help='configuration file') parser.add_argument('--debug', '-d', dest='debug', action='store_true', help='configuration file') parser.add_argument('--create_missing_groups', '-g', dest='create_groups', action='store_true', help='create missing target groups') args = parser.parse_args() if args.config_file: config.set_file(args.config_file) config.set_args(args, dots=True) log_level = logging.DEBUG if args.debug else logging.INFO logging.basicConfig( format='%(asctime)s %(levelname)s %(name)s %(message)s', level=log_level, ) syncer = LDAPSyncer(config) syncer()
def main(): cfg = confuse.LazyConfig('prca', __name__) # Add overrides on top of config.yaml for the workspace. cfg.set_file('./config.workspace.yaml') # Setting up logging. logging.basicConfig( level=logging.INFO, format='%(asctime)s, %(levelname)s, %(name)s, %(message)s', datefmt='%Y-%m-%d %H:%M:%S %z', handlers=[ logging.StreamHandler(), logging.FileHandler(filename=cfg['log_file'].as_filename(), mode='a') ]) logger = logging.getLogger('prca') logger.info('Program started.') error_alert_sound_file = cfg['error_alert_sound_file'].as_filename() prra = PullRequestResourceAccess( cfg['github']['personal_access_tokens'].get(list), cfg['github']['requests_cache_file'].as_filename()) pull_request_comments_csv_file = Path( cfg['bigquery'] ['pull_request_comments_results_csv_file'].as_filename()) try: with CommentResourceAccess( cfg['ghtorrent_mongodb']['ssh_tunnel_host'].get(), cfg['ghtorrent_mongodb']['ssh_tunnel_port'].get(int), cfg['ghtorrent_mongodb']['ssh_username'].get(), cfg['ghtorrent_mongodb']['ssh_private_key'].get(), cfg['ghtorrent_mongodb']['ssh_private_key_password'].get(), cfg['ghtorrent_mongodb']['host'].get(), cfg['ghtorrent_mongodb']['port'].get(int), cfg['ghtorrent_mongodb']['username'].get(), cfg['ghtorrent_mongodb']['password'].get(), cfg['ghtorrent_mongodb']['database'].get(), error_alert_sound_file) as comment_loader: file_processor = BigQueryCsvFileProcessor(comment_loader, prra) file_processor.process(pull_request_comments_csv_file) except Exception: logger.exception(f'Failed to process the BigQuery .csv file.') # Continuously make alert sound until manual interruption. while True: for _ in range(3): playsound(error_alert_sound_file, True) time.sleep(30) logger.info('Program ended.')
def main(): parser = argparse.ArgumentParser( prog=APP_NAME, description='Keep a fork synchronized with its upstream') parser.add_argument('--ssh-key', help='Path to SSH private key with push access') parser.add_argument('--cache-dir', help='Directory to cache repositories in', default='/cache') parser.add_argument('--log-level', help='Desired log level', default='INFO') args = parser.parse_args() config = confuse.LazyConfig(APP_NAME, __name__) config.set_args(args) valid = config.get(CONFIG_TEMPLATE) run(**valid)
def __init__(self, neo4j_host='localhost', neo4j_user='******', neo4j_pass='******', neo4j_port=7687): """Constructor for initial setup :param neo4j_host: Neo4j server hostname, defaults to 'localhost' :type neo4j_host: str, optional :param neo4j_user: Neo4j login username, defaults to 'neo4j' :type neo4j_user: str, optional :param neo4j_pass: Neo4j login password, defaults to 'password' :type neo4j_pass: str, optional :param neo4j_port: Neo4j port to connect to, defaults to 7687 :type neo4j_port: int, optional """ self.temp_dir = self.__create_temp_directory() self.db = None self.config = confuse.LazyConfig('cwf2neo', __name__) self.neo4j_host = os.getenv('NEO4J_HOST', neo4j_host) self.neo4j_user = os.getenv('NEO4J_USER', neo4j_user) self.neo4j_pass = os.getenv('NEO4J_PASS', neo4j_pass) self.neo4j_port = os.getenv('NEO4J_BOLT_PORT', neo4j_port)
import confuse config = confuse.LazyConfig('pySense', __name__) CONFIG_DIR = config.config_dir() USER_CONFIG_PATH = config.user_config_path() template = { 'package': str, 'handlers': { 'date': { 'arrow_format': str, 'default_format': str, 'query_format': str, }, 'datetime': { 'arrow_format': str, 'default_format': str, }, }, 'environment': str, 'logging': { 'name': str, 'level': str, 'propigate': bool, }, 'sense': { 'username': str, 'password': str, 'api': { 'url': str, 'timeout': int, },
def __init__(self): self.config = confuse.LazyConfig("tungsten-prometheus-exporter", __name__)
confuse.Filename()]), "baudrate": int, "encoding": optional(str, "utf-8"), }, "manufacturer_code": confuse.StrSeq(), "secret_key": optional(str), "max_session_age": confuse.OneOf([int, None]), "https": optional(bool, False), "sentry_dsn": optional(str), "sentry_csp_url": optional(str), "log_level": optional(str), } config = confuse.LazyConfig("cherrydoor", __name__) def add_args(parser): """Add arguments to the arparse parser. Parameters ---------- parser : argparse.ArgumentParser parser to add arguments to Returns ------- parser : argparse.ArgumentParser parser with added arguments """ args_template = {
import confuse config = confuse.LazyConfig('Config', __name__) def get_config(): return config
# -*- coding: utf-8 -*- """Top-level package for drfs.""" __author__ = """Data Revenue GmbH""" __email__ = "*****@*****.**" import confuse config = confuse.LazyConfig("drfs", __name__) from ._version import get_versions __version__ = get_versions()["version"] del get_versions from .path import DRPath from .structure import Tree, P
# Load Configuration env_variable_pattern = re.compile('.*?\${(\w+)}.*?') _configfile = None load_dotenv() def replace_env_variables(loader, node): """ Extracts the environment variable from the node's value :param yaml.Loader loader: the yaml loader :param node: the current node in the yaml :return: the parsed string that contains the value of the environment variable """ value = loader.construct_scalar(node) match = env_variable_pattern.findall( value) # to find all env variables in line if match: full_value = value for g in match: full_value = full_value.replace(f'${{{g}}}', os.environ.get(g, g)) return full_value if not full_value.isnumeric() else int(full_value) return value confuse.Loader.add_constructor('!ENV', replace_env_variables) #config = confuse.Configuration('CryptoML-API', __name__) config = confuse.LazyConfig('CryptoML-API', __name__) config.set_file('config.yml')
def main(): cfg = confuse.LazyConfig('ccc4prc', __name__) # Add overrides on top of config.yaml for the workspace. cfg.set_file('./config.workspace.yaml') # Setting up logging. logging.basicConfig( level=logging.INFO, format='%(asctime)s, %(levelname)s, %(name)s, %(message)s', datefmt='%Y-%m-%d %H:%M:%S %z', handlers=[ logging.StreamHandler(), logging.FileHandler(filename=cfg['log_file'].as_filename(), mode='a') ]) logger = logging.getLogger('ccc4prc') logger.info('Program started.') dac_factory = DialogueActClassifierFactory() dac_clf = dac_factory.get_classifier( Path(cfg['dialogue_act_classification'] ['classifier_file'].as_filename()), cfg['dialogue_act_classification']['test_set_percentage'].as_number()) input_result = input('Generate Manual Labelling File? (y/n): ') if is_yes(input_result): csv_file = Path( cfg['bigquery'] ['pull_request_comments_results_csv_file'].as_filename()) classified_csv_file = dac_factory.classify_prc_csv_file(csv_file) manual_labelling_file_generator = FileGenerator() manual_labelling_file_generator.generate(classified_csv_file) input_result = input('Perform Machine Learning? (y/n): ') if is_yes(input_result): ml = MachineLearning(dac_clf.labels()) labeled_seed_excel_file = cfg['machine_learning'][ 'labeled_seed_excel_file'].as_filename() dataset_dir = Path(labeled_seed_excel_file).parent training_dataset_file = dataset_dir / ('training_dataset.csv') test_dataset_file = dataset_dir / ('test_dataset.csv') training_dataset = DataFrame() if training_dataset_file.exists(): training_dataset = read_csv(training_dataset_file) test_dataset = DataFrame() if test_dataset_file.exists(): test_dataset = read_csv(test_dataset_file) if not training_dataset_file.exists() or not test_dataset_file.exists( ): sample_dataset = read_excel(io=labeled_seed_excel_file, sheet_name='Sample Dataset') training_dataset, test_dataset = ml.train_test_split( sample_dataset) addl_test_dataset = read_excel( io=labeled_seed_excel_file, sheet_name='Additional Test Dataset') test_dataset = concat([test_dataset, addl_test_dataset], ignore_index=True) training_dataset.to_csv(training_dataset_file, header=True, index=False, mode='w') test_dataset.to_csv(test_dataset_file, header=True, index=False, mode='w') unlabeled_dataset = read_csv( cfg['machine_learning']['unlabeled_csv_file'].as_filename()) ml.active_learn(training_dataset, training_dataset_file, test_dataset, unlabeled_dataset) logger.info('Program ended.')
import confuse # Singleton config for the app cc_config = confuse.LazyConfig('cross-check', __name__) filename: str = '' log_name: str = 'default'
import confuse config = confuse.LazyConfig("dashcoch", __name__)
from pathlib import Path import confuse from ncrt.utils import wsl from ncrt.utils.platform import Platform _template = { 'sessions_path': confuse.String(default=( Platform.get() == Platform.POSIX and f"{Path.home()}/.vandyke/SecureCRT/Config/Sessions" or Platform.get() == Platform.WSL and f"{wsl.win_env('APPDATA', wsl_path=True)}\\VanDyke\\Config\\Sessions" or Platform.get() == Platform.WIN and f"{os.environ['APPDATA']}\\VanDyke\\Config\\Sessions" or confuse.REQUIRED )) } _config = confuse.LazyConfig('ncrt', __name__) def config(template=None): if template is None: template = _template return _config.get(template) def ensure_valid(template=None): try: config(template) except confuse.ConfigError as err: print("Configuration is not valid:", file=sys.stderr) print("=>", str(err), file=sys.stderr)
from pkg_resources import iter_entry_points import click import click_log import confuse import sys import os import logging from click_plugins import with_plugins # Importing commands from submodules import dvcli.user.cli as user_group # Global variables configuration = confuse.LazyConfig('dvcli', __name__) logger = logging.getLogger(__name__) # Logging config click_log.basic_config(logger) verbosity = { 0: logging.ERROR, 1: logging.WARN, 2: logging.INFO, 3: logging.DEBUG } @with_plugins(iter_entry_points('dvcli.plugins')) @click.group() @click.option('--config', '-c',
if 'MKL_NUM_THREADS' not in os.environ: os.environ.update(MKL_NUM_THREADS='1') # This is an attempt to monkey-patch the confuse.NotFoundError because the # name of that exception is... confusing. If the class name is updated at # some point in the future, it would be best to remove this patch. class ConfigValueNotFound(Exception): pass confuse.NotFoundError = ConfigValueNotFound # Load settings and configure logging settings = confuse.LazyConfig('jetstream', __name__) log = logging.getLogger(__name__) log.addHandler(logging.NullHandler()) # Package module imports from jetstream import backends, pipelines, runner, templates, utils, workflows from jetstream.projects import Project, init, is_project from jetstream.runner import Runner from jetstream.templates import environment, render_template from jetstream.workflows import Workflow, Task, load_workflow, save_workflow, \ random_workflow from jetstream.pipelines import Pipeline, InvalidPipeline, find_pipelines, \ list_pipelines, get_pipeline def lookup_backend(name=None):
from __future__ import division, absolute_import, print_function import confuse from os import path config = confuse.LazyConfig('irancell', __name__) config['irancell']['auth']['session']['path'] = path.join( config['irancell']['auth']['session']['base_path'].get(), config['irancell']['auth']['session']['file_name'].get())
def path(self, value: pathlib.Path): self.__path = pathlib.Path(value) self.__view = confuse.LazyConfig("") self.load()
import confuse from typing import List from pathlib import Path config = confuse.LazyConfig("untweeter", __name__) print("Loading configuration from", config.config_dir()) def dump(config: confuse.LazyConfig) -> None: fname = Path(config.config_dir()) / "config.yaml" yaml = config.dump() with fname.open("w") as f: f.write(yaml) def get_keys() -> List[str]: keys = [] for key in [ "consumer_key", "consumer_secret", "access_token_key", "access_token_secret", ]: keys.append(config["KEYS"][key].get(str)) return keys def get_limits() -> List[int]: limits = [] for key in ["tweets", "faves"]:
"skip_all_pick_movements": bool, "wait_at_place_egress": int, "robot_movement": { "global_speed_accel": { "speed_override": float, "speed_max_tcp": float, "accel": float, "accel_ramp": float, }, "speed": { "pick": float, "travel": float, "place": float, }, "zone": { "pick": ZoneDataTemplate(), "place": ZoneDataTemplate(), "place_egress": ZoneDataTemplate(), "travel": ZoneDataTemplate(), }, "joint_positions": { "start": confuse.Sequence([float] * 6), "end": confuse.Sequence([float] * 6), "travel_trajectory": confuse.TypeTemplate(list, default=None), }, }, }, } fab_conf = confuse.LazyConfig("rapid_clay_formations_fab", modname=__name__)
import os import confuse CONFIG_DEFAULT_FILENAME = os.path.join(os.path.dirname(__file__), "config_default.yaml") pyhrv_conf = confuse.LazyConfig("pyhrv", __name__) def _get(key: str): view = pyhrv_conf for subkey in key.split("."): view = view[subkey] return view.get() def get_val(key: str): """ Returns the value of a configuration parameter. :param key: The full name of the parameter, e.g. foo.bar.baz :return: The value of that parameter. """ return _get(key + ".value") def get_desc(key: str): """ Returns the description of a configuration parameter. :param key: The full name of the parameter, e.g. 'foo.bar.baz' :return: The description of that parameter. """
import os import confuse config = confuse.LazyConfig('ytbdl', None) def get_loaded_config_sources(): ''' Get existing configuration files Returns: (list): A list of (string) paths to configuration files that exist on the file system. Returns an empty list if no configuration files exist ''' config.resolve() return [s.filename for s in config.sources if os.path.exists(s.filename)] def get_main_config_path(): ''' Get the main configuration file path Returns: (str): A path to the configuration file. This path may or may not exist ''' return os.path.join(config.config_dir(), 'config.yaml') def config_exists(): ''' Determine if one or more configuration files exist.
import logging import confuse import os from time import sleep appname = 'testapp' config = confuse.LazyConfig(appname) logging.basicConfig(format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p') logging.info('App started') directory = config.config_dir() con_file_dir = config.user_config_path() logging.warn('Config file Directory: {0} | User Config File:{1}'.format( directory, con_file_dir)) logging.warn('Discoverd Keys {0}'.format(config.keys())) while (True): config.clear() config.read() logging.warn('{0}: {1}'.format(config.keys()[0], config[config.keys()[0]])) sleep(1)
from pushbullet import Pushbullet import confuse import requests import urllib3.contrib.pyopenssl urllib3.contrib.pyopenssl.inject_into_urllib3() template = { 'balance_limit': float, 'credentials': { 'pushbullet': str, 'tarsnap_address': str, 'tarsnap_password': str, } } config = confuse.LazyConfig('TarsnapMonitor', __name__) parser = argparse.ArgumentParser(description='Tarsnap monitor') parser.add_argument('--address', '-addr', dest='tarsnap_address', metavar='TARSNAP_ADDRESS', help='tarsnap username address') parser.add_argument('--password', '-pass', dest='tarsnap_password', metavar='TARSNAP_PASSWORD', help='tarsnap password') parser.add_argument('--pushbullet', '-push', dest='pushbullet', metavar='PUSHBULLET',
"serial_port": confuse.String(default=None), "serial_baudrate": int, "max_z_adjustment": float, "adjust_loc_frames": bool, }, }, "robot_movement": { "global_speed_accel": { "speed_override": float, "speed_max_tcp": float, "accel": float, "accel_ramp": float, }, "speed": { "precise": float, "travel": float }, "zone": { "precise": ZoneDataTemplate(), "travel": ZoneDataTemplate() }, "set_joint_pos": { "start": confuse.Sequence([float] * 6), "end": confuse.Sequence([float] * 6), }, }, }, } fab_conf = confuse.LazyConfig("compas_rcf", modname=__name__)
template = { 'library': confuse.Filename(), 'import_write': confuse.OneOf([bool, 'ask', 'skip']), 'ignore': confuse.StrSeq(), 'plugins': list, 'paths': { 'directory': confuse.Filename(), 'default': confuse.Filename(relative_to='directory'), }, 'servers': confuse.Sequence({ 'hostname': str, 'options': confuse.StrSeq(), }) } config = confuse.LazyConfig('ConfuseExample', __name__) def main(): parser = argparse.ArgumentParser(description='example Confuse program') parser.add_argument('--library', '-l', dest='library', metavar='LIBPATH', help='library database file') parser.add_argument('--directory', '-d', dest='paths.directory', metavar='DIRECTORY', help='destination music directory') parser.add_argument('--verbose',
help="increase output verbosity", action="store_true") parser.add_argument("-d", "--dryrun", help="run without writing to the database", action="store_true") args = parser.parse_args() if args.verbose: logging.basicConfig(format='%(levelname)s:%(asctime)s %(message)s', level=logging.DEBUG) else: logging.basicConfig(format='%(levelname)s:%(asctime)s %(message)s', level=logging.INFO) config = confuse.LazyConfig('soursensor') # Sourdough starter initial conditions for measuring rise h0 = config['starter']['height_t0'].get(float) d0 = 0. d0_init = False logging.info('Starter initial height: ' + str(h0) + ' mm') db = DB(config['databases']['influxdb']) sensors = [] sensors.append(BME680()) sensors.append(VL53L1XS(config['sensors']['VL53L1X'])) def exit_handler(signal, frame):