Changeset 10615 for src/django_gheat/gheat
- Timestamp:
- Apr 29, 2012, 7:59:27 PM (13 years ago)
- Location:
- src/django_gheat/gheat
- Files:
-
- 10 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/django_gheat/gheat/__init__.py ¶
r9145 r10615 1 import logging2 import os3 4 from gheat import gheatsettings as settings5 6 from django.core.exceptions import ImproperlyConfigured7 from django.db import connection8 9 # Logging config10 # ==============11 12 if settings.DEBUG:13 level = logging.WARNING14 else:15 level = logging.WARNING16 if os.getenv('DEBUG', None):17 level = logging.DEBUG18 19 logging.basicConfig(level=level) # Ack! This should be in Aspen. :^(20 log = logging.getLogger('gheat')21 22 23 # Configuration24 # =============25 # Set some things that backends will need.26 ALWAYS_BUILD = settings.GHEAT_ALWAYS_BUILD = False27 BUILD_EMPTIES = settings.GHEAT_BUILD_EMPTIES = False28 29 DIRMODE = settings.GHEAT_DIRMODE30 try:31 DIRMODE = int(eval(DIRMODE))32 except (NameError, SyntaxError, ValueError):33 raise ImproperlyConfigured("dirmode (%s) must be an integer." % dirmode)34 35 SIZE = 256 # size of (square) tile; NB: changing this will break gmerc calls!36 MAX_ZOOM = 22 # this depends on Google API; 0 is furthest out as of recent ver.37 38 39 # Try to find an image library.40 # =============================41 42 BACKEND = None43 BACKEND_PIL = False44 BACKEND_PYGAME = False45 46 _want = settings.GHEAT_BACKEND.lower()47 if _want not in ('pil', 'pygame', ''):48 raise ImproperlyConfigured( "The %s backend is not supported, only PIL and "49 + "Pygame (assuming those libraries are installed)."50 )51 52 if _want:53 if _want == 'pygame':54 from gheat import pygame_ as backend55 elif _want == 'pil':56 from gheat import pil_ as backend57 BACKEND = _want58 else:59 try:60 from gheat import pygame_ as backend61 BACKEND = 'pygame'62 except ImportError:63 try:64 from gheat import pil_ as backend65 BACKEND = 'pil'66 except ImportError:67 raise68 pass69 70 if BACKEND is None:71 raise ImportError("Neither Pygame nor PIL could be imported.")72 73 BACKEND_PYGAME = BACKEND == 'pygame'74 BACKEND_PIL = BACKEND == 'pil'75 76 log.info("Using the %s library" % BACKEND)77 78 79 # Set up color schemes and dots.80 # ==============================81 82 color_schemes = dict() # this is used below83 84 _color_schemes_dir = os.path.join(settings.GHEAT_CONF_DIR, 'color-schemes')85 for fname in os.listdir(_color_schemes_dir):86 if not fname.endswith('.png'):87 continue88 name = os.path.splitext(fname)[0]89 fspath = os.path.join(_color_schemes_dir, fname)90 color_schemes[name] = backend.ColorScheme(name, fspath)91 92 def load_dots(backend):93 """Given a backend module, return a mapping of zoom level to Dot object.94 """95 return dict([(zoom, backend.Dot(zoom)) for zoom in range(MAX_ZOOM)])96 dots = load_dots(backend) # factored for easier use from scripts97 98 # Some util methods99 # =================100 def translate(root, url):101 """Translate a URL to the filesystem.102 103 We specifically avoid removing symlinks in the path so that the filepath104 remains under the website root. Also, we don't want trailing slashes for105 directories.106 107 """108 parts = [root] + url.lstrip('/').split('/')109 return os.sep.join(parts).rstrip(os.sep)110 111 ROOT = settings.GHEAT_MEDIA_ROOT -
TabularUnified src/django_gheat/gheat/urls.py ¶
r9006 r10615 1 # -*- coding: utf-8 -*-2 from django.conf.urls.defaults import *3 4 urlpatterns = patterns('gheat.views',5 url(6 # Example : today/fire/12/3,2.png7 regex = r'^(?P<color_scheme>\w+)/(?P<zoom>\d+)/(?P<x>\d+),(?P<y>\d+).png$',8 view = 'serve_tile',9 name = 'serve_tile',10 ),11 )
Note:
See TracChangeset
for help on using the changeset viewer.