urls.py 2.6 KB

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