Package omeroweb :: Module settings
[hide private]
[frames] | no frames]

Source Code for Module omeroweb.settings

  1  #!/usr/bin/env python 
  2  #  
  3  # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #  
  4  # #                Django settings for OMERO.web project.               # #  
  5  # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
  6  #  
  7  #  
  8  # Copyright (c) 2008 University of Dundee.  
  9  #  
 10  # This program is free software: you can redistribute it and/or modify 
 11  # it under the terms of the GNU Affero General Public License as 
 12  # published by the Free Software Foundation, either version 3 of the 
 13  # License, or (at your option) any later version. 
 14  #  
 15  # This program is distributed in the hope that it will be useful, 
 16  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 17  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 18  # GNU Affero General Public License for more details. 
 19  #  
 20  # You should have received a copy of the GNU Affero General Public License 
 21  # along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 22  #  
 23  # Author: Aleksandra Tarkowska <A(dot)Tarkowska(at)dundee(dot)ac(dot)uk>, 2008. 
 24  #  
 25  # Version: 1.0 
 26  # 
 27   
 28  import os.path 
 29  import sys 
 30  import datetime 
 31  import logging 
 32  import omero 
 33  import omero.config 
 34  import omero.clients 
 35  import tempfile 
 36  import exceptions 
 37   
 38  from webadmin.custom_models import ServerObjects 
 39  from django.utils import simplejson as json 
 40  from portalocker import LockException 
 41   
 42  # LOGS 
 43  # NEVER DEPLOY a site into production with DEBUG turned on. 
 44  # Debuging mode. 
 45  # A boolean that turns on/off debug mode. 
 46  # handler404 and handler500 works only when False 
 47  if os.environ.has_key('OMERO_HOME'): 
 48      OMERO_HOME =os.environ.get('OMERO_HOME')  
 49  else: 
 50      OMERO_HOME = os.path.join(os.path.dirname(__file__), '..', '..', '..') 
 51      OMERO_HOME = os.path.normpath(OMERO_HOME) 
 52   
 53  LOGFILE = ('OMEROweb.log') 
 54  LOGLEVEL = logging.INFO 
 55  LOGDIR = os.path.join(OMERO_HOME, 'var', 'log').replace('\\','/') 
 56   
 57  if not os.path.isdir(LOGDIR): 
 58      try: 
 59          os.makedirs(LOGDIR) 
 60      except Exception, x: 
 61          exctype, value = sys.exc_info()[:2] 
 62          raise exctype, value 
 63   
 64  import logconfig 
 65  logger = logconfig.get_logger(os.path.join(LOGDIR, LOGFILE), LOGLEVEL) 
 66   
 67  # Load custom settings from etc/grid/config.xml 
 68  # Tue  2 Nov 2010 11:03:18 GMT -- ticket:3228 
 69  from omero.util.concurrency import get_event 
 70  CONFIG_XML = os.path.join(OMERO_HOME, 'etc', 'grid', 'config.xml') 
 71  count = 10 
 72  event = get_event("websettings") 
 73   
 74  while True: 
 75      try: 
 76          CONFIG_XML = omero.config.ConfigXml(CONFIG_XML) 
 77          CUSTOM_SETTINGS = CONFIG_XML.as_map() 
 78          CONFIG_XML.close() 
 79          break 
 80      except LockException: 
 81          logger.error("Exception while loading configuration retrying...", exc_info=True) 
 82          count -= 1 
 83          if not count: 
 84              raise 
 85          else: 
 86              event.wait(1) # Wait a total of 10 seconds 
 87      except: 
 88          logger.error("Exception while loading configuration...", exc_info=True) 
 89          raise 
 90   
 91  del event 
 92  del count 
 93  del get_event 
 94   
 95  FASTCGI = "fastcgi" 
 96  FASTCGITCP = "fastcgi-tcp" 
 97  FASTCGI_TYPES = (FASTCGI, FASTCGITCP) 
 98  DEVELOPMENT = "development" 
 99  DEFAULT_SERVER_TYPE = FASTCGITCP 
