blob: 3be46fcf0ca2a2bddb85e46345432493524566e6 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001#
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002# BitBake Toaster Implementation
3#
4# Copyright (C) 2013 Intel Corporation
5#
Brad Bishopc342db32019-05-15 21:57:59 -04006# SPDX-License-Identifier: GPL-2.0-only
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007#
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008
Andrew Geissler5082cc72023-09-11 08:41:39 -04009from django.urls import re_path as url, include
Brad Bishopd7bf8c12018-02-25 22:55:05 -050010from django.views.generic import RedirectView, TemplateView
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011from django.views.decorators.cache import never_cache
Brad Bishopd7bf8c12018-02-25 22:55:05 -050012import bldcollector.views
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013
14import logging
15
16logger = logging.getLogger("toaster")
17
18# Uncomment the next two lines to enable the admin:
19from django.contrib import admin
20admin.autodiscover()
21
Brad Bishopd7bf8c12018-02-25 22:55:05 -050022urlpatterns = [
Patrick Williamsc124f4f2015-09-15 14:41:29 -050023
24 # Examples:
25 # url(r'^toaster/', include('toaster.foo.urls')),
26
27 # Uncomment the admin/doc line below to enable admin documentation:
28 # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
29
30
Andrew Geissler20137392023-10-12 04:59:14 -060031 url(r'^logs/', include('log_viewer.urls')),
32
Patrick Williamsc124f4f2015-09-15 14:41:29 -050033 # This is here to maintain backward compatibility and will be deprecated
34 # in the future.
Brad Bishopd7bf8c12018-02-25 22:55:05 -050035 url(r'^orm/eventfile$', bldcollector.views.eventfile),
36
37 url(r'^health$', TemplateView.as_view(template_name="health.html"), name='Toaster Health'),
Patrick Williamsc124f4f2015-09-15 14:41:29 -050038
39 # if no application is selected, we have the magic toastergui app here
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050040 url(r'^$', never_cache(RedirectView.as_view(url='/toastergui/', permanent=True))),
Brad Bishopd7bf8c12018-02-25 22:55:05 -050041]
Patrick Williamsc124f4f2015-09-15 14:41:29 -050042
43import toastermain.settings
44
45if toastermain.settings.FRESH_ENABLED:
46 urlpatterns.insert(1, url(r'', include('fresh.urls')))
47 #logger.info("Enabled django-fresh extension")
48
49if toastermain.settings.DEBUG_PANEL_ENABLED:
50 import debug_toolbar
51 urlpatterns.insert(1, url(r'', include(debug_toolbar.urls)))
52 #logger.info("Enabled django_toolbar extension")
53
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050054urlpatterns = [
55 # Uncomment the next line to enable the admin:
Andrew Geissler82c905d2020-04-13 13:39:40 -050056 url(r'^admin/', admin.site.urls),
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050057] + urlpatterns
Patrick Williamsc124f4f2015-09-15 14:41:29 -050058
Patrick Williamsc124f4f2015-09-15 14:41:29 -050059# Automatically discover urls.py in various apps, beside our own
60# and map module directories to the patterns
61
62import os
63currentdir = os.path.dirname(__file__)
64for t in os.walk(os.path.dirname(currentdir)):
65 #if we have a virtualenv skip it to avoid incorrect imports
Patrick Williamsc0f7c042017-02-23 20:41:17 -060066 if 'VIRTUAL_ENV' in os.environ and os.environ['VIRTUAL_ENV'] in t[0]:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050067 continue
68
69 if "urls.py" in t[2] and t[0] != currentdir:
70 modulename = os.path.basename(t[0])
71 # make sure we don't have this module name in
72 conflict = False
73 for p in urlpatterns:
Andrew Geissler82c905d2020-04-13 13:39:40 -050074 if p.pattern.regex.pattern == '^' + modulename + '/':
Patrick Williamsc124f4f2015-09-15 14:41:29 -050075 conflict = True
76 if not conflict:
77 urlpatterns.insert(0, url(r'^' + modulename + '/', include ( modulename + '.urls')))
78 else:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060079 logger.warning("Module \'%s\' has a regexp conflict, was not added to the urlpatterns" % modulename)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050080
81from pprint import pformat
82#logger.debug("urlpatterns list %s", pformat(urlpatterns))