blob: e2fb0aebfdacb5008876bac4c23e72de8e1e83f2 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001#
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
22from django.conf.urls import include, url
23from django.views.generic import RedirectView, TemplateView
24from django.views.decorators.cache import never_cache
25import bldcollector.views
26
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
35urlpatterns = [
36
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.
46 url(r'^orm/eventfile$', bldcollector.views.eventfile),
47
48 url(r'^health$', TemplateView.as_view(template_name="health.html"), name='Toaster Health'),
49
50 # if no application is selected, we have the magic toastergui app here
51 url(r'^$', never_cache(RedirectView.as_view(url='/toastergui/', permanent=True))),
52]
53
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
65urlpatterns = [
66 # Uncomment the next line to enable the admin:
67 url(r'^admin/', include(admin.site.urls)),
68] + urlpatterns
69
70# 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
77 if 'VIRTUAL_ENV' in os.environ and os.environ['VIRTUAL_ENV'] in t[0]:
78 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:
90 logger.warning("Module \'%s\' has a regexp conflict, was not added to the urlpatterns" % modulename)
91
92from pprint import pformat
93#logger.debug("urlpatterns list %s", pformat(urlpatterns))