diff options
author | Nirbheek Chauhan <nirbheek.chauhan@gmail.com> | 2008-10-12 19:41:01 +0530 |
---|---|---|
committer | Nirbheek Chauhan <nirbheek.chauhan@gmail.com> | 2008-10-13 08:17:29 +0530 |
commit | 8fb6165ef1b079214aa0c0d29e60a2dcf0c499f2 (patch) | |
tree | 646b9d6d6a64271d63f55ca9a2ad7c0f8d05f23c /master | |
parent | Update TODO (diff) | |
download | autotua-8fb6165ef1b079214aa0c0d29e60a2dcf0c499f2.tar.gz autotua-8fb6165ef1b079214aa0c0d29e60a2dcf0c499f2.tar.bz2 autotua-8fb6165ef1b079214aa0c0d29e60a2dcf0c499f2.zip |
Improve merging of autotua settings in Django
* Instead of doing a circular import on "autotua_settings", manually do
a merge from "master.settings" (and any other django apps in the dir)
* Entries beginning with '_' and not all UPPERCASE are ignored.
Diffstat (limited to 'master')
-rw-r--r-- | master/custom/autotua_settings.py | 10 | ||||
-rw-r--r-- | master/custom/merge_settings.py | 18 | ||||
-rw-r--r-- | master/master/settings.py | 9 | ||||
-rwxr-xr-x | master/setup-master.py | 8 |
4 files changed, 32 insertions, 13 deletions
diff --git a/master/custom/autotua_settings.py b/master/custom/autotua_settings.py deleted file mode 100644 index 7bd2450..0000000 --- a/master/custom/autotua_settings.py +++ /dev/null @@ -1,10 +0,0 @@ -import os -from settings import * - -_cwd = os.path.dirname(__file__) - -MEDIA_PREFIX = '/site_media/' -TEMPLATE_DIRS += os.path.join(_cwd, 'master', 'templates').replace('\\', '/'), -INSTALLED_APPS += ('master',) -MEDIA_ROOT = os.path.join(_cwd, 'master', 'media').replace('\\', '/') -LOGIN_URL = '/login' diff --git a/master/custom/merge_settings.py b/master/custom/merge_settings.py new file mode 100644 index 0000000..469e8d5 --- /dev/null +++ b/master/custom/merge_settings.py @@ -0,0 +1,18 @@ +import os +# Import/merge settings from sub-modules +for file in os.listdir('.'): + if os.path.isdir(file): + try: + _settings = __import__(file, fromlist=['settings']).settings + except ImportError: + continue + for entry in dir(_settings): + action = '+=' + if entry[0] == '_' or not entry[0].isupper(): + continue + if not locals().has_key(entry): + action = '=' + value = getattr(_settings, entry) + if isinstance(value, str): + value = "'%s'" % value + exec("%s %s %s" % (entry, action, value)) diff --git a/master/master/settings.py b/master/master/settings.py new file mode 100644 index 0000000..e98a61f --- /dev/null +++ b/master/master/settings.py @@ -0,0 +1,9 @@ +import os + +_cwd = os.path.dirname(__file__) + +MEDIA_PREFIX = '/site_media/' +TEMPLATE_DIRS = os.path.join(_cwd, 'templates').replace('\\', '/'), +INSTALLED_APPS = ('master',) +MEDIA_ROOT = os.path.join(_cwd, 'media').replace('\\', '/') +LOGIN_URL = '/login' diff --git a/master/setup-master.py b/master/setup-master.py index 5be5803..6608bb1 100755 --- a/master/setup-master.py +++ b/master/setup-master.py @@ -52,18 +52,20 @@ def install_master(): management.call_command('startproject', DESTDIR) if SYMLINKS: os.symlink(cwd+'/master', DESTDIR+'/master') - for file in ['autotua_settings.py', 'urls.py']: + for file in ['urls.py']: dest_file = DESTDIR+'/'+file if os.path.isfile(dest_file): os.remove(dest_file) os.symlink(cwd+'/custom/'+file, dest_file) else: shutil.copytree(cwd+'/master', DESTDIR+'/master') - for file in ['autotua_settings.py', 'urls.py']: + for file in ['urls.py']: shutil.copy(cwd+'/custom/'+file, DESTDIR) settings = open(DESTDIR+'/settings.py', 'a') - settings.write('\nfrom autotua_settings import *\n') + master_settings = open(cwd+'/custom/merge_settings.py') + settings.write('\n'+master_settings.read()) settings.close() + master_settings.close() # Install icons icondir = os.path.abspath(cwd+'/icons') |