summaryrefslogtreecommitdiff
path: root/foundry/application.py
blob: bc4a569add26aea5ca896171dd323996fd01fde7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python
# vim: set filencoding=utf8
"""
Foundry Main Application

@author: Mike Crute (mcrute@gmail.com)
@organization: SoftGroup Interactive, Inc.
@date: May 02, 2010

Entry point for the application. All of the main app
wireup happens here. This is also where you can get
the WSGI application object. This isn't strictly
required. You could wire this all up by hand.
"""

import jinja2
from snakeguice import Injector
from snakeguice.extras.snakeweb import Application, AutoRoutesModule

from foundry.utils import frozendict
from foundry import controllers, interfaces
from foundry.views import JinjaRenderer
from foundry.template_filters import TEMPLATE_FILTERS

from foundry.vcs.hg.providers import RepoProvider


class MainModule(object):

    def configure(self, binder):
        #-------------------------------------------------------------
        # Mercurial Bindings
        #-------------------------------------------------------------
        binder.bind(interfaces.RepositoryProvider, to=RepoProvider)

        #-------------------------------------------------------------
        # Template Engine Bindings
        #-------------------------------------------------------------
        loader = jinja2.PackageLoader('foundry', 'views')
        tpl_env = jinja2.Environment(loader=loader)
        tpl_env.filters.update(TEMPLATE_FILTERS)
        renderer = JinjaRenderer(tpl_env)

        binder.bind(interfaces.TemplateRenderer, to_instance=renderer)


class MapperModule(AutoRoutesModule):

    configured_routes = frozendict({
        '/': controllers.ChangelogController,
        })


def get_application():
    injector = Injector([MainModule(), MapperModule()])
    return Application(injector)


if __name__ == '__main__':
    from wsgiref.simple_server import make_server

    httpd = make_server('', 8080, get_application())
    httpd.serve_forever()