From 14c4bfed32e37169d40b108512b82522c92ad1b7 Mon Sep 17 00:00:00 2001 From: Joseph Curtin Date: Sat, 17 Dec 2011 19:06:16 -0500 Subject: [PATCH 1/9] added support to pull in all available commands rather the just runserver and runserver_plus --- djangoconfig/__init__.py | 1 + djangoconfig/deployment.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/djangoconfig/__init__.py b/djangoconfig/__init__.py index 8b7b179..7bb3849 100644 --- a/djangoconfig/__init__.py +++ b/djangoconfig/__init__.py @@ -1 +1,2 @@ +__version__ = '0.1.4' from djangoconfig.deployment import bootstrap, setup_environment \ No newline at end of file diff --git a/djangoconfig/deployment.py b/djangoconfig/deployment.py index ec33cb9..4628c8e 100644 --- a/djangoconfig/deployment.py +++ b/djangoconfig/deployment.py @@ -3,6 +3,8 @@ import sys import hashlib import getpass +from django.core.management import get_commands + def bootstrap_script(path, project_path_components): project_path = os.path.join(find_parent_path(path, project_path_components), *project_path_components) @@ -56,7 +58,7 @@ def setup_environment(path): CONFIG_IDENTIFIER = os.environ.get('CONFIG_IDENTIFIER', '') # If we are trying to use runserver, then look for existing configuration so that auto reload does not keep propmpting for the configuration file. - if len(sys.argv) >= 2 and sys.argv[1] in ('runserver', 'runserver_plus',): + if len(sys.argv) >= 2 and sys.argv[1] in get_commands().keys(): if 'CONFIG_IDENTIFIER' in os.environ and CONFIG_IDENTIFIER in [name for id, name in IDENTIFIERS]: bootstrap(path) return From 09b70293e1a2d0c94b18f27eea191dd6028fc818 Mon Sep 17 00:00:00 2001 From: Joseph Curtin Date: Sat, 17 Dec 2011 19:07:32 -0500 Subject: [PATCH 2/9] corrected version in setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 1afe703..101ec83 100755 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup -version = '0.1.3' +version = '0.1.4' setup( name='django-config', From 22adfef0a7eeb926cc50143579c5e5f1d96379bf Mon Sep 17 00:00:00 2001 From: Joey Curtin Date: Sun, 18 Dec 2011 18:36:24 -0500 Subject: [PATCH 3/9] added configuration file support to cache settings. --- djangoconfig/config.py | 54 ++++++++++++++++++++++++++++++++++++++ djangoconfig/deployment.py | 9 ++++--- 2 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 djangoconfig/config.py diff --git a/djangoconfig/config.py b/djangoconfig/config.py new file mode 100644 index 0000000..084ab21 --- /dev/null +++ b/djangoconfig/config.py @@ -0,0 +1,54 @@ +COMMAND_CACHE = 'command_cache' +AVAILABLE_COMMANDS = 'available_commands' + +CONFIG_IDENTIFIER = 'config_identifier' + +CACHE_DIR='config' +CACHE_NAME='django_config_cache.cfg' + +import ConfigParser +import os + + + +def get_config_identifier(path, default): + cache_dir = os.path.join(path, CACHE_DIR) + cache_file = os.path.abspath(os.path.join(cache_dir,CACHE_NAME)) + with open(cache_file,'rb') as configfile: + config = ConfigParser.ConfigParser() + config.readfp(configfile) + + if config.has_section(CONFIG_IDENTIFIER): + os.environ['CONFIG_IDENTIFIER'] = config.get(CONFIG_IDENTIFIER,CONFIG_IDENTIFIER) + return config.get(CONFIG_IDENTIFIER,CONFIG_IDENTIFIER) + + return default or '' + +def get_commands(path): + cache_dir = os.path.join(path, CACHE_DIR) + cache_file = os.path.abspath(os.path.join(cache_dir,CACHE_NAME)) + with open(cache_file,'rb') as configfile: + config = ConfigParser.ConfigParser() + config.readfp(configfile) + + if config.has_section(COMMAND_CACHE): + return config.get(COMMAND_CACHE,AVAILABLE_COMMANDS).split(',') + + return [] +def cache_commands(path): + from django.core.management import get_commands + cache_dir = os.path.join(path, CACHE_DIR) + cache_file = os.path.abspath(os.path.join(cache_dir,CACHE_NAME)) + # If dir dosen't exist, fail silently. + with open(cache_file,'r+wb') as configfile: + + config = ConfigParser.ConfigParser() + config.readfp(configfile) + configfile.seek(0) + + if not config.has_section(COMMAND_CACHE): + config.add_section(COMMAND_CACHE) + for command in get_commands().keys(): + config.set(COMMAND_CACHE,AVAILABLE_COMMANDS,','.join(get_commands().keys())) + + config.write(configfile) \ No newline at end of file diff --git a/djangoconfig/deployment.py b/djangoconfig/deployment.py index 4628c8e..9abe636 100644 --- a/djangoconfig/deployment.py +++ b/djangoconfig/deployment.py @@ -3,8 +3,7 @@ import sys import hashlib import getpass -from django.core.management import get_commands - +from djangoconfig.config import get_commands, cache_commands, get_config_identifier def bootstrap_script(path, project_path_components): project_path = os.path.join(find_parent_path(path, project_path_components), *project_path_components) @@ -21,6 +20,7 @@ def bootstrap(path): sys.exit(1) management.setup_environ(settings) + cache_commands(find_settings_path(path)) def find_settings_path(path): """Legacy support.""" @@ -55,10 +55,11 @@ def get_config_identifiers(path): def setup_environment(path): IDENTIFIERS = get_config_identifiers(path) - CONFIG_IDENTIFIER = os.environ.get('CONFIG_IDENTIFIER', '') + available_commands = get_commands(find_settings_path(path)) + CONFIG_IDENTIFIER = os.environ.get('CONFIG_IDENTIFIER', get_config_identifier(find_settings_path(path),'')) # If we are trying to use runserver, then look for existing configuration so that auto reload does not keep propmpting for the configuration file. - if len(sys.argv) >= 2 and sys.argv[1] in get_commands().keys(): + if len(sys.argv) >= 2 and sys.argv[1] in available_commands: if 'CONFIG_IDENTIFIER' in os.environ and CONFIG_IDENTIFIER in [name for id, name in IDENTIFIERS]: bootstrap(path) return From 2f9647387caec80cbb7e7d6146de1fd465dc1ff1 Mon Sep 17 00:00:00 2001 From: Joey Curtin Date: Sun, 18 Dec 2011 18:48:05 -0500 Subject: [PATCH 4/9] added config file docs --- docs/config.rst | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 docs/config.rst diff --git a/docs/config.rst b/docs/config.rst new file mode 100644 index 0000000..c4bd030 --- /dev/null +++ b/docs/config.rst @@ -0,0 +1,43 @@ +Available Settings: + +* command_cache +Section header for cache + +AVAILABLE_COMMANDS = 'available_commands' + +CONFIG_IDENTIFIER = 'config_identifier' + +CACHE_DIR='config' +CACHE_NAME='django_config_cache.cfg' + + +#### +CFG +#### +An architecture for maintaining multiple settings files in Django + +Purpose +======== +To cache the availble commands and allow for an easy file configuration rather. +Django config is ran before the django-env can be initalized, this file is here to define settings for django config. + + +Available Settings +================== +>> command_cache +>> config_identifier + +## Command Cache +>> [command_cache] +>> available_commands = runserver,shell,shell_plus +* Command Cache is a read only setting. + +## Config Identifier +>> [config_identifier] +>> config_identifier = monty + +Known Bugs +========== +1. File sturcture is moved around everytime an app is started. + + From ccf7ad1ab4bbd3316e523a5fa7dab2c44cff60d7 Mon Sep 17 00:00:00 2001 From: Joey Curtin Date: Sun, 18 Dec 2011 18:51:39 -0500 Subject: [PATCH 5/9] doc fix --- docs/config.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/config.rst b/docs/config.rst index c4bd030..4e02f34 100644 --- a/docs/config.rst +++ b/docs/config.rst @@ -24,17 +24,17 @@ Django config is ran before the django-env can be initalized, this file is here Available Settings ================== ->> command_cache ->> config_identifier +>>> command_cache +>>> config_identifier ## Command Cache ->> [command_cache] ->> available_commands = runserver,shell,shell_plus +>>> [command_cache] +>>> available_commands = runserver,shell,shell_plus * Command Cache is a read only setting. ## Config Identifier ->> [config_identifier] ->> config_identifier = monty +>>> [config_identifier] +>>> config_identifier = monty Known Bugs ========== From ba6846a12ff17b21e1dfe766fe1801ca2bccf817 Mon Sep 17 00:00:00 2001 From: Joey Curtin Date: Sun, 18 Dec 2011 18:54:14 -0500 Subject: [PATCH 6/9] doc fix --- docs/config.rst | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/config.rst b/docs/config.rst index 4e02f34..f0ff091 100644 --- a/docs/config.rst +++ b/docs/config.rst @@ -27,12 +27,16 @@ Available Settings >>> command_cache >>> config_identifier -## Command Cache +------------- +Command Cache +------------- >>> [command_cache] >>> available_commands = runserver,shell,shell_plus * Command Cache is a read only setting. -## Config Identifier +----------------- +Config Identifier +----------------- >>> [config_identifier] >>> config_identifier = monty From 82ec8654bf21dfbe6856d51a2242711372a135e1 Mon Sep 17 00:00:00 2001 From: Joey Curtin Date: Sun, 18 Dec 2011 18:54:48 -0500 Subject: [PATCH 7/9] doc fix --- docs/config.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/config.rst b/docs/config.rst index f0ff091..28e7501 100644 --- a/docs/config.rst +++ b/docs/config.rst @@ -30,9 +30,11 @@ Available Settings ------------- Command Cache ------------- +* Command Cache is a read only setting. + >>> [command_cache] >>> available_commands = runserver,shell,shell_plus -* Command Cache is a read only setting. + ----------------- Config Identifier From 9f8fe2f24f2484f8f0652e9612e2409ec0073871 Mon Sep 17 00:00:00 2001 From: Joey Curtin Date: Sun, 18 Dec 2011 18:55:47 -0500 Subject: [PATCH 8/9] version inc --- djangoconfig/__init__.py | 2 +- docs/config.rst | 2 +- setup.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/djangoconfig/__init__.py b/djangoconfig/__init__.py index 7bb3849..6ab42a7 100644 --- a/djangoconfig/__init__.py +++ b/djangoconfig/__init__.py @@ -1,2 +1,2 @@ -__version__ = '0.1.4' +__version__ = '0.1.5' from djangoconfig.deployment import bootstrap, setup_environment \ No newline at end of file diff --git a/docs/config.rst b/docs/config.rst index 28e7501..03220b5 100644 --- a/docs/config.rst +++ b/docs/config.rst @@ -18,7 +18,7 @@ An architecture for maintaining multiple settings files in Django Purpose ======== -To cache the availble commands and allow for an easy file configuration rather. +To cache the availble commands and allow for an easy file configuration. Django config is ran before the django-env can be initalized, this file is here to define settings for django config. diff --git a/setup.py b/setup.py index 101ec83..252e8ca 100755 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup -version = '0.1.4' +version = '0.1.5' setup( name='django-config', From 6afc8cf94f7a8d9299be3d446742b7da2f8f299e Mon Sep 17 00:00:00 2001 From: Joey Curtin Date: Sun, 18 Dec 2011 18:59:19 -0500 Subject: [PATCH 9/9] doc fix --- docs/config.rst | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/docs/config.rst b/docs/config.rst index 03220b5..a5db550 100644 --- a/docs/config.rst +++ b/docs/config.rst @@ -1,19 +1,6 @@ -Available Settings: - -* command_cache -Section header for cache - -AVAILABLE_COMMANDS = 'available_commands' - -CONFIG_IDENTIFIER = 'config_identifier' - -CACHE_DIR='config' -CACHE_NAME='django_config_cache.cfg' - - -#### -CFG -#### +###### +ConFiG +###### An architecture for maintaining multiple settings files in Django Purpose