settings.py 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. """
  2. Django settings for visualization project.
  3. For more information on this file, see
  4. https://docs.djangoproject.com/en/1.7/topics/settings/
  5. For the full list of settings and their values, see
  6. https://docs.djangoproject.com/en/1.7/ref/settings/
  7. """
  8. # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
  9. import os
  10. from . import settings_env
  11. from mongoengine import register_connection
  12. BASE_DIR = os.path.dirname(os.path.dirname(__file__))
  13. ENVIRONMENT = settings_env.ENVIRONMENT
  14. globalConfiguration = settings_env.globalConfiguration
  15. PATH_TIFF_SEQUENCER = globalConfiguration['sequencer']
  16. if os.path.exists(PATH_TIFF_SEQUENCER) is False:
  17. os.makedirs(PATH_TIFF_SEQUENCER)
  18. PATH_MMAP = globalConfiguration['mmap-folder']
  19. if os.path.exists(PATH_MMAP) is False:
  20. os.makedirs(PATH_MMAP)
  21. PATH_FIJI = globalConfiguration['fiji-path']
  22. DEFAULT_IMPORT_PATH = globalConfiguration['default-import-path']
  23. # good value may be 676 = 26 ^ 2
  24. MAX_NUMBER_SLICES_PER_MAP = 700.0
  25. # defaul: True
  26. Z_DOWNSCALING_ACTIVATED = False
  27. # default: False
  28. REDUCE_HARDDISK_ACCESS_FOR_DEV = globalConfiguration['reduce-harddisk-access']
  29. MAX_NUMBER_SLICES_PER_MAP = float(MAX_NUMBER_SLICES_PER_MAP)
  30. # Quick-start development settings - unsuitable for production
  31. # See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/
  32. # SECURITY WARNING: keep the secret key used in production secret!
  33. SECRET_KEY = '8sd=-3bl&j4r@#43x6nsihb(ppytmu6y0n255=5@m10yh=k*e3'
  34. # SECURITY WARNING: don't run with debug turned on in production!
  35. DEBUG = True
  36. TEMPLATE_DEBUG = True
  37. ALLOWED_HOSTS = []
  38. SUBVOLUME_STATIC = False
  39. # seconds
  40. SUBVOLUME_CACHING_TIME = 180
  41. # Application definition
  42. INSTALLED_APPS = (
  43. 'django.contrib.admin',
  44. 'django.contrib.auth',
  45. 'django.contrib.contenttypes',
  46. 'django.contrib.sessions',
  47. 'django.contrib.messages',
  48. 'django.contrib.staticfiles',
  49. 'volumes',
  50. 'loadtests'
  51. )
  52. MIDDLEWARE_CLASSES = (
  53. 'django.contrib.sessions.middleware.SessionMiddleware',
  54. 'django.middleware.common.CommonMiddleware',
  55. 'django.middleware.csrf.CsrfViewMiddleware',
  56. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  57. 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
  58. 'django.contrib.messages.middleware.MessageMiddleware',
  59. 'django.middleware.clickjacking.XFrameOptionsMiddleware',
  60. )
  61. TEMPLATE_CONTEXT_PROCESSORS = (
  62. "django.contrib.auth.context_processors.auth",
  63. "django.core.context_processors.debug",
  64. "django.core.context_processors.i18n",
  65. "django.core.context_processors.media",
  66. "django.core.context_processors.static",
  67. "django.core.context_processors.tz",
  68. "django.contrib.messages.context_processors.messages",
  69. "django.core.context_processors.request",
  70. "visualization.context_processor.add_settings"
  71. )
  72. ROOT_URLCONF = 'visualization.urls'
  73. WSGI_APPLICATION = 'visualization.wsgi.application'
  74. TEMPLATE_DIRS = (
  75. os.path.join(BASE_DIR, 'templates'), 'templates'
  76. )
  77. # Database
  78. # https://docs.djangoproject.com/en/1.7/ref/settings/#databases
  79. DATABASES = {
  80. 'default': {
  81. 'ENGINE': '',
  82. },
  83. }
  84. CACHES = {
  85. 'default': {
  86. 'BACKEND': 'visualization.memcached.MemcachedCache',
  87. 'LOCATION': '127.0.0.1:11211',
  88. }
  89. }
  90. ''' logger configuration for each environment '''
  91. loggerConfiguration = {}
  92. loggerConfiguration['prod'] = {}
  93. loggerConfiguration['staging'] = {}
  94. loggerConfiguration['dev'] = {}
  95. loggerConfiguration['prod']['django'] = ['django-file']
  96. loggerConfiguration['prod']['django-request'] = ['django-file']
  97. loggerConfiguration['prod']['visualization'] = ['visualization-file']
  98. loggerConfiguration['prod']['volumes'] = ['visualization-file']
  99. loggerConfiguration['prod']['volumes-processing'] = ['visualization-processing-file']
  100. loggerConfiguration['staging'] = loggerConfiguration['prod']
  101. loggerConfiguration['dev']['django'] = []
  102. loggerConfiguration['dev']['django-request'] = []
  103. loggerConfiguration['dev']['visualization'] = ['visualization-file']
  104. loggerConfiguration['dev']['volumes'] = ['visualization-file']
  105. loggerConfiguration['dev']['volumes-processing'] = ['console']
  106. LOGGING = {
  107. 'version': 1,
  108. 'disable_existing_loggers': True,
  109. 'formatters': {
  110. 'verbose': {
  111. 'format': '%(levelname)s %(asctime)s %(pathname)s %(process)d %(message)s'
  112. },
  113. 'simple': {
  114. 'format': '%(levelname)s %(message)s'
  115. },
  116. },
  117. 'handlers': {
  118. 'django-file': {
  119. 'level': 'DEBUG',
  120. 'class': 'logging.FileHandler',
  121. 'filename': globalConfiguration['log-base-path'] + '-django.log',
  122. 'formatter': 'simple'
  123. },
  124. 'visualization-file': {
  125. 'level': 'DEBUG',
  126. 'class': 'logging.FileHandler',
  127. 'filename': globalConfiguration['log-base-path'] + '.log',
  128. 'formatter': 'verbose'
  129. },
  130. 'visualization-processing-file': {
  131. 'level': 'DEBUG',
  132. 'class': 'logging.FileHandler',
  133. 'filename': globalConfiguration['log-base-path'] + '-processing.log',
  134. 'formatter': 'verbose'
  135. },
  136. 'visualization-processing-subvolume-file': {
  137. 'level': 'DEBUG',
  138. 'class': 'logging.FileHandler',
  139. 'filename': globalConfiguration['log-base-path'] + '-processing-subvolume.log',
  140. 'formatter': 'verbose'
  141. },
  142. 'console': {
  143. 'level': 'DEBUG',
  144. 'class': 'logging.StreamHandler'
  145. },
  146. },
  147. 'loggers': {
  148. 'django': {
  149. 'handlers': loggerConfiguration[ENVIRONMENT]['django'],
  150. 'level': 'DEBUG',
  151. 'propagate': False,
  152. },
  153. 'django.request': {
  154. 'handlers': loggerConfiguration[ENVIRONMENT]['django-request'],
  155. 'level': 'DEBUG',
  156. 'propagate': False,
  157. },
  158. 'visualization': {
  159. 'handlers': loggerConfiguration[ENVIRONMENT]['visualization'],
  160. 'level': 'DEBUG',
  161. 'propagate': False,
  162. },
  163. 'volumes': {
  164. 'handlers': loggerConfiguration[ENVIRONMENT]['volumes'],
  165. 'level': 'DEBUG',
  166. 'propagate': False,
  167. },
  168. 'volumes.processing': {
  169. 'handlers': loggerConfiguration[ENVIRONMENT]['volumes-processing'],
  170. 'level': 'DEBUG',
  171. 'propagate': False,
  172. },
  173. 'imageprocessing': {
  174. 'handlers': loggerConfiguration[ENVIRONMENT]['volumes-processing'],
  175. 'level': 'DEBUG',
  176. 'propagate': False,
  177. },
  178. },
  179. }
  180. # Internationalization
  181. # https://docs.djangoproject.com/en/1.7/topics/i18n/
  182. LANGUAGE_CODE = 'en-us'
  183. TIME_ZONE = 'UTC'
  184. USE_I18N = True
  185. USE_L10N = True
  186. USE_TZ = True
  187. # Static files (CSS, JavaScript, Images)
  188. # https://docs.djangoproject.com/en/1.7/howto/static-files/
  189. STATIC_URL = globalConfiguration['static-url-prefix'] + '/static/'
  190. STATICFILES_DIRS = (
  191. os.path.join(BASE_DIR, "static"), ''
  192. )
  193. SESSION_ENGINE = 'mongoengine.django.sessions'
  194. MONGO_DATABASE_NAME = globalConfiguration['db-name']
  195. MONGO_DATABASE_TESTRESULT_NAME = globalConfiguration['db-name-tests-results']
  196. register_connection('default', MONGO_DATABASE_NAME)
  197. register_connection('test_results', MONGO_DATABASE_TESTRESULT_NAME)
  198. # this line has to be after SECRET_KEY
  199. from django.core.cache import cache
  200. cache.set('test', True)
  201. if cache.get('test') is None:
  202. import logging
  203. logging.getLogger(__name__).error('cache backend not available')