Python config.Configuration() Examples

The following are 30 code examples of config.Configuration(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module config , or try the search function .
Example #1
Source File: repo_index.py    From personfinder with Apache License 2.0 7 votes vote down vote up
def post(self, request, *args, **kwargs):
        """Serves POST requests, updating the repo's configuration."""
        del request, args, kwargs  # Unused.
        self.enforce_xsrf(self.ACTION_ID)
        validation_response = self._validate_input()
        if validation_response:
            return validation_response
        self._set_language_config()
        self._set_activation_config()
        self._set_data_retention_config()
        self._set_keywords_config()
        self._set_forms_config()
        self._set_map_config()
        self._set_timezone_config()
        self._set_api_access_control_config()
        self._set_zero_rating_config()
        self._set_spam_config()
        # Reload the config since we just changed it.
        self.env.config = config.Configuration(self.env.repo)
        return self._render_form() 
Example #2
Source File: test_admin_repo_index.py    From personfinder with Apache License 2.0 6 votes vote down vote up
def test_edit_activation_status_config(self):
        # Set the time to an hour past the original update_date.
        utils.set_utcnow_for_test(datetime.datetime(2019, 5, 10, 12, 15, 0))
        self.login_as_superadmin()
        self._post_with_params(
            activation_status=str(model.Repo.ActivationStatus.DEACTIVATED),
            deactivation_message_html='it is deactivated')
        repo = model.Repo.get_by_key_name('haiti')
        self.assertEqual(
            repo.activation_status, model.Repo.ActivationStatus.DEACTIVATED)
        repo_conf = config.Configuration('haiti')
        self.assertEqual(
            repo_conf.deactivation_message_html, 'it is deactivated')
        self.assertEqual(
            repo_conf.updated_date,
            utils.get_timestamp(datetime.datetime(2019, 5, 10, 12, 15, 0))) 
Example #3
Source File: test_admin_create_repo.py    From personfinder with Apache License 2.0 6 votes vote down vote up
def test_create_repo(self):
        """Tests POST requests to create a new repo."""
        get_doc = self.to_doc(self.client.get(
            '/global/admin/create_repo/', secure=True))
        xsrf_token = get_doc.cssselect_one('input[name="xsrf_token"]').get(
            'value')
        post_resp = self.client.post('/global/admin/create_repo/', {
            'xsrf_token': xsrf_token,
            'new_repo': 'idaho'
        }, secure=True)
        # Check that the user's redirected to the repo's main admin page.
        self.assertIsInstance(post_resp, django.http.HttpResponseRedirect)
        self.assertEqual(post_resp.url, '/idaho/admin')
        # Check that the repo object is put in datastore.
        repo = model.Repo.get_by_key_name('idaho')
        self.assertIsNotNone(repo)
        self.assertEqual(
            repo.activation_status, model.Repo.ActivationStatus.STAGING)
        self.assertIs(repo.test_mode, False)
        # Check a couple of the config fields that are set by default.
        repo_conf = config.Configuration('idaho')
        self.assertEqual(repo_conf.language_menu_options, ['en', 'fr'])
        self.assertIs(repo_conf.launched, False)
        self.assertEqual(repo_conf.time_zone_abbreviation, 'UTC') 
Example #4
Source File: test_admin_repo_index.py    From personfinder with Apache License 2.0 6 votes vote down vote up
def test_manager_edit_restrictions(self):
        self.login_as_manager()
        self._post_with_params(
            use_family_name='true',
            family_name_first='true',
            use_alternate_names='true',
            use_postal_code='true',
            allow_believed_dead_via_ui='true',
            min_query_word_length='2',
            show_profile_entry='true',
            map_default_zoom='8',
            map_default_center='[32.7, 85.6]',
            map_size_pixels='[300, 450]',
            time_zone_offset='5.75',
            time_zone_abbreviation='NPT',
            search_auth_key_required='true',
            read_auth_key_required='true',
            zero_rating_mode='true',
            bad_words='voldemort')
        repo_conf = config.Configuration('haiti')
        for key, value in AdminRepoIndexViewTests._PRIOR_CONFIG.items():
            self.assertEqual(repo_conf.get(key), value) 
Example #5
Source File: test_admin_repo_index.py    From personfinder with Apache License 2.0 6 votes vote down vote up
def test_edit_forms_config(self):
        self.login_as_superadmin()
        self._post_with_params(
            use_family_name='true',
            family_name_first='true',
            use_alternate_names='true',
            use_postal_code='true',
            allow_believed_dead_via_ui='true',
            min_query_word_length='2',
            show_profile_entry='true',
            # The value for this doesn't really matter.
            profile_websites='{"arbitrary": "json"}')
        repo_conf = config.Configuration('haiti')
        self.assertIs(repo_conf.use_family_name, True)
        self.assertIs(repo_conf.family_name_first, True)
        self.assertIs(repo_conf.use_alternate_names, True)
        self.assertIs(repo_conf.use_postal_code, True)
        self.assertIs(repo_conf.allow_believed_dead_via_ui, True)
        self.assertEqual(repo_conf.min_query_word_length, 2)
        self.assertIs(repo_conf.show_profile_entry, True)
        self.assertEqual(repo_conf.profile_websites, {'arbitrary': 'json'}) 
Example #6
Source File: global_index.py    From personfinder with Apache License 2.0 6 votes vote down vote up
def post(self, request, *args, **kwargs):
        """Serves POST requests, updating the repo's configuration."""
        del request, args, kwargs  # Unused.
        self.enforce_xsrf(self.ACTION_ID)
        validation_response = self._validate_input()
        if validation_response:
            return validation_response
        self._set_sms_config()
        self._set_repo_alias_config()
        self._set_site_info_config()
        self._set_recaptcha_config()
        self._set_ganalytics_config()
        self._set_gmaps_config()
        self._set_gtranslate_config()
        self._set_notification_config()
        # Reload the config since we just changed it.
        self.env.config = config.Configuration('*')
        return self._render_form() 
Example #7
Source File: dwdownloader.py    From daily-wallpaper with MIT License 6 votes vote down vote up
def change_wallpaper():
    config = Configuration()
    source = config.get('source')
    random = config.get('random')
    if random:
        modules = get_modules()
        selected = randrange(len(modules))
        source = modules[selected]
    module = importlib.import_module(source)
    daily = module.get_daily()
    if daily.resolve_url():
        if download(daily.get_url()):
            if daily.get_title():
                title = '{}: {}'.format(daily.get_name(), daily.get_title())
            else:
                title = daily.get_name()
            caption = daily.get_caption()
            credit = daily.get_credit()
            notify_photo_caption(title, caption, credit)
            set_background(comun.POTD) 
Example #8
Source File: __init__.py    From Providence with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def process(self, repo_patch, alert_callback=None):
        data = u'\n'.join(repo_patch.diff.additions).encode('utf-8').strip()
        def _alert_callback(alert_action):
            alert_config_key = alert_action.get("alert config")
            alert_config = self._alert_configs.get(alert_config_key)
            if alert_config is None:
                logger.error("Alert config for [%s] is None", alert_config_key);
                return
            if alert_config.get("email"):
                default_email = config.Configuration('config.json').get(('email', 'to'))
                to_email = alert_config.get("email", default_email)
                patch_lines = u'\n'.join(repo_patch.diff.additions).encode('utf-8').strip()
                subject = alert_action.get("subject","Unknown Subject")
                (text, html) = self.create_alert_email(subject, data, repo_patch.repo_commit)
                ea = EmailAlert(Alert(subject=subject, 
                                      message=text.encode('utf-8'), 
                                      message_html=html.encode('utf-8')), 
                                to_email=to_email)
                if (self.test_mode == True):
                    print ea
                else:
                    ea.send()
            else:
                logger.warn("Alert type unknown %s" % (alert_config))

        if alert_callback is None:
            alert_callback = _alert_callback
        #data = repo_patch
        for rule in self._rules:
            self._process(data, rule, alert_callback) 
Example #9
Source File: main.py    From daily-wallpaper with MIT License 5 votes vote down vote up
def save_preferences(self):
        config = Configuration()
        config.set('source', get_selected_value_in_combo(self.combobox_source))
        config.set('random', self.switch_random.get_active())
        config.save() 
Example #10
Source File: test_admin_global_index.py    From personfinder with Apache License 2.0 5 votes vote down vote up
def test_edit_gtranslate_config(self):
        self._post_with_params(translate_api_key='NEW-translate-api-key')
        conf = config.Configuration('*')
        self.assertEqual(conf.translate_api_key, 'NEW-translate-api-key') 
Example #11
Source File: test_admin_global_index.py    From personfinder with Apache License 2.0 5 votes vote down vote up
def test_edit_gmaps_config(self):
        self._post_with_params(maps_api_key='NEW-maps-api-key')
        conf = config.Configuration('*')
        self.assertEqual(conf.maps_api_key, 'NEW-maps-api-key') 
Example #12
Source File: test_admin_global_index.py    From personfinder with Apache License 2.0 5 votes vote down vote up
def test_edit_ganalytics_config(self):
        self._post_with_params(
            analytics_id='NEW-analytics-id',
            amp_gtm_id='NEW-amp-gtm-id')
        conf = config.Configuration('*')
        self.assertEqual(conf.analytics_id, 'NEW-analytics-id')
        self.assertEqual(conf.amp_gtm_id, 'NEW-amp-gtm-id') 
Example #13
Source File: test_admin_global_index.py    From personfinder with Apache License 2.0 5 votes vote down vote up
def test_edit_recaptcha_config(self):
        self._post_with_params(
            captcha_site_key='NEW-captcha-key',
            captcha_secret_key='NEW-captcha-secret-key')
        conf = config.Configuration('*')
        self.assertEqual(conf.captcha_site_key, 'NEW-captcha-key')
        self.assertEqual(conf.captcha_secret_key, 'NEW-captcha-secret-key') 
Example #14
Source File: test_admin_global_index.py    From personfinder with Apache License 2.0 5 votes vote down vote up
def test_edit_site_info_config(self):
        self._post_with_params(
            brand='google',
            privacy_policy_url='othersite.org/privacy',
            tos_url='othersite.org/tos',
            feedback_url='othersite.org/feedback')
        conf = config.Configuration('*')
        self.assertEqual(conf.brand, 'google')
        self.assertEqual(conf.privacy_policy_url, 'othersite.org/privacy')
        self.assertEqual(conf.tos_url, 'othersite.org/tos')
        self.assertEqual(conf.feedback_url, 'othersite.org/feedback') 
Example #15
Source File: test_admin_global_index.py    From personfinder with Apache License 2.0 5 votes vote down vote up
def test_edit_sms_config(self):
        self._post_with_params(sms_number_to_repo='{"+1800pfhaiti": "haiti"}')
        conf = config.Configuration('*')
        self.assertEqual(conf.sms_number_to_repo, {'+1800pfhaiti': 'haiti'}) 
Example #16
Source File: test_admin_repo_index.py    From personfinder with Apache License 2.0 5 votes vote down vote up
def test_edit_spam_config(self):
        self.login_as_superadmin()
        self._post_with_params(bad_words='voldemort')
        repo_conf = config.Configuration('haiti')
        self.assertEqual(repo_conf.bad_words, 'voldemort') 
Example #17
Source File: test_admin_repo_index.py    From personfinder with Apache License 2.0 5 votes vote down vote up
def test_edit_zero_rating_config(self):
        self.login_as_superadmin()
        self._post_with_params(zero_rating_mode='true')
        repo_conf = config.Configuration('haiti')
        self.assertIs(repo_conf.zero_rating_mode, True) 
Example #18
Source File: test_admin_repo_index.py    From personfinder with Apache License 2.0 5 votes vote down vote up
def test_api_access_control_config(self):
        self.login_as_superadmin()
        self._post_with_params(
            search_auth_key_required='true',
            read_auth_key_required='true')
        repo_conf = config.Configuration('haiti')
        self.assertIs(repo_conf.search_auth_key_required, True)
        self.assertIs(repo_conf.read_auth_key_required, True) 
Example #19
Source File: test_admin_repo_index.py    From personfinder with Apache License 2.0 5 votes vote down vote up
def test_edit_map_config(self):
        self.login_as_superadmin()
        self._post_with_params(
            map_default_zoom='8',
            map_default_center='[32.7, 85.6]',
            map_size_pixels='[300, 450]')
        repo_conf = config.Configuration('haiti')
        self.assertEqual(repo_conf.map_default_zoom, 8)
        self.assertEqual(repo_conf.map_default_center, [32.7, 85.6])
        self.assertEqual(repo_conf.map_size_pixels, [300, 450]) 
Example #20
Source File: providence.py    From Providence with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def set_global_config():
    configuration = config.Configuration('config.json')
    config.providence_configuration = configuration
    return configuration 
Example #21
Source File: test_admin_repo_index.py    From personfinder with Apache License 2.0 5 votes vote down vote up
def test_edit_keywords_config(self):
        self.login_as_superadmin()
        self._post_with_params(keywords='haiti,earthquake')
        repo_conf = config.Configuration('haiti')
        self.assertEqual(repo_conf.keywords, 'haiti,earthquake') 
Example #22
Source File: test_admin_repo_index.py    From personfinder with Apache License 2.0 5 votes vote down vote up
def test_edit_data_retention_mode_config(self):
        # Set the time to an hour past the original update_date.
        utils.set_utcnow_for_test(datetime.datetime(2019, 5, 10, 12, 15, 0))
        self.login_as_superadmin()
        self._post_with_params(test_mode=True)
        repo = model.Repo.get_by_key_name('haiti')
        self.assertTrue(repo.test_mode)
        repo_conf = config.Configuration('haiti')
        self.assertIs(repo_conf.test_mode, True)
        self.assertEqual(
            repo_conf.updated_date,
            utils.get_timestamp(datetime.datetime(2019, 5, 10, 12, 15, 0))) 
Example #23
Source File: main.py    From daily-wallpaper with MIT License 5 votes vote down vote up
def load_preferences(self):
        config = Configuration()
        select_value_in_combo(self.combobox_source, config.get('source'))
        self.switch_random.set_active(config.get('random'))
        self.set_source_state(not config.get('random')) 
Example #24
Source File: test_admin_repo_index.py    From personfinder with Apache License 2.0 5 votes vote down vote up
def test_edit_repo_titles(self):
        self.login_as_superadmin()
        self._post_with_params(
            repotitle__en='en title', repotitle__fr='new and improved fr title')
        repo_conf = config.Configuration('haiti')
        self.assertEqual(
            repo_conf.repo_titles['fr'], 'new and improved fr title') 
Example #25
Source File: test_admin_repo_index.py    From personfinder with Apache License 2.0 5 votes vote down vote up
def test_edit_lang_list(self):
        self.login_as_superadmin()
        self._post_with_params(
            langlist__0='en', langlist__1='fr', langlist__2='es')
        repo_conf = config.Configuration('haiti')
        self.assertEqual(repo_conf.language_menu_options, ['en', 'fr', 'es']) 
Example #26
Source File: repo_feed.py    From personfinder with Apache License 2.0 5 votes vote down vote up
def add_feed_elements(self, root):
        ET.SubElement(root, 'id').text = self.build_absolute_uri()
        ET.SubElement(root, 'title').text = RepoFeedView._TITLE
        if self.env.repo == 'global':
            repos = model.Repo.all().filter(
                'activation_status !=', model.Repo.ActivationStatus.STAGING)
        else:
            repo = model.Repo.get(self.env.repo)
            if repo.activation_status == model.Repo.ActivationStatus.ACTIVE:
                repos = [repo]
            else:
                raise django.http.Http404()
        repo_confs = {}
        for repo in repos:
            repo_id = repo.key().name()
            repo_conf = config.Configuration(repo_id, include_global=False)
            repo_confs[repo_id] = repo_conf
        updated_dates = [conf.updated_date for conf in repo_confs.values()]
        # If there's no non-staging repositories, it's not really clear what
        # updated_date should be; we just use the current time.
        latest_updated_date = (
            max(updated_dates) if updated_dates else utils.get_utcnow())
        ET.SubElement(root, 'updated').text = utils.format_utc_timestamp(
            latest_updated_date)
        for repo in repos:
            if repo.activation_status == model.Repo.ActivationStatus.ACTIVE:
                self._add_repo_entry(root, repo, repo_confs[repo.key().name()]) 
Example #27
Source File: email_alert.py    From Providence with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __init__(self, alert=None, creds=None):
        configuration = config.Configuration('config.json')

        self.server = configuration.get(('email', 'host'))
        self.to_email = configuration.get(('email', 'to'))
        self.from_email = self.to_email 
        self.creds=creds
        self.alert=alert 
Example #28
Source File: test_pluginloader.py    From Providence with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def setUp(self):
        configuration = config.Configuration('tests/plugins/test_pluginloader.config.json')
        self.plugins = Plugins(configuration) 
Example #29
Source File: get_em_result.py    From U-Net-Fixed-Point-Quantization-for-Medical-Image-Segmentation with MIT License 5 votes vote down vote up
def parse_configs(config_files, base_em_dir):
    global is_cuda
    is_cuda = True
    configs = []
    for config_file in config_files:
        config_file = base_em_dir+config_file+"/config.yaml"
        config = configuration.Configuration(model_type, config_file)
        config = config.config_dict
        is_cuda &= True if (str(config['gpu_core_num']).lower() != "none" and torch.cuda.is_available()) else False
        model  = get_model(config)
        config_obj = {}
        config_obj['model'] = model
        config_obj['config']= config
        configs.append(config_obj)
    return configs 
Example #30
Source File: get_nih_result.py    From U-Net-Fixed-Point-Quantization-for-Medical-Image-Segmentation with MIT License 5 votes vote down vote up
def parse_configs(config_files, base_em_dir):
    global is_cuda
    is_cuda = True
    configs = []
    for config_file in config_files:
        config_file = base_em_dir+config_file+"/config.yaml"
        config = configuration.Configuration(model_type, config_file)
        config = config.config_dict
        is_cuda &= True if (str(config['gpu_core_num']).lower() != "none" and torch.cuda.is_available()) else False
        model  = get_model(config)
        config_obj = {}
        config_obj['model'] = model
        config_obj['config']= config
        configs.append(config_obj)
    return configs