source: src/django_gheat/gheat/__init__.py@ 9006

Last change on this file since 9006 was 9006, checked in by dennisw, 14 years ago

django_gheat - versie van gheat die gebruik maakt van django framework, ondersteunt SQL connecties in tegenstelling tot gheat dat gebruik maakt van sqlite

File size: 3.1 KB
Line 
1import logging
2import os
3
4from gheat import gheatsettings as settings
5
6from django.core.exceptions import ImproperlyConfigured
7from django.db import connection
8
9# Logging config
10# ==============
11
12if settings.DEBUG:
13 level = logging.INFO
14else:
15 level = logging.WARNING
16logging.basicConfig(level=level) # Ack! This should be in Aspen. :^(
17log = logging.getLogger('gheat')
18
19
20# Configuration
21# =============
22# Set some things that backends will need.
23ALWAYS_BUILD = settings.GHEAT_ALWAYS_BUILD
24BUILD_EMPTIES = settings.GHEAT_BUILD_EMPTIES
25
26DIRMODE = settings.GHEAT_DIRMODE
27try:
28 DIRMODE = int(eval(DIRMODE))
29except (NameError, SyntaxError, ValueError):
30 raise ImproperlyConfigured("dirmode (%s) must be an integer." % dirmode)
31
32SIZE = 256 # size of (square) tile; NB: changing this will break gmerc calls!
33MAX_ZOOM = 31 # this depends on Google API; 0 is furthest out as of recent ver.
34
35
36# Try to find an image library.
37# =============================
38
39BACKEND = None
40BACKEND_PIL = False
41BACKEND_PYGAME = False
42
43_want = settings.GHEAT_BACKEND.lower()
44if _want not in ('pil', 'pygame', ''):
45 raise ImproperlyConfigured( "The %s backend is not supported, only PIL and "
46 + "Pygame (assuming those libraries are installed)."
47 )
48
49if _want:
50 if _want == 'pygame':
51 from gheat import pygame_ as backend
52 elif _want == 'pil':
53 from gheat import pil_ as backend
54 BACKEND = _want
55else:
56 try:
57 from gheat import pygame_ as backend
58 BACKEND = 'pygame'
59 except ImportError:
60 try:
61 from gheat import pil_ as backend
62 BACKEND = 'pil'
63 except ImportError:
64 raise
65 pass
66
67 if BACKEND is None:
68 raise ImportError("Neither Pygame nor PIL could be imported.")
69
70BACKEND_PYGAME = BACKEND == 'pygame'
71BACKEND_PIL = BACKEND == 'pil'
72
73log.info("Using the %s library" % BACKEND)
74
75
76# Set up color schemes and dots.
77# ==============================
78
79color_schemes = dict() # this is used below
80
81_color_schemes_dir = os.path.join(settings.GHEAT_CONF_DIR, 'color-schemes')
82for fname in os.listdir(_color_schemes_dir):
83 if not fname.endswith('.png'):
84 continue
85 name = os.path.splitext(fname)[0]
86 fspath = os.path.join(_color_schemes_dir, fname)
87 color_schemes[name] = backend.ColorScheme(name, fspath)
88
89def load_dots(backend):
90 """Given a backend module, return a mapping of zoom level to Dot object.
91 """
92 return dict([(zoom, backend.Dot(zoom)) for zoom in range(MAX_ZOOM)])
93dots = load_dots(backend) # factored for easier use from scripts
94
95# Some util methods
96# =================
97def translate(root, url):
98 """Translate a URL to the filesystem.
99
100 We specifically avoid removing symlinks in the path so that the filepath
101 remains under the website root. Also, we don't want trailing slashes for
102 directories.
103
104 """
105 parts = [root] + url.lstrip('/').split('/')
106 return os.sep.join(parts).rstrip(os.sep)
107
108ROOT = settings.GHEAT_MEDIA_ROOT
Note: See TracBrowser for help on using the repository browser.