blob: e2fb0aebfdacb5008876bac4c23e72de8e1e83f2 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001#
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
Brad Bishopd7bf8c12018-02-25 22:55:05 -050022from django.conf.urls import include, url
23from django.views.generic import RedirectView, TemplateView
Patrick Williamsc124f4f2015-09-15 14:41:29 -050024from django.views.decorators.cache import never_cache
Brad Bishopd7bf8c12018-02-25 22:55:05 -050025import bldcollector.views
Patrick Williamsc124f4f2015-09-15 14:41:29 -050026
27import logging
28
29logger = logging.getLogger("toaster")
30
31# Uncomment the next two lines to enable the admin:
32from django.contrib import admin
33admin.autodiscover()
34
Brad Bishopd7bf8c12018-02-25 22:55:05 -050035urlpatterns = [
Patrick Williamsc124f4f2015-09-15 14:41:29 -050036
37 # Examples:
38 # url(r'^toaster/', include('toaster.foo.urls')),
39
40 # Uncomment the admin/doc line below to enable admin documentation:
41 # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
42
43
44 # This is here to maintain backward compatibility and will be deprecated
45 # in the future.
Brad Bishopd7bf8c12018-02-25 22:55:05 -050046 url(r'^orm/eventfile$', bldcollector.views.eventfile),
47
48 url(r'^health$', TemplateView.as_view(template_name="health.html"), name='Toaster Health'),
Patrick Williamsc124f4f2015-09-15 14:41:29 -050049
50 # if no application is selected, we have the magic toastergui app here
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050051 url(r'^$', never_cache(RedirectView.as_view(url='/toastergui/', permanent=True))),
Brad Bishopd7bf8c12018-02-25 22:55:05 -050052]
Patrick Williamsc124f4f2015-09-15 14:41:29 -050053
54import toastermain.settings
55
56if toastermain.settings.FRESH_ENABLED:
57 urlpatterns.insert(1, url(r'', include('fresh.urls')))
58 #logger.info("Enabled django-fresh extension")
59
60if toastermain.settings.DEBUG_PANEL_ENABLED:
61 import debug_toolbar
62 urlpatterns.insert(1, url(r'', include(debug_toolbar.urls)))
63 #logger.info("Enabled django_toolbar extension")
64
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050065urlpatterns = [
66 # Uncomment the next line to enable the admin:
67 url(r'^admin/', include(admin.site.urls)),
68] + urlpatterns
Patrick Williamsc124f4f2015-09-15 14:41:29 -050069
Patrick Williamsc124f4f2015-09-15 14:41:29 -050070# Automatically discover urls.py in various apps, beside our own
71# and map module directories to the patterns
72
73import os
74currentdir = os.path.dirname(__file__)
75for t in os.walk(os.path.dirname(currentdir)):
76 #if we have a virtualenv skip it to avoid incorrect imports
Patrick Williamsc0f7c042017-02-23 20:41:17 -060077 if 'VIRTUAL_ENV' in os.environ and os.environ['VIRTUAL_ENV'] in t[0]:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050078 continue
79
80 if "urls.py" in t[2] and t[0] != currentdir:
81 modulename = os.path.basename(t[0])
82 # make sure we don't have this module name in
83 conflict = False
84 for p in urlpatterns:
85 if p.regex.pattern == '^' + modulename + '/':
86 conflict = True
87 if not conflict:
88 urlpatterns.insert(0, url(r'^' + modulename + '/', include ( modulename + '.urls')))
89 else:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060090 logger.warning("Module \'%s\' has a regexp conflict, was not added to the urlpatterns" % modulename)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050091
92from pprint import pformat
93#logger.debug("urlpatterns list %s", pformat(urlpatterns))