100  ALL_SERVER_TYPES = (FASTCGITCP, FASTCGI, DEVELOPMENT) 
101   
102  DEFAULT_SESSION_ENGINE = 'django.contrib.sessions.backends.file' 
103  SESSION_ENGINE_VALUES = ('django.contrib.sessions.backends.db', 
104                           'django.contrib.sessions.backends.file', 
105                           'django.contrib.sessions.backends.cache', 
106                           'django.contrib.sessions.backends.cached_db') 
107   
108 -def parse_boolean(s):
109 s = s.strip().lower() 110 if s in ('true', '1', 't'): 111 return True 112 return False
113
114 -def parse_paths(s):
115 return [os.path.normpath(path) for path in json.loads(s)]
116
117 -def check_server_type(s):
118 if s not in ALL_SERVER_TYPES: 119 raise ValueError("Unknown server type: %s. Valid values are: %s" % (s, ALL_SERVER_TYPES)) 120 return s
121
122 -def check_session_engine(s):
123 if s not in SESSION_ENGINE_VALUES: 124 raise ValueError("Unknown session engine: %s. Valid values are: %s" % (s, SESSION_ENGINE_VALUES)) 125 return s
126
127 -def identity(x):
128 return x
129
130 -def remove_slash(s):
131 if s is not None and len(s) > 0: 132 if s.endswith("/"): 133 s = s[:-1] 134 return s
135
136 -class LeaveUnset(exceptions.Exception):
137 pass
138
139 -def leave_none_unset(s):
140 if s is None: 141 raise LeaveUnset() 142 return s
143 144 CUSTOM_SETTINGS_MAPPINGS = { 145 "omero.web.public.user": ["PUBLIC_USER", None, leave_none_unset], 146 "omero.web.public.password": ["PUBLIC_PASSWORD", None, leave_none_unset], 147 "omero.web.database_engine": ["DATABASE_ENGINE", None, leave_none_unset], 148 "omero.web.database_host": ["DATABASE_HOST", None, leave_none_unset], 149 "omero.web.database_name": ["DATABASE_NAME", None, leave_none_unset], 150 "omero.web.database_password": ["DATABASE_PASSWORD", None, leave_none_unset], 151 "omero.web.database_port": ["DATABASE_PORT", None, leave_none_unset], 152 "omero.web.database_user": ["DATABASE_USER", None, leave_none_unset], 153 "omero.web.admins": ["ADMINS", '[]', json.loads], 154 "omero.web.application_host": ["APPLICATION_HOST", "http://localhost:4080", remove_slash], 155 "omero.web.application_server": ["APPLICATION_SERVER", DEFAULT_SERVER_TYPE, check_server_type], 156 "omero.web.application_server.host": ["APPLICATION_SERVER_HOST", "0.0.0.0", str], 157 "omero.web.application_server.port": ["APPLICATION_SERVER_PORT", "4080", str], 158 "omero.web.cache_backend": ["CACHE_BACKEND", None, leave_none_unset], 159 "omero.web.webgateway_cache": ["WEBGATEWAY_CACHE", None, leave_none_unset], 160 "omero.web.session_engine": ["SESSION_ENGINE", DEFAULT_SESSION_ENGINE, check_session_engine], 161 "omero.web.debug": ["DEBUG", "false", parse_boolean], 162 "omero.web.email_host": ["EMAIL_HOST", None, identity], 163 "omero.web.email_host_password": ["EMAIL_HOST_PASSWORD", None, identity], 164 "omero.web.email_host_user": ["EMAIL_HOST_USER", None, identity], 165 "omero.web.email_port": ["EMAIL_PORT", None, identity], 166 "omero.web.email_subject_prefix": ["EMAIL_SUBJECT_PREFIX", "[OMERO.web] ", str], 167 "omero.web.email_use_tls": ["EMAIL_USE_TLS", "false", parse_boolean], 168 "omero.web.logdir": ["LOGDIR", LOGDIR, str], 169 "omero.web.send_broken_link_emails": ["SEND_BROKEN_LINK_EMAILS", "true", parse_boolean], 170 "omero.web.server_email": ["SERVER_EMAIL", None, identity], 171 "omero.web.server_list": ["SERVER_LIST", '[["localhost", 4064, "omero"]]', json.loads], 172 "omero.web.use_eman2": ["USE_EMAN2", "false", parse_boolean], 173 # the following parameters configure when to show/hide the 'Volume viewer' icon in the Image metadata panel 174 "omero.web.open_astex_max_side": ["OPEN_ASTEX_MAX_SIDE", 400, int], 175 "omero.web.open_astex_min_side": ["OPEN_ASTEX_MIN_SIDE", 20, int], 176 "omero.web.open_astex_max_voxels": ["OPEN_ASTEX_MAX_VOXELS", 27000000, int], # 300 x 300 x 300 177 178 "omero.web.scripts_to_ignore": ["SCRIPTS_TO_IGNORE", '["/omero/figure_scripts/Movie_Figure.py", "/omero/figure_scripts/Split_View_Figure.py", "/omero/figure_scripts/Thumbnail_Figure.py", "/omero/figure_scripts/ROI_Split_Figure.py", "/omero/export_scripts/Make_Movie.py"]', parse_paths], 179 } 180 181 for key, values in CUSTOM_SETTINGS_MAPPINGS.items(): 182 183 global_name, default_value, mapping = values 184 185 try: 186 global_value = CUSTOM_SETTINGS[key] 187 values.append(False) 188 except KeyError: 189 global_value = default_value 190 values.append(True) 191 192 try: 193 globals()[global_name] = mapping(global_value) 194 except ValueError: 195 raise ValueError("Invalid %s JSON: %r" % (global_name, global_value)) 196 except LeaveUnset: 197 pass 198 199 TEMPLATE_DEBUG = DEBUG 200 201 # Configure logging and set place to store logs. 202 INTERNAL_IPS = () 203 LOGGING_LOG_SQL = False 204 205 # Logging levels: logging.DEBUG, logging.INFO, logging.WARNING, logging.ERROR logging.CRITICAL 206 207 if DEBUG: 208 LOGLEVEL = logging.DEBUG 209 logger.setLevel(LOGLEVEL) 210 211 for key in sorted(CUSTOM_SETTINGS_MAPPINGS): 212 values = CUSTOM_SETTINGS_MAPPINGS[key] 213 global_name, default_value, mapping, using_default = values 214 source = using_default and "default" or key 215 global_value = globals().get(global_name, "(unset)") 216 if global_name.lower().find("password") < 0: 217 logger.debug("%s = %r (source:%s)", global_name, global_value, source) 218 else: 219 logger.debug("%s = '***' (source:%s)", global_name, source) 220 221 222 ### 223 ### BEGIN EMDB settings 224 ### 225 try: 226 if USE_EMAN2: 227 logger.info("Using EMAN2...") 228 from EMAN2 import * 229 except: 230 logger.info("Not using EMAN2...") 231 pass 232 ### 233 ### END EMDB settings 234 ### 235 236 # Local time zone for this installation. Choices can be found here: 237 # http://www.postgresql.org/docs/8.1/appmedia/omeroweb/datetime-keywords.html#DATETIME-TIMEZONE-SET-TABLE 238 # although not all variations may be possible on all operating systems. 239 # If running in a Windows environment this must be set to the same as your 240 # system time zone. 241 TIME_ZONE = 'Europe/London' 242 FIRST_DAY_OF_WEEK = 0 # 0-Monday, ... 6-Sunday 243 244 # Language code for this installation. All choices can be found here: 245 # http://www.w3.org/TR/REC-html40/struct/dirlang.html#langcodes 246 # http://blogs.law.harvard.edu/tech/stories/storyReader$15 247 LANGUAGE_CODE = 'en-gb' 248 249 SITE_ID = 1 250 251 # If you set this to False, Django will make some optimizations so as not 252 # to load the internationalization machinery. 253 USE_I18N = True 254 255 # Absolute path to the directory that holds media. 256 # Example: "/home/media/media.lawrence.com/" 257 MEDIA_ROOT = os.path.join(os.path.dirname(__file__), 'media') 258 259 # URL that handles the media served from MEDIA_ROOT. 260 # Example: "http://media.lawrence.com" 261 MEDIA_URL = '/appmedia/' 262 263 # URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a 264 # trailing slash. 265 # Examples: "http://foo.com/media/", "/media/". 266 ADMIN_MEDIA_PREFIX = '/admin_appmedia/omeroweb/' 267 268 # Make this unique, and don't share it with anybody. 269 SECRET_KEY = '@@k%g#7=%4b6ib7yr1tloma&g0s2nni6ljf!m0h&x9c712c7yj' 270 271 # List of callables that know how to import templates from various sources. 272 TEMPLATE_LOADERS = ( 273 'django.template.loaders.filesystem.load_template_source', 274 'django.template.loaders.app_directories.load_template_source', 275 # 'django.template.loaders.eggs.load_template_source', 276 ) 277 278 MIDDLEWARE_CLASSES = ( 279 'django.middleware.common.CommonMiddleware', 280 'django.contrib.sessions.middleware.SessionMiddleware', 281 'django.middleware.doc.XViewMiddleware', 282 ) 283 284 ROOT_URLCONF = 'omeroweb.urls' 285 286 # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". 287 # Always use forward slashes, even on Windows. 288 # Don't forget to use absolute paths, not relative paths. 289 TEMPLATE_DIRS = ( 290 os.path.join(os.path.join(os.path.dirname(__file__), 'feedback'), 'templates').replace('\\','/'), 291 os.path.join(os.path.join(os.path.dirname(__file__), 'webadmin'), 'templates').replace('\\','/'), 292 os.path.join(os.path.join(os.path.dirname(__file__), 'webclient'), 'templates').replace('\\','/'), 293 #os.path.join(os.path.join(os.path.dirname(__file__), 'webemdb'), 'templates').replace('\\','/'), 294 os.path.join(os.path.join(os.path.dirname(__file__), 'webmobile'), 'templates').replace('\\','/'), 295 os.path.join(os.path.join(os.path.dirname(__file__), 'webpublic'), 'templates').replace('\\','/'), 296 ) 297 298 INSTALLED_APPS = ( 299 'django.contrib.admin', 300 'django.contrib.markup', 301 'django.contrib.auth', 302 'django.contrib.contenttypes', 303 'django.contrib.sessions', 304 'django.contrib.sites', 305 'omeroweb.feedback', 306 'omeroweb.webadmin', 307 'omeroweb.webclient', 308 'omeroweb.webgateway', 309 'omeroweb.webtest', 310 #'omeroweb.webemdb', 311 'omeroweb.webmobile', 312 'omeroweb.webpublic', 313 'omeroweb.webredirect', 314 ) 315 316 FEEDBACK_URL = "qa.openmicroscopy.org.uk:80" 317 318 IGNORABLE_404_ENDS = ('*.ico') 319 320 # SESSION_ENGINE is now set by the bin/omero config infrastructure 321 SESSION_FILE_PATH = tempfile.gettempdir() 322 323 # Cookies config 324 SESSION_EXPIRE_AT_BROWSER_CLOSE = True # False 325 SESSION_COOKIE_AGE = 86400 # 1 day in sec (86400) 326 327 # file upload settings 328 FILE_UPLOAD_TEMP_DIR = tempfile.gettempdir() 329 FILE_UPLOAD_MAX_MEMORY_SIZE = 2621440 #default 2621440 330 331 DEFAULT_IMG = os.path.join(os.path.dirname(__file__), 'media', 'omeroweb', "images", 'image128.png').replace('\\','/') 332 DEFAULT_USER = os.path.join(os.path.dirname(__file__), 'media', 'omeroweb', "images", 'personal32.png').replace('\\','/') 333 334 # Pagination 335 try: 336 PAGE 337 except: 338 PAGE = 200 339 340 SERVER_LIST = ServerObjects(SERVER_LIST) 341 342 MANAGERS = ADMINS 343 344 EMAIL_TEMPLATES = { 345 'create_share': { 346 'html_content':'<p>Hi,</p><p>I would like to share some of my data with you.<br/>Please find it on the <a href="%s/webclient/public/?server=%i">%s/webclient/public/?server=%i</a>.</p><p>%s</p>', 347 'text_content':'Hi, I would like to share some of my data with you. Please find it on the %s/webclient/public/?server=%i. /n %s' 348 }, 349 'add_member_to_share': { 350 'html_content':'<p>Hi,</p><p>I would like to share some of my data with you.<br/>Please find it on the <a href="%s/webclient/public/?server=%i">%s/webclient/public/?server=%i</a>.</p><p>%s</p>', 351 'text_content':'Hi, I would like to share some of my data with you. Please find it on the %s/webclient/public/?server=%i. /n %s' 352 }, 353 'remove_member_from_share': { 354 'html_content':'<p>You were removed from the share <a href="%s/webclient/public/?server=%i">%s/webclient/public/?server=%i</a>. This share is no longer available for you.</p>', 355 'text_content':'You were removed from the share %s/webclient/public/?server=%i. This share is no longer available for you.' 356 }, 357 'add_comment_to_share': { 358 'html_content':'<p>New comment is available on share <a href="%s/webclient/public/?server=%i">%s/webclient/public/?server=%i</a>.</p>', 359 'text_content':'New comment is available on share %s/webclient/public/?server=%i.' 360 } 361 } 362