Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | # |
| 2 | # ex:ts=4:sw=4:sts=4:et |
| 3 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- |
| 4 | # |
| 5 | # BitBake Toaster Implementation |
| 6 | # |
| 7 | # Copyright (C) 2013 Intel Corporation |
| 8 | # |
| 9 | # This program is free software; you can redistribute it and/or modify |
| 10 | # it under the terms of the GNU General Public License version 2 as |
| 11 | # published by the Free Software Foundation. |
| 12 | # |
| 13 | # This program is distributed in the hope that it will be useful, |
| 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | # GNU General Public License for more details. |
| 17 | # |
| 18 | # You should have received a copy of the GNU General Public License along |
| 19 | # with this program; if not, write to the Free Software Foundation, Inc., |
| 20 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 21 | |
| 22 | from django.conf.urls import patterns, include, url |
| 23 | from django.views.generic import RedirectView |
| 24 | from django.views.decorators.cache import never_cache |
| 25 | |
| 26 | import logging |
| 27 | |
| 28 | logger = logging.getLogger("toaster") |
| 29 | |
| 30 | # Uncomment the next two lines to enable the admin: |
| 31 | from django.contrib import admin |
| 32 | admin.autodiscover() |
| 33 | |
| 34 | urlpatterns = patterns('', |
| 35 | |
| 36 | # Examples: |
| 37 | # url(r'^toaster/', include('toaster.foo.urls')), |
| 38 | |
| 39 | # Uncomment the admin/doc line below to enable admin documentation: |
| 40 | # url(r'^admin/doc/', include('django.contrib.admindocs.urls')), |
| 41 | |
| 42 | |
| 43 | # This is here to maintain backward compatibility and will be deprecated |
| 44 | # in the future. |
| 45 | url(r'^orm/eventfile$', 'bldcollector.views.eventfile'), |
| 46 | |
| 47 | # if no application is selected, we have the magic toastergui app here |
| 48 | url(r'^$', never_cache(RedirectView.as_view(url='/toastergui/'))), |
| 49 | ) |
| 50 | |
| 51 | import toastermain.settings |
| 52 | |
| 53 | if toastermain.settings.FRESH_ENABLED: |
| 54 | urlpatterns.insert(1, url(r'', include('fresh.urls'))) |
| 55 | #logger.info("Enabled django-fresh extension") |
| 56 | |
| 57 | if toastermain.settings.DEBUG_PANEL_ENABLED: |
| 58 | import debug_toolbar |
| 59 | urlpatterns.insert(1, url(r'', include(debug_toolbar.urls))) |
| 60 | #logger.info("Enabled django_toolbar extension") |
| 61 | |
| 62 | |
| 63 | if toastermain.settings.MANAGED: |
| 64 | urlpatterns = [ |
| 65 | # Uncomment the next line to enable the admin: |
| 66 | url(r'^admin/', include(admin.site.urls)), |
| 67 | ] + urlpatterns |
| 68 | # Automatically discover urls.py in various apps, beside our own |
| 69 | # and map module directories to the patterns |
| 70 | |
| 71 | import os |
| 72 | currentdir = os.path.dirname(__file__) |
| 73 | for t in os.walk(os.path.dirname(currentdir)): |
| 74 | #if we have a virtualenv skip it to avoid incorrect imports |
| 75 | if os.environ.has_key('VIRTUAL_ENV') and os.environ['VIRTUAL_ENV'] in t[0]: |
| 76 | continue |
| 77 | |
| 78 | if "urls.py" in t[2] and t[0] != currentdir: |
| 79 | modulename = os.path.basename(t[0]) |
| 80 | # make sure we don't have this module name in |
| 81 | conflict = False |
| 82 | for p in urlpatterns: |
| 83 | if p.regex.pattern == '^' + modulename + '/': |
| 84 | conflict = True |
| 85 | if not conflict: |
| 86 | urlpatterns.insert(0, url(r'^' + modulename + '/', include ( modulename + '.urls'))) |
| 87 | else: |
| 88 | logger.warn("Module \'%s\' has a regexp conflict, was not added to the urlpatterns" % modulename) |
| 89 | |
| 90 | from pprint import pformat |
| 91 | #logger.debug("urlpatterns list %s", pformat(urlpatterns)) |