horizon/openstack_dashboard/utils/config.py
Ivan Kolodyazhny d870b40583 Remove six usage from openstack_dashboard package
We don't support Python 2 anymore so we don't need this
compatibility library.

six.reraise usages are left as is until it'll be moved to some
base lib like oslo.utils to not re-implenent this method in
Horizon.

This patch also removes Python2-specific base test case methods
assertItemsEqual and assertNotRegexpMatches in flavor of new
Python 3 analogues.

Change-Id: I26a59176be9e9f213128e4945a58b9459334b626
2020-01-15 12:47:48 +02:00

67 lines
2.2 KiB
Python

# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""
This module contains utility functions for loading Horizon's
configuration from .ini files using the oslo.config library.
"""
from oslo_config import cfg
# XXX import the actual config groups here
# from openstack_dashboard.config import config_compress
def load_config(files=None, root_path=None, local_path=None):
"""Load the configuration from specified files."""
config = cfg.ConfigOpts()
config.register_opts([
cfg.Opt('root_path', default=root_path),
cfg.Opt('local_path', default=local_path),
])
# XXX register actual config groups here
# theme_group = config_theme.register_config(config)
if files is not None:
config(args=[], default_config_files=files)
return config
def apply_config(config, target):
"""Apply the configuration on the specified settings module."""
# TODO(rdopiera) fill with actual config groups
# apply_config_group(config.email, target, 'email')
def apply_config_group(config_group, target, prefix=None):
for key, value in config_group.items():
name = key.upper()
if prefix:
name = '_'.join([prefix.upper(), name])
target[name] = value
def list_options():
# This is a really nasty hack to make the translatable strings
# work without having to initialize Django and read all the settings.
from django.apps import registry
from django.conf import settings
settings.configure()
registry.apps.check_apps_ready = lambda: True
config = load_config()
return [
(name, [d['opt'] for d in group._opts.values()])
for (name, group) in config._groups.items()
]