author | Tero Marttila <terom@fixme.fi> |
Sat, 07 Feb 2009 06:54:52 +0200 | |
branch | sites |
changeset 30 | a86a25a9f75b |
parent 29 | b06ff4c05d42 |
child 31 | 107062ebb6f9 |
permissions | -rw-r--r-- |
29
b06ff4c05d42
start prototyping some site-based code
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
1 |
""" |
b06ff4c05d42
start prototyping some site-based code
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
2 |
Per-site stuff |
b06ff4c05d42
start prototyping some site-based code
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
3 |
""" |
b06ff4c05d42
start prototyping some site-based code
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
4 |
|
30
a86a25a9f75b
route requests through sites/www.qmsk.net, although still hardcoded
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
5 |
import imp |
a86a25a9f75b
route requests through sites/www.qmsk.net, although still hardcoded
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
6 |
|
29
b06ff4c05d42
start prototyping some site-based code
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
7 |
SITE_DIR = "sites" |
b06ff4c05d42
start prototyping some site-based code
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
8 |
|
b06ff4c05d42
start prototyping some site-based code
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
9 |
class Site (object) : |
b06ff4c05d42
start prototyping some site-based code
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
10 |
""" |
b06ff4c05d42
start prototyping some site-based code
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
11 |
A site is a website and its configuration |
b06ff4c05d42
start prototyping some site-based code
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
12 |
""" |
b06ff4c05d42
start prototyping some site-based code
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
13 |
|
30
a86a25a9f75b
route requests through sites/www.qmsk.net, although still hardcoded
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
14 |
def __init__ (self, name) : |
a86a25a9f75b
route requests through sites/www.qmsk.net, although still hardcoded
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
15 |
""" |
a86a25a9f75b
route requests through sites/www.qmsk.net, although still hardcoded
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
16 |
The given name must be like a valid hostname, e.g. 'www.qmsk.net' |
a86a25a9f75b
route requests through sites/www.qmsk.net, although still hardcoded
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
17 |
""" |
29
b06ff4c05d42
start prototyping some site-based code
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
18 |
|
30
a86a25a9f75b
route requests through sites/www.qmsk.net, although still hardcoded
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
19 |
# store |
a86a25a9f75b
route requests through sites/www.qmsk.net, although still hardcoded
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
20 |
self.name = name |
29
b06ff4c05d42
start prototyping some site-based code
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
21 |
|
30
a86a25a9f75b
route requests through sites/www.qmsk.net, although still hardcoded
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
22 |
# load the site |
a86a25a9f75b
route requests through sites/www.qmsk.net, although still hardcoded
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
23 |
self._load() |
a86a25a9f75b
route requests through sites/www.qmsk.net, although still hardcoded
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
24 |
|
a86a25a9f75b
route requests through sites/www.qmsk.net, although still hardcoded
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
25 |
def _load (self) : |
a86a25a9f75b
route requests through sites/www.qmsk.net, although still hardcoded
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
26 |
""" |
a86a25a9f75b
route requests through sites/www.qmsk.net, although still hardcoded
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
27 |
Loads this site, as a python module (i.e. dir with __init__.py) |
a86a25a9f75b
route requests through sites/www.qmsk.net, although still hardcoded
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
28 |
""" |
a86a25a9f75b
route requests through sites/www.qmsk.net, although still hardcoded
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
29 |
|
a86a25a9f75b
route requests through sites/www.qmsk.net, although still hardcoded
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
30 |
# first, we need to find it |
a86a25a9f75b
route requests through sites/www.qmsk.net, although still hardcoded
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
31 |
file, pathname, description = imp.find_module(self.name, [SITE_DIR]) |
a86a25a9f75b
route requests through sites/www.qmsk.net, although still hardcoded
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
32 |
|
a86a25a9f75b
route requests through sites/www.qmsk.net, although still hardcoded
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
33 |
# then, we can load it |
a86a25a9f75b
route requests through sites/www.qmsk.net, although still hardcoded
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
34 |
self.module = imp.load_module(self.name, file, pathname, description) |
a86a25a9f75b
route requests through sites/www.qmsk.net, although still hardcoded
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
35 |
|
a86a25a9f75b
route requests through sites/www.qmsk.net, although still hardcoded
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
36 |
# create our mapper |
a86a25a9f75b
route requests through sites/www.qmsk.net, although still hardcoded
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
37 |
self.mapper = self.module.build_mapper() |
a86a25a9f75b
route requests through sites/www.qmsk.net, although still hardcoded
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
38 |
|
a86a25a9f75b
route requests through sites/www.qmsk.net, although still hardcoded
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
39 |
def get_mapper (self) : |
a86a25a9f75b
route requests through sites/www.qmsk.net, although still hardcoded
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
40 |
""" |
a86a25a9f75b
route requests through sites/www.qmsk.net, although still hardcoded
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
41 |
Return the Mapper for this site |
a86a25a9f75b
route requests through sites/www.qmsk.net, although still hardcoded
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
42 |
""" |
a86a25a9f75b
route requests through sites/www.qmsk.net, although still hardcoded
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
43 |
|
a86a25a9f75b
route requests through sites/www.qmsk.net, although still hardcoded
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
44 |
return self.mapper |
a86a25a9f75b
route requests through sites/www.qmsk.net, although still hardcoded
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
45 |
|
a86a25a9f75b
route requests through sites/www.qmsk.net, although still hardcoded
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
46 |
def lookup (request) : |
a86a25a9f75b
route requests through sites/www.qmsk.net, although still hardcoded
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
47 |
""" |
a86a25a9f75b
route requests through sites/www.qmsk.net, although still hardcoded
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
48 |
Lookup and return a Site object for the given request |
a86a25a9f75b
route requests through sites/www.qmsk.net, although still hardcoded
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
49 |
""" |
a86a25a9f75b
route requests through sites/www.qmsk.net, although still hardcoded
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
50 |
|
a86a25a9f75b
route requests through sites/www.qmsk.net, although still hardcoded
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
51 |
# request hostnmae |
a86a25a9f75b
route requests through sites/www.qmsk.net, although still hardcoded
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
52 |
hostname = request.env.get('HTTP_POST') |
a86a25a9f75b
route requests through sites/www.qmsk.net, although still hardcoded
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
53 |
|
a86a25a9f75b
route requests through sites/www.qmsk.net, although still hardcoded
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
54 |
# XXX: hardcoded for now |
a86a25a9f75b
route requests through sites/www.qmsk.net, although still hardcoded
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
55 |
return Site("www.qmsk.net") |
a86a25a9f75b
route requests through sites/www.qmsk.net, although still hardcoded
Tero Marttila <terom@fixme.fi>
parents:
29
diff
changeset
|
56 |