From 2bcbd241340494e9b8f292e556ab66d984f7c3c7 Mon Sep 17 00:00:00 2001 From: Sergio Oliveira Date: Thu, 9 Apr 2015 18:01:45 -0300 Subject: [PATCH] Removed settings yaml --- .travis.yml | 3 +-- colab/settings.py | 6 ------ colab/utils/conf.py | 93 +++++---------------------------------------------------------------------------------------- setup.py | 2 -- tests/config_settings.py | 11 ----------- tests/run.py | 4 +--- tests/settings.py | 15 +++++++++++++-- 7 files changed, 20 insertions(+), 114 deletions(-) delete mode 100644 tests/config_settings.py diff --git a/.travis.yml b/.travis.yml index d6132d8..b028529 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,8 +7,7 @@ python: env: global: - - DJANGO_SETTINGS_MODULE=tests.settings - - COLAB_SETTINGS=tests/settings.yaml + - DJANGO_SETTINGS_MODULE=tests.settings install: - pip install coveralls flake8 diff --git a/colab/settings.py b/colab/settings.py index 6ee3b78..77eb8d3 100644 --- a/colab/settings.py +++ b/colab/settings.py @@ -279,14 +279,8 @@ CONVERSEJS_SHOW_ONLY_ONLINE_USERS = True # Tastypie settings TASTYPIE_DEFAULT_FORMATS = ['json', ] -from .utils.conf import load_yaml_settings -from .utils.conf import load_py_settings from .utils.conf import load_colab_apps -locals().update(load_yaml_settings()) - -locals().update(load_py_settings()) - if locals().get('RAVEN_DSN', False): RAVEN_CONFIG = { 'dsn': RAVEN_DSN + '?timeout=30', # noqa diff --git a/colab/utils/conf.py b/colab/utils/conf.py index 484d301..ccf1ade 100644 --- a/colab/utils/conf.py +++ b/colab/utils/conf.py @@ -4,68 +4,12 @@ import sys import warnings -import yaml - -import yamlordereddictloader - from django.core.exceptions import ImproperlyConfigured import importlib -USING_YAML_SETTINGS = False - - -class InaccessibleYAMLSettings(ImproperlyConfigured): - """Settings YAML is Inaccessible. - - Check if the file exists and if you have read permissions.""" - - -def _load_yaml_file(yaml_path): - try: - with open(yaml_path) as yaml_file: - yaml_settings = yaml.load(yaml_file.read(), - yamlordereddictloader.Loader) - except IOError: - msg = ('Could not open settings file {}. Please ' - 'check if the file exists and if user ' - 'has read rights.').format(yaml_path) - raise InaccessibleYAMLSettings(msg) - - return yaml_settings - - -def load_yaml_settings(): - settings_dir = '/etc/colab/settings.d' - yaml_path = os.getenv('COLAB_YAML_SETTINGS', '/etc/colab/settings.yaml') - - if os.path.exists(yaml_path): - global USING_YAML_SETTINGS - USING_YAML_SETTINGS = True - warnings.warn("YAML Settings file is deprecated. Use Py file instead.") - else: - return {} - - yaml_settings = _load_yaml_file(yaml_path) - - parse_yml_menus(yaml_settings) - - # Try to read settings from settings.d - if os.path.exists(settings_dir): - for file_name in os.listdir(settings_dir): - if file_name.endswith('.yaml') or file_name.endswith('yml'): - file_path = os.path.join(settings_dir, file_name) - yaml_settings_d = _load_yaml_file(file_path) - - parse_yml_menus(yaml_settings_d) - - yaml_settings.update(yaml_settings_d) - - return yaml_settings or {} - - -class InaccessiblePySettings(ImproperlyConfigured): +class InaccessibleSettings(ImproperlyConfigured): """Settings.py is Inaccessible. Check if the file exists and if you have read permissions.""" @@ -82,11 +26,11 @@ def _load_py_file(py_path, path): msg = ('Could not open settings file {}. Please ' 'check if the file exists and if user ' 'has read rights.').format(py_path) - raise InaccessiblePySettings(msg) + raise InaccessibleSettings(msg) except SyntaxError as excpt: msg = ('Syntax Error: {}'.format(excpt)) - raise InaccessiblePySettings(msg) + raise InaccessibleSettings(msg) finally: sys.path = original_path @@ -103,12 +47,9 @@ def load_py_settings(): settings_module = settings_file.split('.')[-2].split('/')[-1] py_path = "/".join(settings_file.split('/')[:-1]) - global USING_YAML_SETTINGS - if not os.path.exists(py_path) and not USING_YAML_SETTINGS: + if not os.path.exists(py_path): msg = "The py file {} does not exist".format(py_path) - raise InaccessiblePySettings(msg) - elif USING_YAML_SETTINGS: - return {} + raise InaccessibleSettings(msg) py_settings = _load_py_file(settings_module, py_path) @@ -128,10 +69,6 @@ def load_py_settings(): def load_colab_apps(): plugins_dir = os.getenv('COLAB_PLUGINS', '/etc/colab/plugins.d/') - global USING_YAML_SETTINGS - if USING_YAML_SETTINGS: - return {} - COLAB_APPS = {} # Try to read settings from plugins.d @@ -159,23 +96,3 @@ def load_colab_apps(): COLAB_APPS[app_name][key] = value return {'COLAB_APPS': COLAB_APPS} - - -def parse_yml_menus(yaml_settings): - if 'COLAB_APPS' in yaml_settings: - for key, plugin in yaml_settings['COLAB_APPS'].items(): - if 'menu' in plugin: - parse_yml_tuples(yaml_settings['COLAB_APPS'][key]['menu']) - - -def parse_yml_tuples(menu): - dict_links = menu['links'] - dict_auth_links = menu['auth_links'] - menu['links'] = tuple() - menu['auth_links'] = tuple() - - for key, value in dict_links.items(): - menu['links'] += ((key, value),) - - for key, value in dict_auth_links.items(): - menu['auth_links'] += ((key, value),) diff --git a/setup.py b/setup.py index 361ee32..bbadab6 100644 --- a/setup.py +++ b/setup.py @@ -24,8 +24,6 @@ REQUIREMENTS = [ 'django-tastypie==0.11.0', 'gunicorn==19.1.0', 'eventlet==0.15.2', - 'PyYAML==3.11', - 'yamlordereddictloader==0.1.1', # Deps for sentry client (raven) 'raven==3.5.2', diff --git a/tests/config_settings.py b/tests/config_settings.py deleted file mode 100644 index c7c6f26..0000000 --- a/tests/config_settings.py +++ /dev/null @@ -1,11 +0,0 @@ -SECRET_KEY = 'ddddddddddddddddddddddddddddddddddddddddddddddddddddddaddddddddd' - -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.postgresql_psycopg2', - 'HOST': 'localhost', - 'NAME': 'colab', - 'USER': 'colab', - 'PASSWORD': 'colab', - } -} diff --git a/tests/run.py b/tests/run.py index c88597d..ff172cc 100755 --- a/tests/run.py +++ b/tests/run.py @@ -4,11 +4,9 @@ import os import sys os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings' -os.environ['COLAB_SETTINGS'] = 'tests/config_settings.py' -os.environ['COLAB_YAML_SETTINGS'] = 'tests/settings.yaml' os.environ['COLAB_PLUGINS'] = 'tests/plugins.d' os.environ['COVERAGE_PROCESS_START'] = '.coveragerc' -os.environ['REUSE_DB'] = '0' + import django import coverage diff --git a/tests/settings.py b/tests/settings.py index d7670d2..8e6bed1 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -32,8 +32,19 @@ LOGGING = { import os HAYSTACK_CONNECTIONS = { 'default': { - 'ENGINE': 'haystack.backends.solr_backend.SolrEngine', - 'URL': 'http://127.0.0.1:8983/solr' + 'ENGINE': 'haystack.backends.solr_backend.SolrEngine', + 'URL': 'http://127.0.0.1:8983/solr', }, } +SECRET_KEY = 'not-a-secret' + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'HOST': 'localhost', + 'NAME': 'colab', + 'USER': 'colab', + 'PASSWORD': 'colab', + } +} -- libgit2 0.21.2