From: Diane Trout Date: Tue, 7 Oct 2008 21:15:42 +0000 (+0000) Subject: I moved more of options in settings.py to the .htsworkflow.ini X-Git-Url: http://woldlab.caltech.edu/gitweb/?p=htsworkflow.git;a=commitdiff_plain;h=8ba413d357b85d3d0fa0e38f2a6c0f0375d0dc5a I moved more of options in settings.py to the .htsworkflow.ini In this case, the list of admin users were moved to a [admins] section in the ini file as well as the allowed_ips to [allowed_hosts] and allowed_analys_ips to [allowed_analysis_hosts]. Currently localhost is always allowed. --- diff --git a/htswfrontend/htswfrontend/settings.py b/htswfrontend/htswfrontend/settings.py index e48fb05..98a0ff3 100644 --- a/htswfrontend/htswfrontend/settings.py +++ b/htswfrontend/htswfrontend/settings.py @@ -1,14 +1,56 @@ -import ConfigParser +""" +Generate settings for the Django Application. + +To make it easier to customize the application the settings can be +defined in a configuration file read by ConfigParser. + +The options understood by this module are (with their defaults): + + [frontend] + email_host=localhost + email_port=25 + database_engine=sqlite3 + database_name=/path/to/db + + [admins] + #name1=email1 + [allowed_hosts] + #name1=ip + localhost=127.0.0.1 + + [allowed_analysis_hosts] + #name1=ip + localhost=127.0.0.1 + +""" +import ConfigParser import os +def options_to_list(dest, section_name): + """ + Load a options from section_name and store in a dictionary + """ + if options.has_section(section_name): + for name in options.options(section_name): + dest.append( options.get(section_name, name) ) + +def options_to_dict(dest, section_name): + """ + Load a options from section_name and store in a dictionary + """ + if options.has_section(section_name): + for name in options.options(section_name): + dest[name] = options.get(section_name, name) + # define your defaults here options = ConfigParser.SafeConfigParser( - { 'email_host': 'myerslab.stanford.edu', + { 'email_host': 'localhost', 'email_port': '25', 'database_engine': 'sqlite3', 'database_name': os.path.abspath('/htsworkflow/htswfrontend/dev_fctracker.db'), + 'time_zone': 'America/Los_Angeles', }) options.read([os.path.expanduser("~/.htsworkflow.ini"), @@ -19,9 +61,8 @@ options.read([os.path.expanduser("~/.htsworkflow.ini"), DEBUG = True TEMPLATE_DEBUG = DEBUG -ADMINS = ( - ('Rami Rauch', 'rrauch@stanford.edu'), -) +ADMINS = [] +options_to_list(ADMINS, 'admins') MANAGERS = ADMINS @@ -43,7 +84,7 @@ DATABASE_PORT = '' # Set to empty string for default. Not used with # although not all variations may be possible on all operating systems. # If running in a Windows environment this must be set to the same as your # system time zone. -TIME_ZONE = 'America/Los_Angeles' +TIME_ZONE = options.get('frontend', 'time_zone') # Language code for this installation. All choices can be found here: # http://www.w3.org/TR/REC-html40/struct/dirlang.html#langcodes @@ -109,8 +150,11 @@ INSTALLED_APPS = ( ) # Project specific settings -ALLOWED_IPS = {"74.51.115.100":"HudsonAlpha","64.89.97.100":"HudsonAlpha","127.0.0.1":"Localhost"} -ALLOWED_ANALYS_IPS = {"171.65.76.194":"Stanford Analysis 1","127.0.0.1":"Localhost"} +ALLOWED_IPS={'localhost': '127.0.0.1'} +options_to_dict(ALLOWED_IPS, 'allowed_hosts') + +ALLOWED_ANALYS_IPS = {'localhost': '127.0.0.1'} +options_to_dict(ALLOWED_ANALYS_IPS, 'allowed_analysis_hosts') #UPLOADTO_HOME = os.path.abspath('../../uploads') #UPLOADTO_CONFIG_FILE = os.path.join(UPLOADTO_HOME, 'eland_config') #UPLOADTO_ELAND_RESULT_PACKS = os.path.join(UPLOADTO_HOME, 'eland_results')