Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | # |
| 2 | # ex:ts=4:sw=4:sts=4:et |
| 3 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- |
| 4 | # |
| 5 | # BitBake Toaster Implementation |
| 6 | # |
| 7 | # Copyright (C) 2013 Intel Corporation |
| 8 | # |
| 9 | # This program is free software; you can redistribute it and/or modify |
| 10 | # it under the terms of the GNU General Public License version 2 as |
| 11 | # published by the Free Software Foundation. |
| 12 | # |
| 13 | # This program is distributed in the hope that it will be useful, |
| 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | # GNU General Public License for more details. |
| 17 | # |
| 18 | # You should have received a copy of the GNU General Public License along |
| 19 | # with this program; if not, write to the Free Software Foundation, Inc., |
| 20 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 21 | |
| 22 | # Django settings for Toaster project. |
| 23 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 24 | import os |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 25 | |
| 26 | DEBUG = True |
| 27 | TEMPLATE_DEBUG = DEBUG |
| 28 | |
| 29 | # Set to True to see the SQL queries in console |
| 30 | SQL_DEBUG = False |
| 31 | if os.environ.get("TOASTER_SQLDEBUG", None) is not None: |
| 32 | SQL_DEBUG = True |
| 33 | |
| 34 | |
| 35 | ADMINS = ( |
| 36 | # ('Your Name', 'your_email@example.com'), |
| 37 | ) |
| 38 | |
| 39 | MANAGERS = ADMINS |
| 40 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 41 | TOASTER_SQLITE_DEFAULT_DIR = os.path.join(os.environ.get('TOASTER_DIR', ''), |
| 42 | 'build') |
| 43 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 44 | DATABASES = { |
| 45 | 'default': { |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 46 | # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. |
| 47 | 'ENGINE': 'django.db.backends.sqlite3', |
| 48 | # DB name or full path to database file if using sqlite3. |
| 49 | 'NAME': "%s/toaster.sqlite" % TOASTER_SQLITE_DEFAULT_DIR, |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 50 | 'USER': '', |
| 51 | 'PASSWORD': '', |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 52 | #'HOST': '127.0.0.1', # e.g. mysql server |
| 53 | #'PORT': '3306', # e.g. mysql port |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 54 | } |
| 55 | } |
| 56 | |
| 57 | # Needed when Using sqlite especially to add a longer timeout for waiting |
| 58 | # for the database lock to be released |
| 59 | # https://docs.djangoproject.com/en/1.6/ref/databases/#database-is-locked-errors |
| 60 | if 'sqlite' in DATABASES['default']['ENGINE']: |
| 61 | DATABASES['default']['OPTIONS'] = { 'timeout': 20 } |
| 62 | |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame^] | 63 | # Update as of django 1.8.16 release, the '*' is needed to allow us to connect while running |
| 64 | # on hosts without explicitly setting the fqdn for the toaster server. |
| 65 | # See https://docs.djangoproject.com/en/dev/ref/settings/ for info on ALLOWED_HOSTS |
| 66 | # Previously this setting was not enforced if DEBUG was set but it is now. |
| 67 | # The previous behavior was such that ALLOWED_HOSTS defaulted to ['localhost','127.0.0.1','::1'] |
| 68 | # and if you bound to 0.0.0.0:<port #> then accessing toaster as localhost or fqdn would both work. |
| 69 | # To have that same behavior, with a fqdn explicitly enabled you would set |
| 70 | # ALLOWED_HOSTS= ['localhost','127.0.0.1','::1','myserver.mycompany.com'] for |
| 71 | # Django >= 1.8.16. By default, we are not enforcing this restriction in |
| 72 | # DEBUG mode. |
| 73 | if DEBUG is True: |
| 74 | # this will allow connection via localhost,hostname, or fqdn |
| 75 | ALLOWED_HOSTS = ['*'] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 76 | |
| 77 | # Local time zone for this installation. Choices can be found here: |
| 78 | # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name |
| 79 | # although not all choices may be available on all operating systems. |
| 80 | # In a Windows environment this must be set to your system time zone. |
| 81 | |
| 82 | # Always use local computer's time zone, find |
| 83 | import hashlib |
| 84 | if 'TZ' in os.environ: |
| 85 | TIME_ZONE = os.environ['TZ'] |
| 86 | else: |
| 87 | # need to read the /etc/localtime file which is the libc standard |
| 88 | # and do a reverse-mapping to /usr/share/zoneinfo/; |
| 89 | # since the timezone may match any number of identical timezone definitions, |
| 90 | |
| 91 | zonefilelist = {} |
| 92 | ZONEINFOPATH = '/usr/share/zoneinfo/' |
| 93 | for dirpath, dirnames, filenames in os.walk(ZONEINFOPATH): |
| 94 | for fn in filenames: |
| 95 | filepath = os.path.join(dirpath, fn) |
| 96 | zonename = filepath.lstrip(ZONEINFOPATH).strip() |
| 97 | try: |
| 98 | import pytz |
| 99 | from pytz.exceptions import UnknownTimeZoneError |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 100 | try: |
| 101 | if pytz.timezone(zonename) is not None: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 102 | zonefilelist[hashlib.md5(open(filepath, 'rb').read()).hexdigest()] = zonename |
| 103 | except UnknownTimeZoneError as ValueError: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 104 | # we expect timezone failures here, just move over |
| 105 | pass |
| 106 | except ImportError: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 107 | zonefilelist[hashlib.md5(open(filepath, 'rb').read()).hexdigest()] = zonename |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 108 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 109 | TIME_ZONE = zonefilelist[hashlib.md5(open('/etc/localtime', 'rb').read()).hexdigest()] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 110 | |
| 111 | # Language code for this installation. All choices can be found here: |
| 112 | # http://www.i18nguy.com/unicode/language-identifiers.html |
| 113 | LANGUAGE_CODE = 'en-us' |
| 114 | |
| 115 | SITE_ID = 1 |
| 116 | |
| 117 | # If you set this to False, Django will make some optimizations so as not |
| 118 | # to load the internationalization machinery. |
| 119 | USE_I18N = True |
| 120 | |
| 121 | # If you set this to False, Django will not format dates, numbers and |
| 122 | # calendars according to the current locale. |
| 123 | USE_L10N = True |
| 124 | |
| 125 | # If you set this to False, Django will not use timezone-aware datetimes. |
| 126 | USE_TZ = True |
| 127 | |
| 128 | # Absolute filesystem path to the directory that will hold user-uploaded files. |
| 129 | # Example: "/var/www/example.com/media/" |
| 130 | MEDIA_ROOT = '' |
| 131 | |
| 132 | # URL that handles the media served from MEDIA_ROOT. Make sure to use a |
| 133 | # trailing slash. |
| 134 | # Examples: "http://example.com/media/", "http://media.example.com/" |
| 135 | MEDIA_URL = '' |
| 136 | |
| 137 | # Absolute path to the directory static files should be collected to. |
| 138 | # Don't put anything in this directory yourself; store your static files |
| 139 | # in apps' "static/" subdirectories and in STATICFILES_DIRS. |
| 140 | # Example: "/var/www/example.com/static/" |
| 141 | STATIC_ROOT = '' |
| 142 | |
| 143 | # URL prefix for static files. |
| 144 | # Example: "http://example.com/static/", "http://static.example.com/" |
| 145 | STATIC_URL = '/static/' |
| 146 | |
| 147 | # Additional locations of static files |
| 148 | STATICFILES_DIRS = ( |
| 149 | # Put strings here, like "/home/html/static" or "C:/www/django/static". |
| 150 | # Always use forward slashes, even on Windows. |
| 151 | # Don't forget to use absolute paths, not relative paths. |
| 152 | ) |
| 153 | |
| 154 | # List of finder classes that know how to find static files in |
| 155 | # various locations. |
| 156 | STATICFILES_FINDERS = ( |
| 157 | 'django.contrib.staticfiles.finders.FileSystemFinder', |
| 158 | 'django.contrib.staticfiles.finders.AppDirectoriesFinder', |
| 159 | # 'django.contrib.staticfiles.finders.DefaultStorageFinder', |
| 160 | ) |
| 161 | |
| 162 | # Make this unique, and don't share it with anybody. |
| 163 | SECRET_KEY = 'NOT_SUITABLE_FOR_HOSTED_DEPLOYMENT' |
| 164 | |
| 165 | # List of callables that know how to import templates from various sources. |
| 166 | TEMPLATE_LOADERS = ( |
| 167 | 'django.template.loaders.filesystem.Loader', |
| 168 | 'django.template.loaders.app_directories.Loader', |
| 169 | # 'django.template.loaders.eggs.Loader', |
| 170 | ) |
| 171 | |
| 172 | MIDDLEWARE_CLASSES = ( |
| 173 | 'django.middleware.common.CommonMiddleware', |
| 174 | 'django.contrib.sessions.middleware.SessionMiddleware', |
| 175 | 'django.middleware.csrf.CsrfViewMiddleware', |
| 176 | 'django.contrib.auth.middleware.AuthenticationMiddleware', |
| 177 | 'django.contrib.messages.middleware.MessageMiddleware', |
| 178 | # Uncomment the next line for simple clickjacking protection: |
| 179 | # 'django.middleware.clickjacking.XFrameOptionsMiddleware', |
| 180 | ) |
| 181 | |
| 182 | CACHES = { |
| 183 | # 'default': { |
| 184 | # 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache', |
| 185 | # 'LOCATION': '127.0.0.1:11211', |
| 186 | # }, |
| 187 | 'default': { |
| 188 | 'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache', |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 189 | 'LOCATION': '/tmp/toaster_cache_%d' % os.getuid(), |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 190 | 'TIMEOUT': 1, |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | |
| 195 | from os.path import dirname as DN |
| 196 | SITE_ROOT=DN(DN(os.path.abspath(__file__))) |
| 197 | |
| 198 | import subprocess |
| 199 | TOASTER_BRANCH = subprocess.Popen('git branch | grep "^* " | tr -d "* "', cwd = SITE_ROOT, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0] |
| 200 | TOASTER_REVISION = subprocess.Popen('git rev-parse HEAD ', cwd = SITE_ROOT, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0] |
| 201 | |
| 202 | ROOT_URLCONF = 'toastermain.urls' |
| 203 | |
| 204 | # Python dotted path to the WSGI application used by Django's runserver. |
| 205 | WSGI_APPLICATION = 'toastermain.wsgi.application' |
| 206 | |
| 207 | TEMPLATE_DIRS = ( |
| 208 | # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". |
| 209 | # Always use forward slashes, even on Windows. |
| 210 | # Don't forget to use absolute paths, not relative paths. |
| 211 | ) |
| 212 | |
| 213 | TEMPLATE_CONTEXT_PROCESSORS = ('django.contrib.auth.context_processors.auth', |
| 214 | 'django.core.context_processors.debug', |
| 215 | 'django.core.context_processors.i18n', |
| 216 | 'django.core.context_processors.media', |
| 217 | 'django.core.context_processors.static', |
| 218 | 'django.core.context_processors.tz', |
| 219 | 'django.contrib.messages.context_processors.messages', |
| 220 | "django.core.context_processors.request", |
| 221 | 'toastergui.views.managedcontextprocessor', |
| 222 | ) |
| 223 | |
| 224 | INSTALLED_APPS = ( |
| 225 | 'django.contrib.auth', |
| 226 | 'django.contrib.contenttypes', |
| 227 | 'django.contrib.messages', |
| 228 | 'django.contrib.sessions', |
| 229 | 'django.contrib.admin', |
| 230 | 'django.contrib.staticfiles', |
| 231 | |
| 232 | # Uncomment the next line to enable admin documentation: |
| 233 | # 'django.contrib.admindocs', |
| 234 | 'django.contrib.humanize', |
| 235 | 'bldcollector', |
| 236 | 'toastermain', |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 237 | ) |
| 238 | |
| 239 | |
| 240 | INTERNAL_IPS = ['127.0.0.1', '192.168.2.28'] |
| 241 | |
| 242 | # Load django-fresh is TOASTER_DEVEL is set, and the module is available |
| 243 | FRESH_ENABLED = False |
| 244 | if os.environ.get('TOASTER_DEVEL', None) is not None: |
| 245 | try: |
| 246 | import fresh |
| 247 | MIDDLEWARE_CLASSES = ("fresh.middleware.FreshMiddleware",) + MIDDLEWARE_CLASSES |
| 248 | INSTALLED_APPS = INSTALLED_APPS + ('fresh',) |
| 249 | FRESH_ENABLED = True |
| 250 | except: |
| 251 | pass |
| 252 | |
| 253 | DEBUG_PANEL_ENABLED = False |
| 254 | if os.environ.get('TOASTER_DEVEL', None) is not None: |
| 255 | try: |
| 256 | import debug_toolbar, debug_panel |
| 257 | MIDDLEWARE_CLASSES = ('debug_panel.middleware.DebugPanelMiddleware',) + MIDDLEWARE_CLASSES |
| 258 | #MIDDLEWARE_CLASSES = MIDDLEWARE_CLASSES + ('debug_toolbar.middleware.DebugToolbarMiddleware',) |
| 259 | INSTALLED_APPS = INSTALLED_APPS + ('debug_toolbar','debug_panel',) |
| 260 | DEBUG_PANEL_ENABLED = True |
| 261 | |
| 262 | # this cache backend will be used by django-debug-panel |
| 263 | CACHES['debug-panel'] = { |
| 264 | 'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache', |
| 265 | 'LOCATION': '/var/tmp/debug-panel-cache', |
| 266 | 'TIMEOUT': 300, |
| 267 | 'OPTIONS': { |
| 268 | 'MAX_ENTRIES': 200 |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | except: |
| 273 | pass |
| 274 | |
| 275 | |
| 276 | SOUTH_TESTS_MIGRATE = False |
| 277 | |
| 278 | |
| 279 | # We automatically detect and install applications here if |
| 280 | # they have a 'models.py' or 'views.py' file |
| 281 | import os |
| 282 | currentdir = os.path.dirname(__file__) |
| 283 | for t in os.walk(os.path.dirname(currentdir)): |
| 284 | modulename = os.path.basename(t[0]) |
| 285 | #if we have a virtualenv skip it to avoid incorrect imports |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 286 | if 'VIRTUAL_ENV' in os.environ and os.environ['VIRTUAL_ENV'] in t[0]: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 287 | continue |
| 288 | |
| 289 | if ("views.py" in t[2] or "models.py" in t[2]) and not modulename in INSTALLED_APPS: |
| 290 | INSTALLED_APPS = INSTALLED_APPS + (modulename,) |
| 291 | |
| 292 | # A sample logging configuration. The only tangible logging |
| 293 | # performed by this configuration is to send an email to |
| 294 | # the site admins on every HTTP 500 error when DEBUG=False. |
| 295 | # See http://docs.djangoproject.com/en/dev/topics/logging for |
| 296 | # more details on how to customize your logging configuration. |
| 297 | LOGGING = { |
| 298 | 'version': 1, |
| 299 | 'disable_existing_loggers': False, |
| 300 | 'filters': { |
| 301 | 'require_debug_false': { |
| 302 | '()': 'django.utils.log.RequireDebugFalse' |
| 303 | } |
| 304 | }, |
| 305 | 'formatters': { |
| 306 | 'datetime': { |
| 307 | 'format': '%(asctime)s %(levelname)s %(message)s' |
| 308 | } |
| 309 | }, |
| 310 | 'handlers': { |
| 311 | 'mail_admins': { |
| 312 | 'level': 'ERROR', |
| 313 | 'filters': ['require_debug_false'], |
| 314 | 'class': 'django.utils.log.AdminEmailHandler' |
| 315 | }, |
| 316 | 'console': { |
| 317 | 'level': 'DEBUG', |
| 318 | 'class': 'logging.StreamHandler', |
| 319 | 'formatter': 'datetime', |
| 320 | } |
| 321 | }, |
| 322 | 'loggers': { |
| 323 | 'toaster' : { |
| 324 | 'handlers': ['console'], |
| 325 | 'level': 'DEBUG', |
| 326 | }, |
| 327 | 'django.request': { |
| 328 | 'handlers': ['console'], |
| 329 | 'level': 'WARN', |
| 330 | 'propagate': True, |
| 331 | }, |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | if DEBUG and SQL_DEBUG: |
| 336 | LOGGING['loggers']['django.db.backends'] = { |
| 337 | 'level': 'DEBUG', |
| 338 | 'handlers': ['console'], |
| 339 | } |
| 340 | |
| 341 | |
| 342 | # If we're using sqlite, we need to tweak the performance a bit |
| 343 | from django.db.backends.signals import connection_created |
| 344 | def activate_synchronous_off(sender, connection, **kwargs): |
| 345 | if connection.vendor == 'sqlite': |
| 346 | cursor = connection.cursor() |
| 347 | cursor.execute('PRAGMA synchronous = 0;') |
| 348 | connection_created.connect(activate_synchronous_off) |
| 349 | # |
| 350 | |
| 351 | |
| 352 | class InvalidString(str): |
| 353 | def __mod__(self, other): |
| 354 | from django.template.base import TemplateSyntaxError |
| 355 | raise TemplateSyntaxError( |
| 356 | "Undefined variable or unknown value for: \"%s\"" % other) |
| 357 | |
| 358 | TEMPLATE_STRING_IF_INVALID = InvalidString("%s") |