diff options
Diffstat (limited to 'bitbake/lib/toaster/toastermain/settings.py')
-rw-r--r-- | bitbake/lib/toaster/toastermain/settings.py | 85 |
1 files changed, 39 insertions, 46 deletions
diff --git a/bitbake/lib/toaster/toastermain/settings.py b/bitbake/lib/toaster/toastermain/settings.py index a4b370c8d4..e06adc5a93 100644 --- a/bitbake/lib/toaster/toastermain/settings.py +++ b/bitbake/lib/toaster/toastermain/settings.py | |||
@@ -9,6 +9,8 @@ | |||
9 | # Django settings for Toaster project. | 9 | # Django settings for Toaster project. |
10 | 10 | ||
11 | import os | 11 | import os |
12 | from pathlib import Path | ||
13 | from toastermain.logs import LOGGING_SETTINGS | ||
12 | 14 | ||
13 | DEBUG = True | 15 | DEBUG = True |
14 | 16 | ||
@@ -39,6 +41,9 @@ DATABASES = { | |||
39 | } | 41 | } |
40 | } | 42 | } |
41 | 43 | ||
44 | # New in Django 3.2 | ||
45 | DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' | ||
46 | |||
42 | # Needed when Using sqlite especially to add a longer timeout for waiting | 47 | # Needed when Using sqlite especially to add a longer timeout for waiting |
43 | # for the database lock to be released | 48 | # for the database lock to be released |
44 | # https://docs.djangoproject.com/en/1.6/ref/databases/#database-is-locked-errors | 49 | # https://docs.djangoproject.com/en/1.6/ref/databases/#database-is-locked-errors |
@@ -84,14 +89,17 @@ else: | |||
84 | from pytz.exceptions import UnknownTimeZoneError | 89 | from pytz.exceptions import UnknownTimeZoneError |
85 | try: | 90 | try: |
86 | if pytz.timezone(zonename) is not None: | 91 | if pytz.timezone(zonename) is not None: |
87 | zonefilelist[hashlib.md5(open(filepath, 'rb').read()).hexdigest()] = zonename | 92 | with open(filepath, 'rb') as f: |
93 | zonefilelist[hashlib.md5(f.read()).hexdigest()] = zonename | ||
88 | except UnknownTimeZoneError as ValueError: | 94 | except UnknownTimeZoneError as ValueError: |
89 | # we expect timezone failures here, just move over | 95 | # we expect timezone failures here, just move over |
90 | pass | 96 | pass |
91 | except ImportError: | 97 | except ImportError: |
92 | zonefilelist[hashlib.md5(open(filepath, 'rb').read()).hexdigest()] = zonename | 98 | with open(filepath, 'rb') as f: |
99 | zonefilelist[hashlib.md5(f.read()).hexdigest()] = zonename | ||
93 | 100 | ||
94 | TIME_ZONE = zonefilelist[hashlib.md5(open('/etc/localtime', 'rb').read()).hexdigest()] | 101 | with open('/etc/localtime', 'rb') as f: |
102 | TIME_ZONE = zonefilelist[hashlib.md5(f.read()).hexdigest()] | ||
95 | 103 | ||
96 | # Language code for this installation. All choices can be found here: | 104 | # Language code for this installation. All choices can be found here: |
97 | # http://www.i18nguy.com/unicode/language-identifiers.html | 105 | # http://www.i18nguy.com/unicode/language-identifiers.html |
@@ -103,10 +111,6 @@ SITE_ID = 1 | |||
103 | # to load the internationalization machinery. | 111 | # to load the internationalization machinery. |
104 | USE_I18N = True | 112 | USE_I18N = True |
105 | 113 | ||
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. | 114 | # If you set this to False, Django will not use timezone-aware datetimes. |
111 | USE_TZ = True | 115 | USE_TZ = True |
112 | 116 | ||
@@ -147,6 +151,8 @@ STATICFILES_FINDERS = ( | |||
147 | # Make this unique, and don't share it with anybody. | 151 | # Make this unique, and don't share it with anybody. |
148 | SECRET_KEY = 'NOT_SUITABLE_FOR_HOSTED_DEPLOYMENT' | 152 | SECRET_KEY = 'NOT_SUITABLE_FOR_HOSTED_DEPLOYMENT' |
149 | 153 | ||
154 | TMPDIR = os.environ.get('TOASTER_DJANGO_TMPDIR', '/tmp') | ||
155 | |||
150 | class InvalidString(str): | 156 | class InvalidString(str): |
151 | def __mod__(self, other): | 157 | def __mod__(self, other): |
152 | from django.template.base import TemplateSyntaxError | 158 | from django.template.base import TemplateSyntaxError |
@@ -183,7 +189,13 @@ TEMPLATES = [ | |||
183 | 'django.template.loaders.app_directories.Loader', | 189 | 'django.template.loaders.app_directories.Loader', |
184 | #'django.template.loaders.eggs.Loader', | 190 | #'django.template.loaders.eggs.Loader', |
185 | ], | 191 | ], |
186 | 'string_if_invalid': InvalidString("%s"), | 192 | # https://docs.djangoproject.com/en/4.2/ref/templates/api/#how-invalid-variables-are-handled |
193 | # Generally, string_if_invalid should only be enabled in order to debug | ||
194 | # a specific template problem, then cleared once debugging is complete. | ||
195 | # If you assign a value other than '' to string_if_invalid, | ||
196 | # you will experience rendering problems with these templates and sites. | ||
197 | # 'string_if_invalid': InvalidString("%s"), | ||
198 | 'string_if_invalid': "", | ||
187 | 'debug': DEBUG, | 199 | 'debug': DEBUG, |
188 | }, | 200 | }, |
189 | }, | 201 | }, |
@@ -207,7 +219,7 @@ CACHES = { | |||
207 | # }, | 219 | # }, |
208 | 'default': { | 220 | 'default': { |
209 | 'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache', | 221 | 'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache', |
210 | 'LOCATION': '/tmp/toaster_cache_%d' % os.getuid(), | 222 | 'LOCATION': '%s/toaster_cache_%d' % (TMPDIR, os.getuid()), |
211 | 'TIMEOUT': 1, | 223 | 'TIMEOUT': 1, |
212 | } | 224 | } |
213 | } | 225 | } |
@@ -239,6 +251,9 @@ INSTALLED_APPS = ( | |||
239 | 'django.contrib.humanize', | 251 | 'django.contrib.humanize', |
240 | 'bldcollector', | 252 | 'bldcollector', |
241 | 'toastermain', | 253 | 'toastermain', |
254 | |||
255 | # 3rd-lib | ||
256 | "log_viewer", | ||
242 | ) | 257 | ) |
243 | 258 | ||
244 | 259 | ||
@@ -299,43 +314,21 @@ for t in os.walk(os.path.dirname(currentdir)): | |||
299 | # the site admins on every HTTP 500 error when DEBUG=False. | 314 | # the site admins on every HTTP 500 error when DEBUG=False. |
300 | # See http://docs.djangoproject.com/en/dev/topics/logging for | 315 | # See http://docs.djangoproject.com/en/dev/topics/logging for |
301 | # more details on how to customize your logging configuration. | 316 | # more details on how to customize your logging configuration. |
302 | LOGGING = { | 317 | LOGGING = LOGGING_SETTINGS |
303 | 'version': 1, | 318 | |
304 | 'disable_existing_loggers': False, | 319 | # Build paths inside the project like this: BASE_DIR / 'subdir'. |
305 | 'filters': { | 320 | BUILDDIR = os.environ.get("BUILDDIR", TMPDIR) |
306 | 'require_debug_false': { | 321 | |
307 | '()': 'django.utils.log.RequireDebugFalse' | 322 | # LOG VIEWER |
308 | } | 323 | # https://pypi.org/project/django-log-viewer/ |
309 | }, | 324 | LOG_VIEWER_FILES_PATTERN = '*.log*' |
310 | 'formatters': { | 325 | LOG_VIEWER_FILES_DIR = os.path.join(BUILDDIR, "toaster_logs/") |
311 | 'datetime': { | 326 | LOG_VIEWER_PAGE_LENGTH = 25 # total log lines per-page |
312 | 'format': '%(asctime)s %(levelname)s %(message)s' | 327 | LOG_VIEWER_MAX_READ_LINES = 100000 # total log lines will be read |
313 | } | 328 | LOG_VIEWER_PATTERNS = ['INFO', 'DEBUG', 'WARNING', 'ERROR', 'CRITICAL'] |
314 | }, | 329 | |
315 | 'handlers': { | 330 | # Optionally you can set the next variables in order to customize the admin: |
316 | 'mail_admins': { | 331 | LOG_VIEWER_FILE_LIST_TITLE = "Logs list" |
317 | 'level': 'ERROR', | ||
318 | 'filters': ['require_debug_false'], | ||
319 | 'class': 'django.utils.log.AdminEmailHandler' | ||
320 | }, | ||
321 | 'console': { | ||
322 | 'level': 'DEBUG', | ||
323 | 'class': 'logging.StreamHandler', | ||
324 | 'formatter': 'datetime', | ||
325 | } | ||
326 | }, | ||
327 | 'loggers': { | ||
328 | 'toaster' : { | ||
329 | 'handlers': ['console'], | ||
330 | 'level': 'DEBUG', | ||
331 | }, | ||
332 | 'django.request': { | ||
333 | 'handlers': ['console'], | ||
334 | 'level': 'WARN', | ||
335 | 'propagate': True, | ||
336 | }, | ||
337 | } | ||
338 | } | ||
339 | 332 | ||
340 | if DEBUG and SQL_DEBUG: | 333 | if DEBUG and SQL_DEBUG: |
341 | LOGGING['loggers']['django.db.backends'] = { | 334 | LOGGING['loggers']['django.db.backends'] = { |