urls.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #
  2. # BitBake Toaster Implementation
  3. #
  4. # Copyright (C) 2013 Intel Corporation
  5. #
  6. # SPDX-License-Identifier: GPL-2.0-only
  7. #
  8. from django.urls import re_path as url, include
  9. from django.views.generic import RedirectView, TemplateView
  10. from django.views.decorators.cache import never_cache
  11. import bldcollector.views
  12. import logging
  13. logger = logging.getLogger("toaster")
  14. # Uncomment the next two lines to enable the admin:
  15. from django.contrib import admin
  16. admin.autodiscover()
  17. urlpatterns = [
  18. # Examples:
  19. # url(r'^toaster/', include('toaster.foo.urls')),
  20. # Uncomment the admin/doc line below to enable admin documentation:
  21. # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
  22. url(r'^logs/', include('log_viewer.urls')),
  23. # This is here to maintain backward compatibility and will be deprecated
  24. # in the future.
  25. url(r'^orm/eventfile$', bldcollector.views.eventfile),
  26. url(r'^health$', TemplateView.as_view(template_name="health.html"), name='Toaster Health'),
  27. # if no application is selected, we have the magic toastergui app here
  28. url(r'^$', never_cache(RedirectView.as_view(url='/toastergui/', permanent=True))),
  29. ]
  30. import toastermain.settings
  31. if toastermain.settings.FRESH_ENABLED:
  32. urlpatterns.insert(1, url(r'', include('fresh.urls')))
  33. #logger.info("Enabled django-fresh extension")
  34. if toastermain.settings.DEBUG_PANEL_ENABLED:
  35. import debug_toolbar
  36. urlpatterns.insert(1, url(r'', include(debug_toolbar.urls)))
  37. #logger.info("Enabled django_toolbar extension")
  38. urlpatterns = [
  39. # Uncomment the next line to enable the admin:
  40. url(r'^admin/', admin.site.urls),
  41. ] + urlpatterns
  42. # Automatically discover urls.py in various apps, beside our own
  43. # and map module directories to the patterns
  44. import os
  45. currentdir = os.path.dirname(__file__)
  46. for t in os.walk(os.path.dirname(currentdir)):
  47. #if we have a virtualenv skip it to avoid incorrect imports
  48. if 'VIRTUAL_ENV' in os.environ and os.environ['VIRTUAL_ENV'] in t[0]:
  49. continue
  50. if "urls.py" in t[2] and t[0] != currentdir:
  51. modulename = os.path.basename(t[0])
  52. # make sure we don't have this module name in
  53. conflict = False
  54. for p in urlpatterns:
  55. if p.pattern.regex.pattern == '^' + modulename + '/':
  56. conflict = True
  57. if not conflict:
  58. urlpatterns.insert(0, url(r'^' + modulename + '/', include ( modulename + '.urls')))
  59. else:
  60. logger.warning("Module \'%s\' has a regexp conflict, was not added to the urlpatterns" % modulename)
  61. from pprint import pformat
  62. #logger.debug("urlpatterns list %s", pformat(urlpatterns))