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