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