• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

allura


Commit MetaInfo

修订版2f8d060ff4313f707506c8043e392afe141ff380 (tree)
时间2011-04-30 02:07:36
作者Rick Copeland <rcopeland@geek...>
CommiterRick Copeland

Log Message

[#1831] Remove pylons-isms

Signed-off-by: Rick Copeland <rcopeland@geek.net>

更改概述

  • delete: Allura/allura/config/app_cfg.py
  • delete: Allura/allura/config/deployment.ini
  • delete: Allura/allura/config/environment.py
  • delete: Allura/allura/config/middleware.py

差异

--- a/Allura/allura/config/app_cfg.py
+++ /dev/null
@@ -1,100 +0,0 @@
1-# -*- coding: utf-8 -*-
2-"""
3-Global configuration file for TG2-specific settings in allura.
4-
5-This file complements development/deployment.ini.
6-
7-Please note that **all the argument values are strings**. If you want to
8-convert them into boolean, for example, you should use the
9-:func:`paste.deploy.converters.asbool` function, as in::
10-
11- from paste.deploy.converters import asbool
12- setting = asbool(global_conf.get('the_setting'))
13-
14-"""
15-import pdb; pdb.set_trace()
16-import logging
17-import pkg_resources
18-
19-import tg
20-import jinja2
21-from tg.configuration import AppConfig, config
22-from routes import Mapper
23-from webhelpers.html import literal
24-
25-import ew
26-
27-import allura
28-# needed for tg.configuration to work
29-from allura.lib import app_globals
30-
31-log = logging.getLogger(__name__)
32-
33-class ForgeConfig(AppConfig):
34-
35- def __init__(self, root_controller='root'):
36- AppConfig.__init__(self)
37- self.root_controller = root_controller
38- self.package = allura
39- self.renderers = [ 'json', 'genshi', 'mako', 'jinja' ]
40- self.default_renderer = 'genshi'
41- self.use_sqlalchemy = False
42- self.use_toscawidgets = True
43- self.use_transaction_manager = False
44- # self.handle_status_codes = [ 403, 404 ]
45- self.handle_status_codes = [ 403, 404 ]
46-
47- def after_init_config(self):
48- config['pylons.strict_c'] = True
49-
50- def setup_routes(self):
51- map = Mapper(directory=config['pylons.paths']['controllers'],
52- always_scan=config['debug'])
53- # Setup a default route for the root of object dispatch
54- map.connect('*url', controller=self.root_controller,
55- action='routes_placeholder')
56- config['routes.map'] = map
57-
58- def setup_jinja_renderer(self):
59- config['pylons.app_globals'].jinja2_env = jinja2.Environment(
60- loader=PackagePathLoader(),
61- auto_reload=self.auto_reload_templates,
62- autoescape=True,
63- extensions=['jinja2.ext.do'])
64- # Jinja's unable to request c's attributes without strict_c
65- config['pylons.strict_c'] = True
66- self.render_functions.jinja = tg.render.render_jinja
67-
68-class JinjaEngine(ew.TemplateEngine):
69-
70- @property
71- def _environ(self):
72- return config['pylons.app_globals'].jinja2_env
73-
74- def load(self, template_name):
75- try:
76- return self._environ.get_template(template_name)
77- except jinja2.TemplateNotFound:
78- raise ew.errors.TemplateNotFound, '%s not found' % template_name
79-
80- def parse(self, template_text, filepath=None):
81- return self._environ.from_string(template_text)
82-
83- def render(self, template, context):
84- context = self.context(context)
85- with ew.utils.push_context(ew.widget_context, render_context=context):
86- text = template.render(**context)
87- return literal(text)
88-
89-class PackagePathLoader(jinja2.BaseLoader):
90-
91- def __init__(self):
92- self.fs_loader = jinja2.FileSystemLoader(['/'])
93-
94- def get_source(self, environment, template):
95- package, path = template.split(':')
96- filename = pkg_resources.resource_filename(package, path)
97- return self.fs_loader.get_source(environment, filename)
98-
99-
100-base_config = ForgeConfig()
--- a/Allura/allura/config/deployment.ini
+++ /dev/null
@@ -1,88 +0,0 @@
1-#
2-# allura - TurboGears configuration
3-#
4-# The %(here)s variable will be replaced with the parent directory of this file
5-#
6-[DEFAULT]
7-# WARGING == If debug is not set to false, you'll get the interactive
8-# debugger on production, which is a huge security hole.
9-
10-debug = false
11-email_to = you@yourdomain.com
12-smtp_server = localhost
13-error_email_from = paste@localhost
14-
15-[server:main]
16-use = egg:Paste#http
17-host = 0.0.0.0
18-port = 8080
19-
20-[app:main]
21-use = egg:Allura
22-full_stack = true
23-cache_dir = %(here)s/data
24-beaker.session.key = allura
25-beaker.session.secret = ${app_instance_secret}
26-app_instance_uuid = ${app_instance_uuid}
27-
28-# If you'd like to fine-tune the individual locations of the cache data dirs
29-# for the Cache data, or the Session saves, un-comment the desired settings
30-# here:
31-#beaker.cache.data_dir = %(here)s/data/cache
32-#beaker.session.data_dir = %(here)s/data/sessions
33-# Specify the database for SQLAlchemy to use via
34-# turbogears.database
35-# %(here) may include a ':' character on Windows environments; this can
36-# invalidate the URI when specifying a SQLite db via path name
37-sqlalchemy.url = sqlite:///%(here)s/somedb.db
38-sqlalchemy.echo = False
39-
40-# WARNING: *THE LINE BELOW MUST BE UNCOMMENTED ON A PRODUCTION ENVIRONMENT*
41-# Debug mode will enable the interactive debugging tool, allowing ANYONE to
42-# execute malicious code after an exception is raised.
43-#set debug = false
44-
45-# Logging configuration
46-# Add additional loggers, handlers, formatters here
47-# Uses python's logging config file format
48-# http://docs.python.org/lib/logging-config-fileformat.html
49-
50-[loggers]
51-keys = root, allura, sqlalchemy
52-
53-[handlers]
54-keys = console
55-
56-[formatters]
57-keys = generic
58-
59-# If you create additional loggers, add them as a key to [loggers]
60-[logger_root]
61-level = INFO
62-handlers = console
63-
64-[logger_allura]
65-level = INFO
66-handlers =
67-qualname = allura
68-
69-[logger_sqlalchemy]
70-level = WARN
71-handlers =
72-qualname = sqlalchemy.engine
73-# "level = INFO" logs SQL queries.
74-# "level = DEBUG" logs SQL queries and results.
75-# "level = WARN" logs neither. (Recommended for production systems.)
76-
77-
78-# If you create additional handlers, add them as a key to [handlers]
79-[handler_console]
80-class = StreamHandler
81-args = (sys.stderr,)
82-level = NOTSET
83-formatter = generic
84-
85-# If you create additional formatters, add them as a key to [formatters]
86-[formatter_generic]
87-format = %(asctime)s,%(msecs)03d %(levelname)-5.5s [%(name)s] %(message)s
88-datefmt = %H:%M:%S
--- a/Allura/allura/config/environment.py
+++ /dev/null
@@ -1,10 +0,0 @@
1-# -*- coding: utf-8 -*-
2-"""WSGI environment setup for allura."""
3-
4-from allura.config.app_cfg import base_config
5-
6-__all__ = ['load_environment']
7-
8-#Use base_config to setup the environment loader function
9-load_environment = base_config.make_load_environment()
10-
--- a/Allura/allura/config/middleware.py
+++ /dev/null
@@ -1,172 +0,0 @@
1-# -*- coding: utf-8 -*-
2-"""WSGI middleware initialization for the allura application."""
3-import mimetypes
4-
5-import tg
6-import pkg_resources
7-from tg import config
8-from paste.deploy.converters import asbool
9-from paste.registry import RegistryManager
10-from beaker.middleware import SessionMiddleware
11-from routes.middleware import RoutesMiddleware
12-from pylons.middleware import StatusCodeRedirect
13-
14-import ew
15-import ming
16-from ming.orm.middleware import MingMiddleware
17-
18-from allura.config.app_cfg import base_config
19-from allura.config.environment import load_environment
20-from allura.config.app_cfg import ForgeConfig
21-from allura.lib.custom_middleware import StatsMiddleware
22-from allura.lib.custom_middleware import SSLMiddleware
23-from allura.lib.custom_middleware import StaticFilesMiddleware
24-from allura.lib.custom_middleware import CSRFMiddleware
25-from allura.lib.custom_middleware import LoginRedirectMiddleware
26-from allura.lib import patches
27-from allura.lib import helpers as h
28-
29-__all__ = ['make_app']
30-
31-# Use base_config to setup the necessary PasteDeploy application factory.
32-# make_base_app will wrap the TG2 app with all the middleware it needs.
33-make_base_app = base_config.setup_tg_wsgi_app(load_environment)
34-
35-
36-def make_app(global_conf, full_stack=True, **app_conf):
37- root = app_conf.get('override_root', 'root')
38- return _make_core_app(root, global_conf, full_stack, **app_conf)
39-
40-def _make_core_app(root, global_conf, full_stack=True, **app_conf):
41- """
42- Set allura up with the settings found in the PasteDeploy configuration
43- file used.
44-
45- :param root: The controller module containing the TG root
46- :param global_conf: The global settings for allura (those
47- defined under the ``[DEFAULT]`` section).
48- :type global_conf: dict
49- :param full_stack: Should the whole TG2 stack be set up?
50- :type full_stack: str or bool
51- :return: The allura application with all the relevant middleware
52- loaded.
53-
54- This is the PasteDeploy factory for the allura application.
55-
56- ``app_conf`` contains all the application-specific settings (those defined
57- under ``[app:main]``.
58-
59-
60- """
61- # Run all the initialization code here
62- mimetypes.init(
63- [pkg_resources.resource_filename('allura', 'etc/mime.types')]
64- + mimetypes.knownfiles)
65- patches.apply()
66- # Configure MongoDB
67- ming.configure(**app_conf)
68-
69- # Configure EW variable provider
70- ew.render.TemplateEngine.register_variable_provider(get_tg_vars)
71-
72- # Create base app
73- base_config = ForgeConfig(root)
74- load_environment = base_config.make_load_environment()
75-
76- # Code adapted from tg.configuration, replacing the following lines:
77- # make_base_app = base_config.setup_tg_wsgi_app(load_environment)
78- # app = make_base_app(global_conf, full_stack=True, **app_conf)
79-
80- # Configure the Pylons environment
81- load_environment(global_conf, app_conf)
82-
83- app = tg.TGApp()
84- if asbool(config.get('auth.method', 'local')=='sfx'):
85- import sfx.middleware
86- d = h.config_with_prefix(config, 'auth.')
87- d.update(h.config_with_prefix(config, 'sfx.'))
88- app = sfx.middleware.SfxMiddleware(app, d)
89- # Required for pylons
90- app = RoutesMiddleware(app, config['routes.map'])
91- # Required for sessions
92- app = SessionMiddleware(app, config)
93- # Converts exceptions to HTTP errors, shows traceback in debug mode
94- app = tg.error.ErrorHandler(app, global_conf, **config['pylons.errorware'])
95- # Redirect some status codes to /error/document
96- if asbool(config['debug']):
97- app = StatusCodeRedirect(app, base_config.handle_status_codes)
98- else:
99- app = StatusCodeRedirect(app, base_config.handle_status_codes + [500])
100- # Redirect 401 to the login page
101- app = LoginRedirectMiddleware(app)
102- # Add instrumentation
103- if app_conf.get('stats.sample_rate', '0.25') != '0':
104- stats_config = dict(global_conf, **app_conf)
105- app = StatsMiddleware(app, stats_config)
106- # Clear cookies when the CSRF field isn't posted
107- if not app_conf.get('disable_csrf_protection'):
108- app = CSRFMiddleware(app, '_session_id')
109- # Setup the allura SOPs
110- app = allura_globals_middleware(app)
111- # Ensure https for logged in users, http for anonymous ones
112- if asbool(app_conf.get('auth.method', 'local')=='sfx'):
113- app = SSLMiddleware(app, app_conf.get('no_redirect.pattern'))
114- # Setup resource manager, widget context SOP
115- app = ew.WidgetMiddleware(
116- app,
117- compress=not asbool(global_conf['debug']),
118- # compress=True,
119- script_name=app_conf.get('ew.script_name', '/_ew_resources/'),
120- url_base=app_conf.get('ew.url_base', '/_ew_resources/'))
121- # Make sure that the wsgi.scheme is set appropriately when we
122- # have the funky HTTP_X_SFINC_SSL environ var
123- if asbool(app_conf.get('auth.method', 'local')=='sfx'):
124- app = set_scheme_middleware(app)
125- # Handle static files (by tool)
126- app = StaticFilesMiddleware(app, app_conf.get('static.script_name'))
127- # Handle setup and flushing of Ming ORM sessions
128- app = MingMiddleware(app)
129- # Set up the registry for stacked object proxies (SOPs).
130- # streaming=true ensures they won't be cleaned up till
131- # the WSGI application's iterator is exhausted
132- app = RegistryManager(app, streaming=True)
133- return app
134-
135-def set_scheme_middleware(app):
136- def SchemeMiddleware(environ, start_response):
137- if asbool(environ.get('HTTP_X_SFINC_SSL', 'false')):
138- environ['wsgi.url_scheme'] = 'https'
139- return app(environ, start_response)
140- return SchemeMiddleware
141-
142-def allura_globals_middleware(app):
143- def AlluraGlobalsMiddleware(environ, start_response):
144- from allura import credentials
145- from allura.lib import security, app_globals
146- from tg import tg_globals
147- registry = environ['paste.registry']
148- registry.register(credentials, security.Credentials())
149- registry.register(tg_globals.environ, environ)
150- registry.register(tg_globals.c, EmptyClass())
151- registry.register(tg_globals.g, app_globals.Globals())
152- return app(environ, start_response)
153- return AlluraGlobalsMiddleware
154-
155-class EmptyClass(object): pass
156-
157-def get_tg_vars(context):
158- import pylons, tg
159- from allura.lib import helpers as h
160- from urllib import quote, quote_plus
161- context.setdefault('g', pylons.g)
162- context.setdefault('c', pylons.c)
163- context.setdefault('h', h)
164- context.setdefault('request', pylons.request)
165- context.setdefault('response', pylons.response)
166- context.setdefault('url', pylons.url)
167- context.setdefault('tg', dict(
168- config=tg.config,
169- flash_obj=tg.flash,
170- quote=quote,
171- quote_plus=quote_plus,
172- url=tg.url))