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