def test_init_no_user_configs_but_merge_specified(self): kwargs = {"operator_merge_default": "eh"} with(self.assertRaises(Exception)): cl = ConfigLoader(**kwargs) kwargs = {"token_merge_default": "eh"} with(self.assertRaises(Exception)): cl = ConfigLoader(**kwargs) kwargs = {"parselet_merge_default": "eh"} with(self.assertRaises(Exception)): cl = ConfigLoader(**kwargs)
def load(self, apply_ignored=True): """ Load configurations from configuration repository at the given path. :param bool apply_ignored: whether 'ignored' settings should be taken into account """ self.config_loader = ConfigLoader(self.args.config, self.settings, apply_ignored) self.entities = self.config_loader.load() if self.okta_users: if self.args.action == 'check': self.lg.info('Okta user loading not supported in test') self.entities['user'] = {} self.okta_groups = [] return # only groups defined both in IPA & Okta are taken for Okta users ipa_groups = self.entities.get('group', []).keys() self.okta_loader = OktaLoader(self.settings, ipa_groups) if self.entities.get('user'): self.lg.warning( '%d users parsed from Git but will be overwritten by Okta', len(self.entities['user'])) self.entities['user'] = self.okta_loader.load() # parse Okta groups to use for constructing diff self.okta_groups = self.okta_loader.load_groups()
def setup( self, filepath: str, make_outputs: bool = True ): """ Load a configuration file and create output directories. Parameters ---------- filepath : str Path to the configuration file. make_outputs: bool If true, create output directories, but only when output_dir_key exists. Returns ------- config : Configuration """ config_loader = ConfigLoader() self.cfg = config_loader.load(filepath) self._validate_dic_keys() if self.cfg["EXPERIMENT"]["USER"] != getpass.getuser(): raise WrongUserKeyError("USER value in config file does not match current user ") if make_outputs: self._create_output_dirs() return self.cfg
def main(): config = ConfigLoader('config.ini') feed_fetcher = FeedFetcher(config) # initial poll to get most recent alert id print("Initial fetch to set references...") feed_fetcher.poll() mail = MailSender(config) def job(): try: new_results = feed_fetcher.poll_new() new_results.reverse() for result in new_results: mail.mail_entry(result) print(f"Mailing {len(new_results)} entries") except FeedFetcher.Inaccessible: print('Failed to load feed, deferring to next interval') print("Scheduling...") schedule.every(config.get_interval()).minutes.do(job) print("Now looping!") while True: schedule.run_pending() time.sleep(5)
def __init__(self): self.conn = None self.engine = None cfg = ConfigLoader() self.config = cfg.get_config() self.mysql_host = self.config.get('mysql_host') self.mysql_user = self.config.get('mysql_user') self.mysql_pass = self.config.get('mysql_pass') self.mysql_database = self.config.get('mysql_database') self.logging = Logger() conn_string = "mysql+mysqldb://{0}:{1}@{2}/{3}".format( self.mysql_user, self.mysql_pass, self.mysql_host, self.mysql_database) self.engine = create_engine(conn_string) meta = MetaData(bind=self.engine) self.dbconn = None ### Recommendations Table ### self.recommendations = Table( 'product_recommendations', meta, Column('product_id', TEXT, nullable=False), Column('related_product_id', TEXT, nullable=False), Column('school_code', Integer, nullable=True), Column('subject_code', Integer, nullable=True), Column('class_year', Integer, nullable=True), Column('tag_similarity', Integer, nullable=True), Column('similarity', Integer, nullable=True), Column('similarity_score', Integer, nullable=True))
def configure(self, df, config_num): """ Configures NN inputs - selects config_num and creates train/test split """ self.config_num = config_num CL = ConfigLoader(df, self.channel) X_train, X_test, y_train, y_test = CL.configTrainTestData(self.config_num, self.binary) return X_train, X_test, y_train, y_test
def __init__(self): cfg = ConfigLoader() self.config = cfg.get_config() host = self.config.get('redis_host') port = self.config.get('redis_port') db = self.config.get('redis_db') self.ttl = self.config.get('redis_ttl') self.db = redis.StrictRedis(host=host, port=port, db=db)
def main(): loader = ConfigLoader("config.ini",['ubuntu','staging','development']) print(loader.get('ftp')) print(loader.get('ftp.name')) print(loader.get('ftp.enabled')) print(loader.get('poda')) print(loader.get('common')) print(loader.get('common.basic_size_limit'))
def load(self, apply_ignored=True): """ Load configurations from configuration repository at the given path. :param bool apply_ignored: whether 'ignored' seetings should be taken into account """ self.config_loader = ConfigLoader(self.args.config, self.settings, apply_ignored) self.entities = self.config_loader.load()
def main(): start_time = time() print("Running Basic Setup Steps....") config_loader = ConfigLoader() output_directory_path = config_loader.get_base_path( ) + config_loader.get_output_directory_name() if not os.path.exists(output_directory_path): os.makedirs(output_directory_path) parser = Parser(config_loader) profanity_filter = ProfanityFilter(config_loader, parser) de_duplicator = DeDuplicator(parser) keyword_dictionary_builder = KeywordDictionaryBuilder(parser) sym_spell_checker = SymSpellChecker(config_loader, parser) print("Running Parser....") parser.parse(config_loader.get_query_logs_file_path(), config_loader.get_frequency_file_path(), config_loader.get_max_total_queries()) print("Running De-duplicator....") de_duplicator.remove_duplicates( config_loader.get_frequency_file_path(), config_loader.get_frequency_file_path(), config_loader.get_de_duplicated_keyword_ordered_1_file_path(), config_loader.get_de_duplicated_missing_space_1_file_path(), config_loader.get_de_duplicated_synonyms_1_file_path()) print("Running Profanity Filter....") profanity_filter.remove_profane_queries( config_loader.get_frequency_file_path(), config_loader.get_frequency_file_path(), config_loader.get_filtered_profane_queries_file_path()) print("Running Keyword Dictionary Builder....") keyword_dictionary_builder.build_dictionary_file_from_frequency_file( config_loader.get_frequency_file_path(), config_loader.get_dictionary_file_path()) print("Running SymSpell Checker....") sym_spell_checker.run_sym_spell(config_loader.get_sym_spell_iterations(), config_loader.get_frequency_file_path(), config_loader.get_dictionary_file_path(), config_loader.get_dictionary_file_path()) print("Running De-duplicator....") de_duplicator.remove_duplicates( config_loader.get_dictionary_file_path(), config_loader.get_dictionary_file_path(), config_loader.get_de_duplicated_keyword_ordered_2_file_path(), config_loader.get_de_duplicated_missing_space_2_file_path(), config_loader.get_de_duplicated_synonyms_2_file_path()) print("Completed!!!") print("Total time taken: ", (time() - start_time) / 60, " minutes")
def __init__(self): """ this class created for handling and dealing with check points """ config_loader = ConfigLoader() self.config = config_loader.get_config() connection_pool = database_connection_pool.ConnectionPool() connection = connection_pool.get_connection(self.config) self.database = check_point_db.CheckPointDatabase( connection=connection)
def __init__(self, config_file_name, dataset_files): """Initialise the program. :param config_file_name: Name of the config file. :param dataset_files: List of dataset file names. """ self._config_file_path = path.join(self._WORKING_DIR, self._CONFIG_DIR, config_file_name) self._config_loader = ConfigLoader(self._config_file_path) self._config_loader.read_config() self._dataset_files = dataset_files self._iscx2012_loader = ISCX2012IDS(dataset_files)
def test_init_merge_defaults_when_use_default_not_present(self): kwargs = { "operator_merge_default": True, "config_location": "eh" } cl = ConfigLoader(**kwargs) self.assertTrue(cl.operator_merge_default) kwargs = { "parselet_merge_default": True, "config_location": "eh" } cl = ConfigLoader(**kwargs) self.assertTrue(cl.parselet_merge_default) kwargs = { "token_merge_default": True, "config_location": "eh" } cl = ConfigLoader(**kwargs) self.assertTrue(cl.token_merge_default)
def __init__(self): """ the loaded config file will pass into this class :param config: """ loader = ConfigLoader() self.config = loader.get_config() self.smtp_ssl_host = self.config["mail_service.mail_host"]["email_host"][0] self.smtp_ssl_port = self.config["mail_service.mail_host"]["email_port"] self.username = self.config["mail_service.mail_host"]["email_user_name"] self.password = self.config["mail_service.mail_host"]["email_host_password"] self.sender = self.config["mail_service.mail_host"]["email_user_name"]
def __init__(self, config_kwargs=None): """ Given the configuration options specified, build the parser environment. Arguments: config_kwargs (dict): options for configuration, see config_loader """ if not config_kwargs: config_kwargs = {} self.configurator = Configurator(ConfigLoader(**config_kwargs).load()) self.var_repo = VarRepo() self.parser_instance = None self.tokenizer = None
def __init__(self): cfg = ConfigLoader() self.config = cfg.load() self.MONGO_HOST = self.config.get('mongo_host') self.MONGO_PORT = self.config.get('mongo_port') self.USER_LIMIT = self.config.get('data_user_limit') self.DOC_LIMIT = self.config.get('data_doc_limit') self.MIN_DOWNLOADS = self.config.get('data_min_downloads') client = MongoClient(self.MONGO_HOST, self.MONGO_PORT) self.db = client.mU self.users = None
def __init__(self): # logging.basicConfig(level=logging.DEBUG, # format='[%(levelname)s] (%(threadName)-10s) %(message)s', # ) self.logging = Logger() self.repo = MongoRepository() self.mysql = MysqlRepository() cfg = ConfigLoader() self.config = cfg.get_config() self.CUTTOFF_DAYS = timedelta( days=self.config.get('data_days_to_analyze')) self.redis = RedisRepository() self.ar_counter = 0 self.cb_counter = 0
def test_init_no_merge_if_both_not_true(self): kwargs = { "operator_merge_default": True, "config_location": "eh", "operator_use_default": False } cl = ConfigLoader(**kwargs) self.assertFalse(cl.operator_merge_default) kwargs = { "parselet_merge_default": True, "config_location": "eh", "parselet_use_default": False } cl = ConfigLoader(**kwargs) self.assertFalse(cl.parselet_merge_default) kwargs = { "token_merge_default": True, "config_location": "eh", "token_use_default": False } cl = ConfigLoader(**kwargs) self.assertFalse(cl.token_merge_default)
def __init__(self, contr): # Load config path_to_config = os.path.dirname(__file__) + "/config/" self._config = ConfigLoader(path_to_config + self._CONFIG_POLICIES_FILE_NAME, path_to_config + self._CONFIG_RULE_FILE_NAME) # Set logging logging_config = self._config.get_logging_config() self._logging = logging.getLogger(__name__) self._logging.setLevel(logging_config["min_lvl"]) self._logging.propagate = logging_config["propagate"] self._logging.addHandler(logging_config["handler"]) # Set flow table numbers self._table_id_blacklist = 0 self._table_id_whitelist = 1 self._table_id_next = 2 self._contr = contr self._supported = self._verify_contr_handlers() self._logging.info("Starting ACLSwitch...") # Create objects to manage different features self._flow_man = FlowManager(self, logging_config) self._api = ACLSwitchAPI(logging_config, self._VERSION, self._flow_man) self._api.policy_create(self._POLICY_DEFAULT) # Read config files # TODO Command line argument for custom location for config file policies, pd_assignments = self._config.load_policies() rules = self._config.load_rules() for pol in policies: self._api.policy_create(pol) for rule in rules: self._api.acl_create_rule(rule) for assignment in pd_assignments: self._api.switch_register(assignment["switch_id"]) self._api.policy_assign_switch(assignment["switch_id"], assignment["policy"], from_file=True) # Register REST WSGI through the controller app self._contr.register_rest_wsgi(ACLSwitchREST, kwargs={ self._INSTANCE_NAME_ASW_API: self._api}) self._logging.info("ACLSwitch started successfully.")
def __init__(self): conf_loader = ConfigLoader() dict_conf = conf_loader.dict_conf dict_bm = conf_loader.dict_bookmark self.conf_loader = conf_loader self.bm_viewer = BmViewer(self, dict_bm['bookmarks']) # init viewers self.var_zsbook_search_viewer = ZSBookSearchViewer(self) self.var_menu_viewer = MenuViewer(self) self.var_book_viewer = EBookReader(self) self.var_img_viewer = EImgReader(self) self.reader_viewer = None self.var_zsbook_loader = ZSBookLoader() self.var_ebook_loader = EBookLoader(dict_conf) self.var_eing_loader = EImgLoader(dict_conf) self.var_loader = None self.curr_type = None bottom_view = HomeViewer(self).view view = ui.NavigationView(bottom_view) self.stack_views = [bottom_view] # 额外保存,用于读取navigation view栈内信息 view.navigation_bar_hidden = True btn_item_pop = ui.ButtonItem( image=ui.Image.named('iob:arrow_return_left_24')) btn_item_pop.action = self.pop_1_view btn_item_push_menu = ui.ButtonItem( image=ui.Image.named('iob:navicon_round_24')) btn_item_push_menu.action = self.push_menu_view self.btn_items_pop = [btn_item_pop] self.btn_items_push_menu = [btn_item_push_menu] self.view = view self.set_right_button_items(bottom_view.right_btns_desc) self.queue_body = None self.queue_index = None self.is_req_body = False self.is_req_index = False
def __init__(self, ELoader, ReaderViewer): conf_loader = ConfigLoader() dict_conf = conf_loader.dict_conf dict_bm = conf_loader.dict_bookmark self.reader_viewer = ReaderViewer(self) self.bm_viewer = BmViewer(self, dict_bm['bookmarks']) self.menu_viewer = MenuViewer(self) self.var_eloader = ELoader(dict_conf) self.navi_viewer = NaviViewer( self, self.reader_viewer.var_ebody_viewer.reader_view) self.conf_loader = conf_loader self.queue_ebody = Queue() self.queue_eindex = Queue() self.has_sent_req = False self.has_sent_eindex_req = False
def __init__(self): """ Virtually private constructor. """ if Scheduler.__instance is not None: raise Exception("This class is a singleton!") else: Scheduler.__instance = self config_loader = ConfigLoader() self.config = config_loader.get_config() executors = { 'default': ThreadPoolExecutor(self.config['check_point.scheduler']['thread_pool_executor']), 'processpool': ProcessPoolExecutor(self.config['check_point.scheduler']['process_pool_executor']) } job_defaults = { 'coalesce': False, 'max_instances': 10 } self.scheduler = BackgroundScheduler(executors=executors, job_defaults=job_defaults) self.scheduler.start()
def load(config_path): global CALIBRATION_STAGES, CALIBRATION_CONFIGS, TARGET_SOURCE_STAGES, \ TARGET_SOURCE_CONFIGS, MAIN_STAGES, PIPELINE_CONFIGS, \ GLOBAL_CONFIGS, CONFIG_PATH, CASA_CONFIGS, IMAGING_CONFIGS CALIBRATION_STAGES = ConfigLoader().load( config_path + "calibration.yml")['calibration_stages'] CALIBRATION_CONFIGS = ConfigLoader().load(config_path + "calibration.yml")['calibration'] PIPELINE_CONFIGS = ConfigLoader().load(config_path + "pipeline.yml") TARGET_SOURCE_STAGES = ConfigLoader().load( config_path + "target_source.yml")['target_source_stages'] TARGET_SOURCE_CONFIGS = ConfigLoader().load( config_path + "target_source.yml")['target_source'] IMAGING_CONFIGS = ConfigLoader().load(config_path + "imaging.yml") CASA_CONFIGS = ConfigLoader().load(config_path + "casa.yml") GLOBAL_CONFIGS = PIPELINE_CONFIGS['global'] MAIN_STAGES = PIPELINE_CONFIGS['stages'] CONFIG_PATH = config_path
def test_init_use_defaults_by_default(self): kwargs = {} cl = ConfigLoader(**kwargs) self.assertTrue(cl.operator_use_default) self.assertTrue(cl.parselet_use_default) self.assertTrue(cl.token_use_default)
def __init__(self): """ """ loader = ConfigLoader() self.config = loader.get_config() self.sender = send_module.SendModule()
def __init__(self): cfg = ConfigLoader() self.config = cfg.get_config() self.SIMILARITY_CUTOFF = self.config.get('similarity_cuttoff') self.logging = Logger()
import bili_console import threading from cdn import Host from super_user import SuperUser if sys.platform == 'win32': loop = asyncio.ProactorEventLoop() asyncio.set_event_loop(loop) else: loop = asyncio.get_event_loop() fileDir = os.path.dirname(os.path.realpath('__file__')) file_color = f'{fileDir}/config/color.toml' file_user = f'{fileDir}/config/user.toml' file_bili = f'{fileDir}/config/bili.toml' file_ip = f'{fileDir}/config/ips.toml' cfg = ConfigLoader(file_color, file_user, file_bili, file_ip) dict_user = cfg.read_user() dict_bili = cfg.read_bili() dict_color = cfg.read_color() dict_ip = cfg.read_ip() Printer(dict_color, dict_user['print_control']['danmu'], dict_user['platform']['platform']) task_control = dict_user['task_control'] if len(dict_user['users']) < 10: users = [ User(i, user_info, dict_bili, task_control, False) for i, user_info in enumerate(dict_user['users']) ] else:
def write_user(self, dict_new): self.webhub.set_status(dict_new) ConfigLoader().write_user(dict_new, self.user_id)
if __name__ == "__main__": # event loop loop = asyncio.get_event_loop() # signal signal.signal(signal.SIGINT, clash_handler) # working directory working_path = os.path.abspath(sys.argv[1]) print("working directory: {0}".format(working_path)) # make data directory _data_directory = "{0}/data".format(working_path) if os.path.exists(_data_directory): shutil.rmtree(_data_directory) print("remove old data folder") os.mkdir(_data_directory) print("make data folder") # load configuration config = Configuration("", []) _config_path = "{0}/config.yml".format(working_path) _config_loader = ConfigLoader(path=_config_path, config=config) print("Listener:\n{0}\nSpeaker:\n{1}".format(config.listener_token, config.speaker_token_list)) # lunch bot bot_manager = BotManager(config=config, loop=loop, working_path=_data_directory) # run loop loop.run_forever()
return cert_applied def manage_ucp_certs(): logger.info("UPC certificate management started...") cert_applied = False if generate_ucp_certs() or config['certbot']['always_apply_certs']['ucp']: cert_applied = True logger.info("Applying UCP certificates") apply_ucp_certs() logger.info("UCP certificates applied") logger.info("UCP certificate management complete") return cert_applied if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument("--conf_dir", help="Configuration directory to use") args = parser.parse_args() config = ConfigLoader(args.conf_dir).load() logger = Logger(filename=__file__, log_level=config['logging']['log_level']) manage_certs()