Skip to content

Commit

Permalink
Add extra settings file to provide common setting parameter. The sett…
Browse files Browse the repository at this point in the history
…ing in the former file will be appended to the generated file.
  • Loading branch information
yakky committed May 20, 2014
1 parent d9ef612 commit a3ca6c3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions djangocms_installer/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 8 additions & 0 deletions djangocms_installer/django/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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:
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a3ca6c3

Please sign in to comment.