From d9ef612744a1f634602a29f7ee7e67c0ad393d33 Mon Sep 17 00:00:00 2001 From: Iacopo Spalletti Date: Sun, 9 Mar 2014 09:03:02 +0100 Subject: [PATCH 1/3] Add tests for --extra-settings --- tests/data/extra_settings.py | 2 ++ tests/django.py | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 tests/data/extra_settings.py diff --git a/tests/data/extra_settings.py b/tests/data/extra_settings.py new file mode 100644 index 0000000..3e1cecd --- /dev/null +++ b/tests/data/extra_settings.py @@ -0,0 +1,2 @@ +CUSTOM_SETTINGS_VAR = True +CMS_PERMISSION = False \ No newline at end of file diff --git a/tests/django.py b/tests/django.py index bf53206..06a3f97 100644 --- a/tests/django.py +++ b/tests/django.py @@ -84,6 +84,32 @@ def test_copy_data(self): self.assertTrue(os.path.exists(starting_page_py)) self.assertTrue(os.path.exists(starting_page_json)) + def test_patch_16_settings(self): + extra_path = os.path.join(os.path.dirname(__file__), 'data', 'extra_settings.py') + config_data = config.parse(['--db=sqlite://localhost/test.db', + '--lang=en', '--extra-settings=%s' % extra_path, + '--django-version=1.6', + '--cms-version=3.0', '--timezone=Europe/Moscow', + '-q', '-u', '-zno', '--i18n=no', + '-p'+self.project_dir, 'example_path_16_settigns']) + install.requirements(config_data.requirements) + django.create_project(config_data) + django.patch_settings(config_data) + django.copy_files(config_data) + # settings is importable even in non django environment + sys.path.append(config_data.project_directory) + + project = __import__(config_data.project_name, + globals(), locals(), ['settings']) + + ## checking for django options + self.assertTrue(project.settings.MEDIA_ROOT, os.path.join(config_data.project_directory, 'media')) + self.assertEqual(project.settings.MEDIA_URL, '/media/') + + # Data from external settings file + self.assertEqual(project.settings.CUSTOM_SETTINGS_VAR, True) + self.assertEqual(project.settings.CMS_PERMISSION, False) + def test_patch_16(self): config_data = config.parse(['--db=sqlite://localhost/test.db', '--lang=en', From a3ca6c37d038e882406e30885853767c434d1c65 Mon Sep 17 00:00:00 2001 From: Iacopo Spalletti Date: Mon, 17 Feb 2014 15:45:58 +0100 Subject: [PATCH 2/3] Add extra settings file to provide common setting parameter. The setting in the former file will be appended to the generated file. --- djangocms_installer/config/__init__.py | 2 ++ djangocms_installer/django/__init__.py | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/djangocms_installer/config/__init__.py b/djangocms_installer/config/__init__.py index 82fb177..e710c17 100644 --- a/djangocms_installer/config/__init__.py +++ b/djangocms_installer/config/__init__.py @@ -84,6 +84,8 @@ def parse(args): default=False, help="Don't create the admin user") parser.add_argument('--template', dest='template', action='store', default=None, help="The path or URL to load the template from") + parser.add_argument('--extra-settings', dest='extra_settings', action='store', + default=None, help="The path to an file that contains extra settings.") args = parser.parse_args(args) diff --git a/djangocms_installer/django/__init__.py b/djangocms_installer/django/__init__.py index 310094a..3568612 100644 --- a/djangocms_installer/django/__init__.py +++ b/djangocms_installer/django/__init__.py @@ -73,6 +73,7 @@ def patch_settings(config_data): overridden_settings = ('MIDDLEWARE_CLASSES', 'INSTALLED_APPS', 'TEMPLATE_LOADERS', 'TEMPLATE_CONTEXT_PROCESSORS', 'TEMPLATE_DIRS', 'LANGUAGES') + extra_settings = '' if not os.path.exists(config_data.settings_path): sys.stdout.write("Error while creating target project, please check the given configuration") @@ -81,6 +82,11 @@ def patch_settings(config_data): with open(config_data.settings_path, 'r') as fd_original: original = fd_original.read() + # extra settings reading + if config_data.extra_settings and os.path.exists(config_data.extra_settings): + with open(config_data.extra_settings, 'r') as fd_extra: + extra_settings = fd_extra.read() + original = original.replace("# -*- coding: utf-8 -*-\n", "") if original.find('BASE_DIR') == -1: @@ -140,6 +146,8 @@ def patch_settings(config_data): original += "SITE_ID = 1\n\n" original += _build_settings(config_data) + # Append extra settings at the end of the file + original += ("\n" + extra_settings) with open(config_data.settings_path, "w") as fd_dest: fd_dest.write(original) From f19fa339eb576e49d78834009ca7d4597c441e4d Mon Sep 17 00:00:00 2001 From: Iacopo Spalletti Date: Sat, 8 Mar 2014 16:22:45 +0100 Subject: [PATCH 3/3] Add documentation for extra-settings parameter. --- docs/reference.rst | 2 ++ docs/usage.rst | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/docs/reference.rst b/docs/reference.rst index 2789fb4..d5ca034 100644 --- a/docs/reference.rst +++ b/docs/reference.rst @@ -59,6 +59,8 @@ advanced usage: * ``--list-plugins``, ``-P``: List plugins that's going to be installed and configured for the project; this will not alter the virtualenv or create the project; +* ``--extra-settings``: Path to a file with extra variables to append to generated settings file. It doesn't need to be + a Python file, its content is blindly copied in the project settings. .. _dj-database-url: https://github.com/kennethreitz/dj-database-url diff --git a/docs/usage.rst b/docs/usage.rst index 6f8e19a..d318c4a 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -57,6 +57,14 @@ This can be helpful to customize the virtualenv: See :ref:`arguments` for arguments reference +Custom settings +--------------- + +If want or need to provide custom settings **before** the initial database sync is run, use `--extra-settings` +parameter. +To use this option, pass the path to a file as argument: its content is going to be appended to the generated +settings file. + HOWTO -----