__init__.py
1.91 KB
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
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
import os
import csv
import deform
from threading import Thread
from pkg_resources import resource_filename
from pyramid.i18n import get_localizer
from pyramid.threadlocal import get_current_request
from pyramid.config import Configurator
from pyramid_beaker import session_factory_from_settings
from pyramid_mailer import mailer_factory_from_settings
from .tools.this_framework import get_locale_name
from .views import RemoveSlashNotFoundViewFactory
from .iso8583 import (
read_conf,
main_loop as iso8583_main_loop,
)
def translator(term):
return get_localizer(get_current_request()).translate(term)
deform_template_dir = resource_filename('deform', 'templates/')
zpt_renderer = deform.ZPTRendererFactory(
[deform_template_dir], translator=translator)
deform.Form.set_default_renderer(zpt_renderer)
iso8583_threads = []
def start_iso8583(conf_file):
if not read_conf(conf_file):
return
thread = Thread(target=iso8583_main_loop, args=(conf_file,))
thread.daemon = True
iso8583_threads.append(thread)
thread.start()
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
session_factory = session_factory_from_settings(settings)
config = Configurator(
settings=settings,
root_factory='iso8583_web.models.ziggurat.RootFactory',
session_factory=session_factory,
locale_negotiator=get_locale_name)
config.include('.models')
config.include('pyramid_beaker')
config.include('pyramid_chameleon')
config.include('.routes')
config.include('.security')
config.add_notfound_view(RemoveSlashNotFoundViewFactory())
config.add_translation_dirs('locale')
config.registry['mailer'] = mailer_factory_from_settings(settings)
config.scan()
start_iso8583(global_config['__file__'])
return config.make_wsgi_app()