X-Git-Url: http://woldlab.caltech.edu/gitweb/?a=blobdiff_plain;f=htsworkflow%2Fsettings.py;h=ee1cb6a2a50a6a1489a46964fe8c9678625f0a20;hb=6d4095658be3e872dbfbb23f0a0b95eb7e396db9;hp=68dfcf90916f10a6578a7fd467618896854ae63a;hpb=51c342d45441249e1e70f8cb8825e0e06cd78895;p=htsworkflow.git diff --git a/htsworkflow/settings.py b/htsworkflow/settings.py index 68dfcf9..ee1cb6a 100644 --- a/htsworkflow/settings.py +++ b/htsworkflow/settings.py @@ -1,7 +1,7 @@ """ Generate settings for the Django Application. -To make it easier to customize the application the settings can be +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): @@ -9,8 +9,11 @@ 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 + database= + + [database_name] + engine=sqlite3 + name=/path/to/database [admins] #name1=email1 @@ -18,18 +21,24 @@ The options understood by this module are (with their defaults): [allowed_hosts] #name1=ip localhost=127.0.0.1 - + [allowed_analysis_hosts] #name1=ip localhost=127.0.0.1 """ import ConfigParser +import logging import os import shlex import htsworkflow +import django +from django.conf import global_settings + +from htsworkflow.util.api import make_django_secret_key HTSWORKFLOW_ROOT = os.path.abspath(os.path.split(htsworkflow.__file__)[0]) +LOGGER = logging.getLogger(__name__) # make epydoc happy __docformat__ = "restructuredtext en" @@ -41,7 +50,7 @@ def options_to_list(options, dest, section_name, option_name): if options.has_option(section_name, option_name): opt = options.get(section_name, option_name) dest.extend( shlex.split(opt) ) - + def options_to_dict(dest, section_name): """ Load a options from section_name and store in a dictionary @@ -51,23 +60,18 @@ def options_to_dict(dest, section_name): dest[name] = options.get(section_name, name) # define your defaults here -options = ConfigParser.SafeConfigParser( - { 'email_host': 'localhost', - 'email_port': '25', - 'database_engine': 'sqlite3', - 'database_name': - os.path.join(HTSWORKFLOW_ROOT, '..', 'fctracker.db'), - 'time_zone': 'America/Los_Angeles', - 'default_pm': '5', - 'link_flowcell_storage_device_url': "http://localhost:8000/inventory/lts/link/", - 'printer1_host': '127.0.0.1', - 'printer1_port': '9100', - 'printer2_host': '127.0.0.1', - 'printer2_port': '9100', - }) - -options.read([os.path.expanduser("~/.htsworkflow.ini"), - '/etc/htsworkflow.ini',]) +options = ConfigParser.SafeConfigParser() + +def save_options(filename, options): + try: + ini_stream = open(filename, 'w') + options.write(ini_stream) + ini_stream.close() + except IOError, e: + LOGGER.debug("Error saving setting: %s" % (str(e))) + +INI_FILE = options.read([os.path.expanduser("~/.htsworkflow.ini"), + '/etc/htsworkflow.ini',]) # OptionParser will use the dictionary passed into the config parser as # 'Default' values in any section. However it still needs an empty section @@ -89,14 +93,22 @@ options_to_list(options, ADMINS, 'frontend', 'admins') MANAGERS = [] options_to_list(options, MANAGERS, 'frontend', 'managers') -DEFAULT_PM=int(options.get('frontend', 'default_pm')) +if options.has_option('front', 'default_pm'): + DEFAULT_PM=int(options.get('frontend', 'default_pm')) +else: + DEFAULT_PM=5 -AUTHENTICATION_BACKENDS = ( +AUTHENTICATION_BACKENDS = ( 'htsworkflow.frontend.samples.auth_backend.HTSUserModelBackend', ) -CUSTOM_USER_MODEL = 'samples.HTSUser' +CUSTOM_USER_MODEL = 'samples.HTSUser' -EMAIL_HOST = options.get('frontend', 'email_host') -EMAIL_PORT = int(options.get('frontend', 'email_port')) +EMAIL_HOST='localhost' +if options.has_option('frontend', 'email_host'): + EMAIL_HOST = options.get('frontend', 'email_host') + +EMAIL_PORT = 25 +if options.has_option('frontend', 'email_port'): + EMAIL_PORT = int(options.get('frontend', 'email_port')) if options.has_option('frontend', 'notification_sender'): NOTIFICATION_SENDER = options.get('frontend', 'notification_sender') @@ -105,12 +117,16 @@ else: NOTIFICATION_BCC = [] options_to_list(options, NOTIFICATION_BCC, 'frontend', 'notification_bcc') -database_section = options.get('frontend', 'database', 'database') +if not options.has_option('frontend', 'database'): + raise ConfigParser.NoSectionError( + "Please define [frontend] database=
") + +database_section = options.get('frontend', 'database') if not options.has_section(database_section): raise ConfigParser.NoSectionError( "No database= defined") - + # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'ado_mssql'. DATABASE_ENGINE = options.get(database_section, 'engine') DATABASE_NAME = options.get(database_section, 'name') @@ -127,12 +143,22 @@ if options.has_option(database_section, 'password_file'): elif options.has_option(database_section, 'password'): DATABASE_PASSWORD = options.get(database_section, 'password') +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': DATABASE_NAME, + } +} + # Local time zone for this installation. Choices can be found here: # http://www.postgresql.org/docs/8.1/static/datetime-keywords.html#DATETIME-TIMEZONE-SET-TABLE # 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 = options.get('frontend', 'time_zone') +if options.has_option('frontend', 'time_zone'): + TIME_ZONE = options.get('frontend', 'time_zone') +else: + TIME_ZONE = 'America/Los_Angeles' # Language code for this installation. All choices can be found here: # http://www.w3.org/TR/REC-html40/struct/dirlang.html#langcodes @@ -153,31 +179,37 @@ MEDIA_ROOT = os.path.join(HTSWORKFLOW_ROOT, 'frontend', 'static', '') # Example: "http://media.lawrence.com" MEDIA_URL = '/static/' -# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a +# URL prefix for static media -- CSS, JavaScript and images. Make sure to use a # trailing slash. -# Examples: "http://foo.com/media/", "/media/". -ADMIN_MEDIA_PREFIX = '/media/' +STATIC_URL = '/media/' # Make this unique, and don't share it with anybody. -SECRET_KEY = '(ekv^=gf(j9f(x25@a7r+8)hqlz%&_1!tw^75l%^041#vi=@4n' +if not options.has_option('frontend', 'secret'): + options.set('frontend', 'secret_key', make_django_secret_key(458)) + save_options(INI_FILE[0], options) +SECRET_KEY = options.get('frontend', 'secret_key') # some of our urls need an api key DEFAULT_API_KEY = 'n7HsXGHIi0vp9j5u4TIRJyqAlXYc4wrH' # List of callables that know how to import templates from various sources. TEMPLATE_LOADERS = ( - 'django.template.loaders.filesystem.load_template_source', - 'django.template.loaders.app_directories.load_template_source', -# 'django.template.loaders.eggs.load_template_source', + 'django.template.loaders.filesystem.Loader', + 'django.template.loaders.app_directories.Loader', ) MIDDLEWARE_CLASSES = ( + 'django.middleware.csrf.CsrfViewMiddleware', 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.doc.XViewMiddleware', ) +TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS + ( + 'htsworkflow.frontend.thispage.thispage', +) ROOT_URLCONF = 'htsworkflow.frontend.urls' TEMPLATE_DIRS = ( @@ -186,13 +218,15 @@ TEMPLATE_DIRS = ( # Don't forget to use absolute paths, not relative paths. '/usr/share/python-support/python-django/django/contrib/admin/templates', #'/usr/lib/pymodules/python2.6/django/contrib/admin/templates/', - os.path.join(HTSWORKFLOW_ROOT, 'frontend','templates'), + os.path.join(HTSWORKFLOW_ROOT, 'frontend', 'templates'), + os.path.join(HTSWORKFLOW_ROOT, 'templates'), ) INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', + 'django.contrib.staticfiles', 'django.contrib.humanize', 'django.contrib.sessions', 'django.contrib.sites', @@ -200,11 +234,11 @@ INSTALLED_APPS = ( 'htsworkflow.frontend.samples', # modules from htsworkflow branch 'htsworkflow.frontend.experiments', - 'htsworkflow.frontend.analysis', + 'htsworkflow.frontend.analysis', 'htsworkflow.frontend.reports', 'htsworkflow.frontend.inventory', 'htsworkflow.frontend.bcmagic', - 'django.contrib.databrowse', + 'htsworkflow.frontend.labels', ) # Project specific settings @@ -224,11 +258,23 @@ if options.has_option('frontend', 'results_dir'): else: RESULT_HOME_DIR='/tmp' -LINK_FLOWCELL_STORAGE_DEVICE_URL = options.get('frontend', 'link_flowcell_storage_device_url') +if options.has_option('frontend', 'link_flowcell_storage_device_url'): + LINK_FLOWCELL_STORAGE_DEVICE_URL = options.get('frontend', + 'link_flowcell_storage_device_url') +else: + LINK_FLOWCELL_STORAGE_DEVICE_URL = None # PORT 9100 is default for Zebra tabletop/desktop printers # PORT 6101 is default for Zebra mobile printers -BCPRINTER_PRINTER1_HOST = options.get('bcprinter', 'printer1_host') -BCPRINTER_PRINTER1_PORT = int(options.get('bcprinter', 'printer1_port')) -BCPRINTER_PRINTER2_HOST = options.get('bcprinter', 'printer2_host') -BCPRINTER_PRINTER2_PORT = int(options.get('bcprinter', 'printer2_port')) +BCPRINTER_PRINTER1_HOST = None +if options.has_option('bcprinter', 'printer1_host'): + BCPRINTER_PRINTER1_HOST = options.get('bcprinter', 'printer1_host') +BCPRINTER_PRINTER1_PORT=9100 +if options.has_option('bcprinter', 'printer1_port'): + BCPRINTER_PRINTER1_PORT = int(options.get('bcprinter', 'printer1_port')) +BCPRINTER_PRINTER2_HOST = None +if options.has_option('bcprinter', 'printer2_host'): + BCPRINTER_PRINTER1_HOST = options.get('bcprinter', 'printer2_host') +BCPRINTER_PRINTER2_PORT=9100 +if options.has_option('bcprinter', 'printer2_port'): + BCPRINTER_PRINTER2_PORT = int(options.get('bcprinter', 'printer2_port'))