Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | # |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2 | # BitBake Toaster Implementation |
| 3 | # |
| 4 | # Copyright (C) 2013 Intel Corporation |
| 5 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 6 | # SPDX-License-Identifier: GPL-2.0-only |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7 | # |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 8 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 9 | from django.conf.urls import include, url |
| 10 | from django.views.generic import RedirectView, TemplateView |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 11 | from django.views.decorators.cache import never_cache |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 12 | import bldcollector.views |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 13 | |
| 14 | import logging |
| 15 | |
| 16 | logger = logging.getLogger("toaster") |
| 17 | |
| 18 | # Uncomment the next two lines to enable the admin: |
| 19 | from django.contrib import admin |
| 20 | admin.autodiscover() |
| 21 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 22 | urlpatterns = [ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 23 | |
| 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 Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 33 | url(r'^orm/eventfile$', bldcollector.views.eventfile), |
| 34 | |
| 35 | 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] | 36 | |
| 37 | # if no application is selected, we have the magic toastergui app here |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 38 | url(r'^$', never_cache(RedirectView.as_view(url='/toastergui/', permanent=True))), |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 39 | ] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 40 | |
| 41 | import toastermain.settings |
| 42 | |
| 43 | if toastermain.settings.FRESH_ENABLED: |
| 44 | urlpatterns.insert(1, url(r'', include('fresh.urls'))) |
| 45 | #logger.info("Enabled django-fresh extension") |
| 46 | |
| 47 | if 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 Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 52 | urlpatterns = [ |
| 53 | # Uncomment the next line to enable the admin: |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 54 | url(r'^admin/', admin.site.urls), |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 55 | ] + urlpatterns |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 56 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 57 | # Automatically discover urls.py in various apps, beside our own |
| 58 | # and map module directories to the patterns |
| 59 | |
| 60 | import os |
| 61 | currentdir = os.path.dirname(__file__) |
| 62 | for t in os.walk(os.path.dirname(currentdir)): |
| 63 | #if we have a virtualenv skip it to avoid incorrect imports |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 64 | 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] | 65 | 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 Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 72 | if p.pattern.regex.pattern == '^' + modulename + '/': |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 73 | conflict = True |
| 74 | if not conflict: |
| 75 | urlpatterns.insert(0, url(r'^' + modulename + '/', include ( modulename + '.urls'))) |
| 76 | else: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 77 | 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] | 78 | |
| 79 | from pprint import pformat |
| 80 | #logger.debug("urlpatterns list %s", pformat(urlpatterns)) |