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.conf.urls import include, url 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 # This is here to maintain backward compatibility and will be deprecated 32 # in the future. 33 url(r'^orm/eventfile$', bldcollector.views.eventfile), 34 35 url(r'^health$', TemplateView.as_view(template_name="health.html"), name='Toaster Health'), 36 37 # if no application is selected, we have the magic toastergui app here 38 url(r'^$', never_cache(RedirectView.as_view(url='/toastergui/', permanent=True))), 39] 40 41import toastermain.settings 42 43if toastermain.settings.FRESH_ENABLED: 44 urlpatterns.insert(1, url(r'', include('fresh.urls'))) 45 #logger.info("Enabled django-fresh extension") 46 47if 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 52urlpatterns = [ 53 # Uncomment the next line to enable the admin: 54 url(r'^admin/', admin.site.urls), 55] + urlpatterns 56 57# Automatically discover urls.py in various apps, beside our own 58# and map module directories to the patterns 59 60import os 61currentdir = os.path.dirname(__file__) 62for t in os.walk(os.path.dirname(currentdir)): 63 #if we have a virtualenv skip it to avoid incorrect imports 64 if 'VIRTUAL_ENV' in os.environ and os.environ['VIRTUAL_ENV'] in t[0]: 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: 72 if p.pattern.regex.pattern == '^' + modulename + '/': 73 conflict = True 74 if not conflict: 75 urlpatterns.insert(0, url(r'^' + modulename + '/', include ( modulename + '.urls'))) 76 else: 77 logger.warning("Module \'%s\' has a regexp conflict, was not added to the urlpatterns" % modulename) 78 79from pprint import pformat 80#logger.debug("urlpatterns list %s", pformat(urlpatterns)) 81