Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | # |
| 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 Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 22 | from django.conf.urls import include, url |
| 23 | from django.views.generic import RedirectView, TemplateView |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 24 | from django.views.decorators.cache import never_cache |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 25 | import bldcollector.views |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 26 | |
| 27 | import logging |
| 28 | |
| 29 | logger = logging.getLogger("toaster") |
| 30 | |
| 31 | # Uncomment the next two lines to enable the admin: |
| 32 | from django.contrib import admin |
| 33 | admin.autodiscover() |
| 34 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 35 | urlpatterns = [ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 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. |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 46 | url(r'^orm/eventfile$', bldcollector.views.eventfile), |
| 47 | |
| 48 | url(r'^health$', TemplateView.as_view(template_name="health.html"), name='Toaster Health'), |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 49 | |
| 50 | # if no application is selected, we have the magic toastergui app here |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 51 | url(r'^$', never_cache(RedirectView.as_view(url='/toastergui/', permanent=True))), |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 52 | ] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 53 | |
| 54 | import toastermain.settings |
| 55 | |
| 56 | if toastermain.settings.FRESH_ENABLED: |
| 57 | urlpatterns.insert(1, url(r'', include('fresh.urls'))) |
| 58 | #logger.info("Enabled django-fresh extension") |
| 59 | |
| 60 | if 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 Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 65 | urlpatterns = [ |
| 66 | # Uncomment the next line to enable the admin: |
| 67 | url(r'^admin/', include(admin.site.urls)), |
| 68 | ] + urlpatterns |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 69 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 70 | # Automatically discover urls.py in various apps, beside our own |
| 71 | # and map module directories to the patterns |
| 72 | |
| 73 | import os |
| 74 | currentdir = os.path.dirname(__file__) |
| 75 | for t in os.walk(os.path.dirname(currentdir)): |
| 76 | #if we have a virtualenv skip it to avoid incorrect imports |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 77 | if 'VIRTUAL_ENV' in os.environ and os.environ['VIRTUAL_ENV'] in t[0]: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 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: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 90 | logger.warning("Module \'%s\' has a regexp conflict, was not added to the urlpatterns" % modulename) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 91 | |
| 92 | from pprint import pformat |
| 93 | #logger.debug("urlpatterns list %s", pformat(urlpatterns)) |