1# 2# BitBake Toaster Implementation 3# 4# Copyright (C) 2013 Intel Corporation 5# 6# SPDX-License-Identifier: GPL-2.0-only 7# 8 9from django.urls import re_path as url, include 10from django.views.generic import RedirectView, TemplateView 11from django.views.decorators.cache import never_cache 12import bldcollector.views 13 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 22urlpatterns = [ 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 url(r'^logs/', include('log_viewer.urls')), 32 33 # This is here to maintain backward compatibility and will be deprecated 34 # in the future. 35 url(r'^orm/eventfile$', bldcollector.views.eventfile), 36 37 url(r'^health$', TemplateView.as_view(template_name="health.html"), name='Toaster Health'), 38 39 # if no application is selected, we have the magic toastergui app here 40 url(r'^$', never_cache(RedirectView.as_view(url='/toastergui/', permanent=True))), 41] 42 43import toastermain.settings 44 45if toastermain.settings.FRESH_ENABLED: 46 urlpatterns.insert(1, url(r'', include('fresh.urls'))) 47 #logger.info("Enabled django-fresh extension") 48 49if toastermain.settings.DEBUG_PANEL_ENABLED: 50 import debug_toolbar 51 urlpatterns.insert(1, url(r'', include(debug_toolbar.urls))) 52 #logger.info("Enabled django_toolbar extension") 53 54urlpatterns = [ 55 # Uncomment the next line to enable the admin: 56 url(r'^admin/', admin.site.urls), 57] + urlpatterns 58 59# Automatically discover urls.py in various apps, beside our own 60# and map module directories to the patterns 61 62import os 63currentdir = os.path.dirname(__file__) 64for t in os.walk(os.path.dirname(currentdir)): 65 #if we have a virtualenv skip it to avoid incorrect imports 66 if 'VIRTUAL_ENV' in os.environ and os.environ['VIRTUAL_ENV'] in t[0]: 67 continue 68 69 if "urls.py" in t[2] and t[0] != currentdir: 70 modulename = os.path.basename(t[0]) 71 # make sure we don't have this module name in 72 conflict = False 73 for p in urlpatterns: 74 if p.pattern.regex.pattern == '^' + modulename + '/': 75 conflict = True 76 if not conflict: 77 urlpatterns.insert(0, url(r'^' + modulename + '/', include ( modulename + '.urls'))) 78 else: 79 logger.warning("Module \'%s\' has a regexp conflict, was not added to the urlpatterns" % modulename) 80 81from pprint import pformat 82#logger.debug("urlpatterns list %s", pformat(urlpatterns)) 83