diff --git a/.gitignore b/.gitignore index f02594065d3a999ad2340e1c1216faf37710e9d2..d9a592e8541e1807eb6922a419f27257779afa0a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.swp *~ *.pyc +django-*.wsgi diff --git a/django-dev.wsgi b/django-dev.wsgi index 4b462e19b20bc13ccbf60f5e8bf7776313dc406a..37a3a156f9d0cbd46195672b3ab6150a0788c8bf 100644 --- a/django-dev.wsgi +++ b/django-dev.wsgi @@ -4,7 +4,7 @@ import sys # XXX The WSGI files should be unified. # Would be easy if settings.py were unified, which isn't hard. -os.environ['DJANGO_SETTINGS_MODULE'] = 'gracedb.settings_dev' +os.environ['DJANGO_SETTINGS_MODULE'] = 'gracedb.settings' sys.path.append('/home/bmoe/sandbox/lib/python2.6/site-packages') sys.path.append('/home/bmoe/sandbox/lib/python2.6') diff --git a/django.wsgi b/django.wsgi index 0250c62da29defbb8854151399754bb4acd7a5f4..605746ab38526e51bd830cbf170f0e4026e13dd7 100644 --- a/django.wsgi +++ b/django.wsgi @@ -1,11 +1,13 @@ import os import sys -# XXX The WSGI files should be unified. -# Would be easy if settings.py were unified, which isn't hard. - os.environ['DJANGO_SETTINGS_MODULE'] = 'gracedb.settings' +# Sandbox libs here, if required. +# +#sys.path.append('/home/bmoe/sandbox/lib/python2.6/site-packages') +#sys.path.append('/home/bmoe/sandbox/lib/python2.6') + import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler() diff --git a/doc/CHANGES b/doc/CHANGES index 411e9c8418f9dd90464eea8ca80452f5ecdc51c0..1f3eabb4df3d6a73ee013a8fba1d70d773b5ab9f 100644 --- a/doc/CHANGES +++ b/doc/CHANGES @@ -1,3 +1,17 @@ +================================================================== +ER2 + + settings refactor + More unified settings/config. + settings/__init__.py + locates and imports * from settings.default then settings.WHATEVER + settings/defaut.py + /production.py + /development.py + /misc.py + + Simple enough and gets rid of settings_dev crap. + Keeps prod/dev configs from diverging too much. ================================================================== Branch goocharts diff --git a/manage_dev.py b/manage_dev.py deleted file mode 100755 index e935d64855141dfe4a368e0a2a1adaadd3a56c46..0000000000000000000000000000000000000000 --- a/manage_dev.py +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env python -from django.core.management import execute_manager - -# THIS IS TERRIBLE, but some idiot named the project AND application gracedb. -# Things looking for gracedb.settings fail because they find the app not the proj. -# This also causes things wanting the app having to do gracedb.gracedb.whatever -# all the time, but that mess has already been made. -import sys, os -sys.path.insert(0, os.path.join(os.path.dirname(__file__),'..')) - -try: - import settings_dev as settings # Assumed to be in the same directory. -except ImportError: - import sys - sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__) - sys.exit(1) - -if __name__ == "__main__": - execute_manager(settings) diff --git a/middleware/debug.py b/middleware/debug.py new file mode 100644 index 0000000000000000000000000000000000000000..b1379cc8aa4cee10481575986764a81b995a26ea --- /dev/null +++ b/middleware/debug.py @@ -0,0 +1,7 @@ + +from django.conf import settings + +def LigoDebugContext(request): + if settings.DEBUG and settings.DEBUG != "PRODUCTION": + return { 'config_name' : settings.CONFIG_NAME } + return {} diff --git a/settings/__init__.py b/settings/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..62596fd562c4fec9cda10c5e0219ab347e6e05bc --- /dev/null +++ b/settings/__init__.py @@ -0,0 +1,36 @@ + +# Django settings for gracedb project. + +try: + # Workaround for a bug + # http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=473584 + # http://bugs.python.org/setuptools/issue36 + # import MySQLdb followed by import pkg_resources complains + # /usr/lib/python2.6/dist-packages/pytz/__init__.py:32: UserWarning: Module _mysql was already imported from /usr/lib/pymodules/python2.6/_mysql.so, but /usr/lib/pymodules/python2.6 is being added to sys.path + import pkg_resources +except: + pass + +import os +ROOT_PATH = os.path.abspath( os.path.join( os.path.dirname(__file__), os.pardir ) ) + +configs = { + '/home/bmoe/ER2': 'development_er2', + '/home/bmoe/er2box/lib/python2.6/site-packages/gracedb' : 'development_er2', + '/home/bmoe/gracedb': 'development', + '/home/gracedb/gracedb': 'production', +} + + +from default import * + +config = configs.get(ROOT_PATH, "NO_CONFIG") + +settings_module = __import__('%s' % config, globals(), locals(), 'gracedb') + +# Load the config settings properties into the local scope. +for setting in dir(settings_module): + if setting == setting.upper(): + locals()[setting] = getattr(settings_module, setting) + + diff --git a/settings.py b/settings/default.py similarity index 73% rename from settings.py rename to settings/default.py index 13ca03bc0d77ea36f99eb21cc3c0fede4552f70c..a4a9f3e8908a601656e0debda13b6a45becddc67 100644 --- a/settings.py +++ b/settings/default.py @@ -1,15 +1,5 @@ -# Django settings for gracedb project. -import os - -try: - # Workaround for a bug - # http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=473584 - # http://bugs.python.org/setuptools/issue36 - # import MySQLdb followed by import pkg_resources complains - # /usr/lib/python2.6/dist-packages/pytz/__init__.py:32: UserWarning: Module _mysql was already imported from /usr/lib/pymodules/python2.6/_mysql.so, but /usr/lib/pymodules/python2.6 is being added to sys.path - import pkg_resources -except: - pass + +# Suitable for production DEBUG = False TEMPLATE_DEBUG = DEBUG @@ -18,7 +8,6 @@ EMAIL_HOST = 'gravity.phys.uwm.edu' ADMINS = ( ('Brian Moe', 'bmoe@gravity.phys.uwm.edu'), -# ('Larry Price', 'larry@gravity.phys.uwm.edu'), ) MANAGERS = ADMINS @@ -28,14 +17,10 @@ ALERT_EMAIL_TO = [ "gracedb@listserv.ligo.org", ] ALERT_EMAIL_BCC = [ -# "Frederique Marion <marionf@lapp.in2p3.fr>", -# "Benoit MOURS <mours@lapp.in2p3.fr>", -# "Jonah Kanner <jkanner@umd.edu>", ] ALERT_TEST_EMAIL_FROM = "GraCEDb TEST <gracedb@ligo.org>" ALERT_TEST_EMAIL_TO = [ -# "bmoe@gravity.phys.uwm.edu", ] XMPP_ALERT_CHANNELS = [ @@ -76,34 +61,36 @@ LATENCY_MAXIMUM_CHARTED = 1800 LATENCY_REPORT_WEB_PAGE_FILE_PATH = LATENCY_REPORT_DEST_DIR + "/latency.inc" -# CBC IFAR Reports - -from utils import posixToGpsTime -from datetime import datetime, timedelta -import time - -now = datetime.now() -yesterday = now - timedelta(days=1) -lastweek = now - timedelta(days=7) -now = posixToGpsTime(time.mktime(now.timetuple())) -yesterday = posixToGpsTime(time.mktime(yesterday.timetuple())) -lastweek = posixToGpsTime(time.mktime(lastweek.timetuple())) - -REPORT_IFAR_IMAGE_DIR = LATENCY_REPORT_DEST_DIR -REPORTS_IFAR = [ - #(query, axis_label, title, fname) - ("LowMass %d..%d" % (yesterday, now), - "GraceDB CBC LowMass ER1 events", - "ER1 FARs from gstlal_ll_inspiral - last day", - "ifar_day.png" - ), - ("LowMass %d..%d" % (lastweek, now), - "GraceDB CBC LowMass ER1 events", - "ER1 FARs from gstlal_ll_inspiral - last week", - "ifar_week.png" - ), -] +# Find another way to do this. +# +## CBC IFAR Reports +# +#from gracedb.utils import posixToGpsTime +#from datetime import datetime, timedelta +#import time +# +#now = datetime.now() +#yesterday = now - timedelta(days=1) +#lastweek = now - timedelta(days=7) +#now = posixToGpsTime(time.mktime(now.timetuple())) +#yesterday = posixToGpsTime(time.mktime(yesterday.timetuple())) +#lastweek = posixToGpsTime(time.mktime(lastweek.timetuple())) +# +#REPORT_IFAR_IMAGE_DIR = LATENCY_REPORT_DEST_DIR +#REPORTS_IFAR = [ +# #(query, axis_label, title, fname), +# ("LowMass %d..%d" % (yesterday, now), +# "GraceDB CBC LowMass ER1 events", +# "ER1 FARs from gstlal_ll_inspiral - last day", +# "ifar_day.png" +# ), +# ("LowMass %d..%d" % (lastweek, now), +# "GraceDB CBC LowMass ER1 events", +# "ER1 FARs from gstlal_ll_inspiral - last week", +# "ifar_week.png" +# ), +#] # RSS Feed Defaults @@ -122,11 +109,11 @@ GRACE_DATETIME_FORMAT = 'Y-m-d H:i:s T' # http://www.i18nguy.com/unicode/language-identifiers.html LANGUAGE_CODE = 'en-us' -SITE_ID = 3 +SITE_ID = 1 # If you set this to False, Django will make some optimizations so as not # to load the internationalization machinery. -USE_I18N = True +USE_I18N = False # Absolute path to the directory that holds media. # Example: "/home/media/media.lawrence.com/" @@ -163,18 +150,19 @@ TEMPLATE_CONTEXT_PROCESSORS = ( "django.core.context_processors.media", "django.core.context_processors.request", "gracedb.middleware.auth.LigoAuthContext", + 'gracedb.middleware.debug.LigoDebugContext', ) AUTHENTICATION_BACKENDS = ('gracedb.middleware.auth.LigoAuthBackend',) -MIDDLEWARE_CLASSES = ( +MIDDLEWARE_CLASSES = [ 'gracedb.middleware.accept.AcceptMiddleware', 'gracedb.middleware.auth.LigoAuthMiddleware', 'gracedb.middleware.cli.CliExceptionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', -) +] ROOT_URLCONF = 'gracedb.urls' diff --git a/settings/development.py b/settings/development.py new file mode 100644 index 0000000000000000000000000000000000000000..cdcd076049b4319a8914899c033b8d6b9c488d94 --- /dev/null +++ b/settings/development.py @@ -0,0 +1,40 @@ + +CONFIG_NAME = "DEVELOPMENT" + +DEBUG = True +TEMPLATE_DEBUG = DEBUG + + +ALERT_EMAIL_FROM = "Dev Alert <root@moe.phys.uwm.edu>" +ALERT_EMAIL_TO = [ + "Brian Moe <bmoe@gravity.phys.uwm.edu>", + ] +ALERT_EMAIL_BCC = ["bmoe@uwm.edu"] + +ALERT_TEST_EMAIL_FROM = "Dev Test Alert <root@moe.phys.uwm.edu>" +ALERT_TEST_EMAIL_TO = [ + "Brian Moe <bmoe@gravity.phys.uwm.edu>", + ] + +# Don't sent out non-test XMPP alerts on dev box! +XMPP_ALERT_CHANNELS = [ + 'test_omega', + 'test_mbtaonline', + 'test_cwb', + 'test_lowmass', + ] + +# SkyAlert +SKYALERT_IVORN_PATTERN = "ivo://ligo.org/gracedb#%s-dev" + +# Latency histograms. Where they go and max latency to bin. +LATENCY_REPORT_DEST_DIR = "/home/bmoe/data/latency" + +SITE_ID = 4 + +TEMPLATE_DIRS = ( + # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". + # Always use forward slashes, even on Windows. + # Don't forget to use absolute paths, not relative paths. + "/home/bmoe/gracedb/templates", +) diff --git a/settings/development_er2.py b/settings/development_er2.py new file mode 100644 index 0000000000000000000000000000000000000000..d4a5543b2cc73304e69b429be7809365b5916810 --- /dev/null +++ b/settings/development_er2.py @@ -0,0 +1,46 @@ + + +CONFIG_NAME = "ER2" + +DEBUG = True +TEMPLATE_DEBUG = DEBUG + +DATABASES = { + 'default' : { + 'NAME' : 'er2', + 'ENGINE' : 'django.db.backends.mysql', + 'USER' : 'gracedb', + 'PASSWORD' : 'weasel', + } +} + +ALERT_EMAIL_FROM = "Dev Alert <root@moe.phys.uwm.edu>" +ALERT_EMAIL_TO = [ + "Brian Moe <bmoe@gravity.phys.uwm.edu>", + ] +ALERT_EMAIL_BCC = ["bmoe@uwm.edu"] + +ALERT_TEST_EMAIL_FROM = "Dev Test Alert <root@moe.phys.uwm.edu>" +ALERT_TEST_EMAIL_TO = [ + "Brian Moe <bmoe@gravity.phys.uwm.edu>", + ] + +XMPP_ALERT_CHANNELS = [ + ] + +# SkyAlert +SKYALERT_IVORN_PATTERN = "ivo://ligo.org/gracedb#%s-dev-er2" + +# Latency histograms. Where they go and max latency to bin. +LATENCY_REPORT_DEST_DIR = "/home/bmoe/data/latency" + +SITE_ID = 4 + +TEMPLATE_DIRS = ( + # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". + # Always use forward slashes, even on Windows. + # Don't forget to use absolute paths, not relative paths. + "/home/bmoe/ER2/templates", +) + + diff --git a/settings/production.py b/settings/production.py new file mode 100644 index 0000000000000000000000000000000000000000..9738870b9656c1ceb33b6b2182e92394b440234d --- /dev/null +++ b/settings/production.py @@ -0,0 +1,4 @@ + +CONFIG_NAME = "PRODUCTION" + +SITE_ID = 3 diff --git a/settings_dev.py b/settings_dev.py deleted file mode 100644 index c0bece276522b8fa465eaf7df76ee0aeb6303043..0000000000000000000000000000000000000000 --- a/settings_dev.py +++ /dev/null @@ -1,185 +0,0 @@ -# Django settings for gracedb project. - -try: - # Workaround for a bug - # http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=473584 - # http://bugs.python.org/setuptools/issue36 - # import MySQLdb followed by import pkg_resources complains - # /usr/lib/python2.6/dist-packages/pytz/__init__.py:32: UserWarning: Module _mysql was already imported from /usr/lib/pymodules/python2.6/_mysql.so, but /usr/lib/pymodules/python2.6 is being added to sys.path - import pkg_resources -except: - pass - - -DEBUG = True -TEMPLATE_DEBUG = DEBUG - -ADMINS = ( - ('Brian Moe', 'bmoe@gravity.phys.uwm.edu'), -) - -MANAGERS = ADMINS - -ALERT_EMAIL_FROM = "Dev Alert <root@moe.phys.uwm.edu>" -ALERT_EMAIL_TO = [ - "Brian Moe <bmoe@gravity.phys.uwm.edu>", - ] -ALERT_EMAIL_BCC = ["bmoe@uwm.edu"] - -ALERT_TEST_EMAIL_FROM = "Dev Test Alert <root@moe.phys.uwm.edu>" -ALERT_TEST_EMAIL_TO = [ - "Brian Moe <bmoe@gravity.phys.uwm.edu>", - ] - -# Don't sent out non-test XMPP alerts on dev box! -XMPP_ALERT_CHANNELS = [ - 'test_omega', - 'test_mbtaonline', - 'test_cwb', - 'test_lowmass', - ] - -DATABASES = { - 'default' : { - 'NAME' : 'gracedb', - 'ENGINE' : 'django.db.backends.mysql', - 'USER' : 'gracedb', - 'PASSWORD' : 'redrum4x', - } -} - -# SkyAlert - -SKYALERT_IVORN_PATTERN = "ivo://ligo.org/gracedb#%s-dev" -SKYALERT_ROLE = "test" -SKYALERT_DESCRIPTION = "LIGO / Virgo trigger" -SKYALERT_SUBMITTERS = ['Patrick Brady', 'Brian Moe'] - - -GRACEDB_DATA_DIR = "/mnt/gracedb-web/data" -#GRACEDB_DATA_DIR = "/mnt/gracedb-web-temp/data" - -# Latency histograms. Where they go and max latency to bin. -LATENCY_REPORT_DEST_DIR = "/home/bmoe/data/latency" -LATENCY_MAXIMUM_CHARTED = 1800 -LATENCY_REPORT_WEB_PAGE_FILE_PATH = LATENCY_REPORT_DEST_DIR + "/latency.inc" - - - -# CBC IFAR Reports - -from utils import posixToGpsTime -from datetime import datetime, timedelta -import time - -now = datetime.now() -yesterday = now - timedelta(days=1) -lastweek = now - timedelta(days=7) -now = posixToGpsTime(time.mktime(now.timetuple())) -yesterday = posixToGpsTime(time.mktime(yesterday.timetuple())) -lastweek = posixToGpsTime(time.mktime(lastweek.timetuple())) - -REPORT_IFAR_IMAGE_DIR = LATENCY_REPORT_DEST_DIR -REPORTS_IFAR = [ - #(query, axis_label, title, fname), - ("LowMass %d..%d" % (yesterday, now), - "GraceDB CBC LowMass ER1 events", - "ER1 FARs from gstlal_ll_inspiral - last day", - "ifar_day.png" - ), - ("LowMass %d..%d" % (lastweek, now), - "GraceDB CBC LowMass ER1 events", - "ER1 FARs from gstlal_ll_inspiral - last week", - "ifar_week.png" - ), -] - - -# RSS Feed Defaults -FEED_MAX_RESULTS = 50 - -# Local time zone for this installation. Choices can be found here: -# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name -# although not all choices may be available 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/Chicago' -GRACE_DATETIME_FORMAT = 'Y-m-d H:i:s T' - -# Language code for this installation. All choices can be found here: -# http://www.i18nguy.com/unicode/language-identifiers.html -LANGUAGE_CODE = 'en-us' - -SITE_ID = 4 - -# If you set this to False, Django will make some optimizations so as not -# to load the internationalization machinery. -USE_I18N = True - -# Absolute path to the directory that holds media. -# Example: "/home/media/media.lawrence.com/" -MEDIA_ROOT = '' - -# URL that handles the media served from MEDIA_ROOT. Make sure to use a -# trailing slash if there is a path component (optional in other cases). -# Examples: "http://media.lawrence.com", "http://example.com/media/" -MEDIA_URL = '/gracedb-static/' - -# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a -# trailing slash. -# Examples: "http://foo.com/media/", "/media/". -ADMIN_MEDIA_PREFIX = '/media/' - -# Make this unique, and don't share it with anybody. -SECRET_KEY = '$$&hl%^_4&s0k7sbdr8ll_^gkz-j8oab0tz$t^^b-%$!83d(av' - -# List of callables that know how to import templates from various sources. -TEMPLATE_LOADERS = ( - #'django.template.loaders.filesystem.load_template_source', - # replaced by... - 'django.template.loaders.filesystem.Loader', - 'django.template.loaders.app_directories.load_template_source', -# 'django.template.loaders.eggs.load_template_source', -) - -TEMPLATE_CONTEXT_PROCESSORS = ( - #"django.core.context_processors.auth", - # replaced by... - "django.contrib.auth.context_processors.auth", - "django.core.context_processors.debug", - "django.core.context_processors.i18n", - "django.core.context_processors.media", - "django.core.context_processors.request", - "gracedb.middleware.auth.LigoAuthContext", -) - -AUTHENTICATION_BACKENDS = ('gracedb.middleware.auth.LigoAuthBackend',) - -MIDDLEWARE_CLASSES = ( - 'gracedb.middleware.accept.AcceptMiddleware', - 'gracedb.middleware.auth.LigoAuthMiddleware', - 'gracedb.middleware.cli.CliExceptionMiddleware', - 'django.middleware.common.CommonMiddleware', - 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', -) - -ROOT_URLCONF = 'gracedb.urls' - -TEMPLATE_DIRS = ( - # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". - # Always use forward slashes, even on Windows. - # Don't forget to use absolute paths, not relative paths. - "/home/bmoe/gracedb/templates", -) - -INSTALLED_APPS = ( - 'django.contrib.auth', - 'django.contrib.admin', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.sites', - 'gracedb.gracedb', - 'gracedb.userprofile', -) diff --git a/templates/base.html b/templates/base.html index 32b3cbbe5e44b8177956e3e3d495fd973f1fd57e..df80171f9508abd62b75675cb4b4275555bd3f6f 100644 --- a/templates/base.html +++ b/templates/base.html @@ -38,6 +38,13 @@ function changeTime(obj, label) { <li id="nav-userprofile"><a href="{% url userprofile-home %}">Options</a></li> {% if ligouser %}<li id="nav-user">Authenticated as: {{ ligouser.name }}</li>{% endif %} </ul> +<center> + {% if config_name %} + <h1 style="color: red;"> + {{config_name}} + </h1> + {% endif %} +</center> {% endblock %} <p> </p> <!-- bad way to create vertical space -->