From 369341218c6d351c85fba946aba5733ee3d331f6 Mon Sep 17 00:00:00 2001 From: Sergio Oliveira Date: Mon, 6 Oct 2014 20:15:50 -0300 Subject: [PATCH] Added command to generate basic configs --- colab/colab.template.yaml | 53 ----------------------------------------------------- colab/management/__init__.py | 7 +++++++ colab/management/initconfig.py | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ setup.py | 1 + 4 files changed, 80 insertions(+), 53 deletions(-) delete mode 100644 colab/colab.template.yaml create mode 100644 colab/management/initconfig.py diff --git a/colab/colab.template.yaml b/colab/colab.template.yaml deleted file mode 100644 index 13dbaaa..0000000 --- a/colab/colab.template.yaml +++ /dev/null @@ -1,53 +0,0 @@ - -DEBUG: false -TEMPLATE_DEBUG: false - -ADMINS: &admin - - - - John Foo - - john@example.com - - - - Mary Bar - - mary@example.com - -MANAGERS: *admin - -COLAB_FROM_ADDRESS: '"Colab" ' -SERVER_EMAIL: '"Colab" ' - -EMAIL_HOST: localhost -EMAIL_PORT: 25 -EMAIL_SUBJECT_PREFIX: '[colab]' - -SECRET_KEY: '{{ secret_key }}' - -SITE_URL: 'http://www.example.com/' - -ALLOWED_HOSTS: - - example.com - - example.org - - example.net - -CONVERSEJS_ENABLED: false - -CONVERSEJS_AUTO_REGISTER: 'xmpp.example.com' - -DATABASES: - default: - ENGINE: django.db.backends.postgresql_psycopg2 - HOST: localhost - NAME: colab - USER: colab - PASSWORD: colab - -ROBOTS_NOINDEX: false - -# Set to false to disable -RAVEN_DSN: 'http://public:secret@example.com/1' - -PROXIED_APPS: - gitlab: - upstream: 'http://localhost:8090/gitlab/' - trac: - upstream: 'http://localhost:5000/trac/' - diff --git a/colab/management/__init__.py b/colab/management/__init__.py index 10b913c..4cf47b4 100644 --- a/colab/management/__init__.py +++ b/colab/management/__init__.py @@ -1,7 +1,10 @@ import os + from django.core.management import ManagementUtility +from .initconfig import initconfig + def execute_from_command_line(argv=None): """ @@ -12,3 +15,7 @@ def execute_from_command_line(argv=None): utility = ManagementUtility(argv) utility.execute() + + +def run_colab_config(argv=None): + initconfig() diff --git a/colab/management/initconfig.py b/colab/management/initconfig.py new file mode 100644 index 0000000..a8c91c6 --- /dev/null +++ b/colab/management/initconfig.py @@ -0,0 +1,72 @@ + +from django.utils.crypto import get_random_string + + +CONFIG_TEMPLATE = """ + +## Set to false in production +DEBUG: true +TEMPLATE_DEBUG: true + +## System admins +ADMINS: &admin + - + - John Foo + - john@example.com + - + - Mary Bar + - mary@example.com + +MANAGERS: *admin + +COLAB_FROM_ADDRESS: '"Colab" ' +SERVER_EMAIL: '"Colab" ' + +EMAIL_HOST: localhost +EMAIL_PORT: 25 +EMAIL_SUBJECT_PREFIX: '[colab]' + +SECRET_KEY: '{secret_key}' + +SITE_URL: 'http://www.example.com/' + +ALLOWED_HOSTS: + - example.com + - example.org + - example.net + +### Uncomment to enable Converse.js +# CONVERSEJS_ENABLED: True + +### Uncomment to enable auto-registration +# CONVERSEJS_AUTO_REGISTER: 'xmpp.example.com' + +## Database settings +DATABASES: + default: + ENGINE: django.db.backends.postgresql_psycopg2 + HOST: localhost + NAME: colab + USER: colab + PASSWORD: colab + +## Disable indexing +ROBOTS_NOINDEX: false + +### Log errors to Sentry instance +# RAVEN_DSN: 'http://public:secret@example.com/1' + +### Colab proxied apps +# PROXIED_APPS: +# gitlab: +# upstream: 'http://localhost:8090/gitlab/' +# trac: +# upstream: 'http://localhost:5000/trac/' + +""" + + +def initconfig(): + chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)' + secret_key = get_random_string(50, chars) + print(CONFIG_TEMPLATE.format(secret_key=secret_key)) diff --git a/setup.py b/setup.py index 1a0cfb7..3c94cab 100644 --- a/setup.py +++ b/setup.py @@ -21,6 +21,7 @@ setup( include_package_data=True, entry_points={'console_scripts': [ 'colab-admin = colab.management:execute_from_command_line', + 'colab-init-config = colab.management:initconfig', ]}, zip_safe=False, long_description=open('README.rst').read(), -- libgit2 0.21.2