settings.py 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. 'automaticimport'
  52. )
  53. MIDDLEWARE_CLASSES = (
  54. 'django.contrib.sessions.middleware.SessionMiddleware',
  55. 'django.middleware.common.CommonMiddleware',
  56. 'django.middleware.csrf.CsrfViewMiddleware',
  57. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  58. 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
  59. 'django.contrib.messages.middleware.MessageMiddleware',
  60. 'django.middleware.clickjacking.XFrameOptionsMiddleware',
  61. )
  62. TEMPLATE_CONTEXT_PROCESSORS = (
  63. "django.contrib.auth.context_processors.auth",
  64. "django.core.context_processors.debug",
  65. "django.core.context_processors.i18n",
  66. "django.core.context_processors.media",
  67. "django.core.context_processors.static",
  68. "django.core.context_processors.tz",
  69. "django.contrib.messages.context_processors.messages",
  70. "django.core.context_processors.request",
  71. "visualization.context_processor.add_settings"
  72. )
  73. ROOT_URLCONF = 'visualization.urls'
  74. WSGI_APPLICATION = 'visualization.wsgi.application'
  75. TEMPLATE_DIRS = (
  76. os.path.join(BASE_DIR, 'templates'), 'templates'
  77. )
  78. # Database
  79. # https://docs.djangoproject.com/en/1.7/ref/settings/#databases
  80. DATABASES = {
  81. 'default': {
  82. 'ENGINE': '',
  83. },
  84. }
  85. CACHES = {
  86. 'default': {
  87. 'BACKEND': 'visualization.memcached.MemcachedCache',
  88. 'LOCATION': '127.0.0.1:11211',
  89. }
  90. }
  91. ''' logger configuration for each environment '''
  92. loggerConfiguration = {}
  93. loggerConfiguration['prod'] = {}
  94. loggerConfiguration['staging'] = {}
  95. loggerConfiguration['dev'] = {}
  96. loggerConfiguration['prod']['django'] = ['django-file']
  97. loggerConfiguration['prod']['django-request'] = ['django-file']
  98. loggerConfiguration['prod']['visualization'] = ['visualization-file']
  99. loggerConfiguration['prod']['volumes'] = ['visualization-file']
  100. loggerConfiguration['prod']['volumes-processing'] = ['visualization-processing-file']
  101. loggerConfiguration['staging'] = loggerConfiguration['prod']
  102. loggerConfiguration['dev']['django'] = []
  103. loggerConfiguration['dev']['django-request'] = []
  104. loggerConfiguration['dev']['visualization'] = ['visualization-file']
  105. loggerConfiguration['dev']['volumes'] = ['visualization-file']
  106. loggerConfiguration['dev']['volumes-processing'] = ['console']
  107. LOGGING = {
  108. 'version': 1,
  109. 'disable_existing_loggers': True,
  110. 'formatters': {
  111. 'verbose': {
  112. 'format': '%(levelname)s %(asctime)s %(pathname)s %(process)d %(message)s'
  113. },
  114. 'simple': {
  115. 'format': '%(levelname)s %(message)s'
  116. },
  117. },
  118. 'handlers': {
  119. 'django-file': {
  120. 'level': 'DEBUG',
  121. 'class': 'logging.FileHandler',
  122. 'filename': globalConfiguration['log-base-path'] + '-django.log',
  123. 'formatter': 'simple'
  124. },
  125. 'visualization-file': {
  126. 'level': 'DEBUG',
  127. 'class': 'logging.FileHandler',
  128. 'filename': globalConfiguration['log-base-path'] + '.log',
  129. 'formatter': 'verbose'
  130. },
  131. 'visualization-processing-file': {
  132. 'level': 'DEBUG',
  133. 'class': 'logging.FileHandler',
  134. 'filename': globalConfiguration['log-base-path'] + '-processing.log',
  135. 'formatter': 'verbose'
  136. },
  137. 'visualization-processing-subvolume-file': {
  138. 'level': 'DEBUG',
  139. 'class': 'logging.FileHandler',
  140. 'filename': globalConfiguration['log-base-path'] + '-processing-subvolume.log',
  141. 'formatter': 'verbose'
  142. },
  143. 'console': {
  144. 'level': 'DEBUG',
  145. 'class': 'logging.StreamHandler'
  146. },
  147. },
  148. 'loggers': {
  149. 'django': {
  150. 'handlers': loggerConfiguration[ENVIRONMENT]['django'],
  151. 'level': 'DEBUG',
  152. 'propagate': False,
  153. },
  154. 'django.request': {
  155. 'handlers': loggerConfiguration[ENVIRONMENT]['django-request'],
  156. 'level': 'DEBUG',
  157. 'propagate': False,
  158. },
  159. 'visualization': {
  160. 'handlers': loggerConfiguration[ENVIRONMENT]['visualization'],
  161. 'level': 'DEBUG',
  162. 'propagate': False,
  163. },
  164. 'volumes': {
  165. 'handlers': loggerConfiguration[ENVIRONMENT]['volumes'],
  166. 'level': 'DEBUG',
  167. 'propagate': False,
  168. },
  169. 'volumes.processing': {
  170. 'handlers': loggerConfiguration[ENVIRONMENT]['volumes-processing'],
  171. 'level': 'DEBUG',
  172. 'propagate': False,
  173. },
  174. 'imageprocessing': {
  175. 'handlers': loggerConfiguration[ENVIRONMENT]['volumes-processing'],
  176. 'level': 'DEBUG',
  177. 'propagate': False,
  178. },
  179. },
  180. }
  181. # Internationalization
  182. # https://docs.djangoproject.com/en/1.7/topics/i18n/
  183. LANGUAGE_CODE = 'en-us'
  184. TIME_ZONE = 'UTC'
  185. USE_I18N = True
  186. USE_L10N = True
  187. USE_TZ = True
  188. # Static files (CSS, JavaScript, Images)
  189. # https://docs.djangoproject.com/en/1.7/howto/static-files/
  190. STATIC_URL = globalConfiguration['static-url-prefix'] + '/static/'
  191. STATICFILES_DIRS = (
  192. os.path.join(BASE_DIR, "static"), ''
  193. )
  194. SESSION_ENGINE = 'mongoengine.django.sessions'
  195. MONGO_DATABASE_NAME = globalConfiguration['db-name']
  196. MONGO_DATABASE_TESTRESULT_NAME = globalConfiguration['db-name-tests-results']
  197. register_connection('default', MONGO_DATABASE_NAME)
  198. register_connection('test_results', MONGO_DATABASE_TESTRESULT_NAME)
  199. # this line has to be after SECRET_KEY
  200. from django.core.cache import cache
  201. cache.set('test', True)
  202. if cache.get('test') is None:
  203. import logging
  204. logging.getLogger(__name__).error('cache backend not available')