blob: 5fb520b384d3bc4b8e63ee5af64cfcd2c4e554e9 [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
Brad Bishopd7bf8c12018-02-25 22:55:05 -05009from django.conf.urls import include, url
10from 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
31 # This is here to maintain backward compatibility and will be deprecated
32 # in the future.
Brad Bishopd7bf8c12018-02-25 22:55:05 -050033 url(r'^orm/eventfile$', bldcollector.views.eventfile),
34
35 url(r'^health$', TemplateView.as_view(template_name="health.html"), name='Toaster Health'),
Patrick Williamsc124f4f2015-09-15 14:41:29 -050036
37 # if no application is selected, we have the magic toastergui app here
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050038 url(r'^$', never_cache(RedirectView.as_view(url='/toastergui/', permanent=True))),
Brad Bishopd7bf8c12018-02-25 22:55:05 -050039]
Patrick Williamsc124f4f2015-09-15 14:41:29 -050040
41import toastermain.settings
42
43if toastermain.settings.FRESH_ENABLED:
44 urlpatterns.insert(1, url(r'', include('fresh.urls')))
45 #logger.info("Enabled django-fresh extension")
46
47if toastermain.settings.DEBUG_PANEL_ENABLED:
48 import debug_toolbar
49 urlpatterns.insert(1, url(r'', include(debug_toolbar.urls)))
50 #logger.info("Enabled django_toolbar extension")
51
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050052urlpatterns = [
53 # Uncomment the next line to enable the admin:
Andrew Geissler82c905d2020-04-13 13:39:40 -050054 url(r'^admin/', admin.site.urls),
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050055] + urlpatterns
Patrick Williamsc124f4f2015-09-15 14:41:29 -050056
Patrick Williamsc124f4f2015-09-15 14:41:29 -050057# Automatically discover urls.py in various apps, beside our own
58# and map module directories to the patterns
59
60import os
61currentdir = os.path.dirname(__file__)
62for t in os.walk(os.path.dirname(currentdir)):
63 #if we have a virtualenv skip it to avoid incorrect imports
Patrick Williamsc0f7c042017-02-23 20:41:17 -060064 if 'VIRTUAL_ENV' in os.environ and os.environ['VIRTUAL_ENV'] in t[0]:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050065 continue
66
67 if "urls.py" in t[2] and t[0] != currentdir:
68 modulename = os.path.basename(t[0])
69 # make sure we don't have this module name in
70 conflict = False
71 for p in urlpatterns:
Andrew Geissler82c905d2020-04-13 13:39:40 -050072 if p.pattern.regex.pattern == '^' + modulename + '/':
Patrick Williamsc124f4f2015-09-15 14:41:29 -050073 conflict = True
74 if not conflict:
75 urlpatterns.insert(0, url(r'^' + modulename + '/', include ( modulename + '.urls')))
76 else:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060077 logger.warning("Module \'%s\' has a regexp conflict, was not added to the urlpatterns" % modulename)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050078
79from pprint import pformat
80#logger.debug("urlpatterns list %s", pformat(urlpatterns))