Commits

Jason R. Coombs  committed 4a58b59

Moved site initialization into a 'run' module so it can be launched from cherryd

  • Participants
  • Parent commits a9c45ab

Comments (0)

Files changed (3)

File jaraco/site/__init__.py

 import os
+import importlib
+
 import cherrypy
 from genshi.core import Stream
 from genshi.output import encode, get_serializer
 from genshi.template import Context, TemplateLoader
 
 def init():
-	from jaraco.site.controllers import Root
-	cherrypy.config.update({
-		'tools.encode.on': True, 'tools.encode.encoding': 'utf-8',
-		'tools.decode.on': True,
-		'tools.sessions.on': True,
-		'tools.trailing_slash.on': True,
-		'tools.staticdir.root': os.path.abspath(os.path.dirname(__file__)),
-	})
-
-	import jaraco.site.sspi
-	basic_auth = {
-		'tools.auth_basic.on': True,
-		'tools.auth_basic.realm': 'jaraco.com',
-		'tools.auth_basic.checkpassword': jaraco.site.sspi.check,
-	}
-
-	app = cherrypy.tree.mount(Root(), '/', {
-		'/static': {
-			'tools.staticdir.on': True,
-			'tools.staticdir.dir': 'static',
-			'tools.staticdir.content_types': dict(svg='image/svg+xml'),
-		},
-		'/auth': basic_auth,
-		'/openid/server': basic_auth,
-	})
-
-	return app
+	importlib.import_module('jaraco.site.run')
 
 class DefaultExtensionTemplateLoader(TemplateLoader):
 	"""

File jaraco/site/run.py

+import cherrypy
+import pkg_resources
+
+try:
+	from . import sspi
+except ImportError:
+	pass
+
+from .controllers import Root
+
+cherrypy.config.update({
+	'tools.encode.on': True, 'tools.encode.encoding': 'utf-8',
+	'tools.decode.on': True,
+	'tools.sessions.on': True,
+	'tools.trailing_slash.on': True,
+	'tools.staticdir.root': pkg_resources.resource_filename('jaraco.site', '')
+})
+
+config = {
+	'/static': {
+		'tools.staticdir.on': True,
+		'tools.staticdir.dir': 'static',
+		'tools.staticdir.content_types': dict(svg='image/svg+xml'),
+	},
+}
+
+if 'sspi' in globals():
+	basic_auth = {
+		'tools.auth_basic.on': True,
+		'tools.auth_basic.realm': 'jaraco.com',
+		'tools.auth_basic.checkpassword': sspi.check,
+	}
+	config['/auth'] = basic_auth
+	config['/openid/server'] = basic_auth
+
+app = cherrypy.tree.mount(Root(), '/', config)
-# -*- coding: utf-8 -*-
+import sys
 
 from setuptools import setup, find_packages
 
+py26_reqs = ['importlib'] if sys.version_info < (2, 7) else []
+
 setup_params = dict(
 	name="jaraco.site",
 	use_hg_version=True,
 		"isapi-wsgi >= 0.4",
 		"svg.charts",
 		'jaraco.util>=5.0.1',
-	],
+	] + py26_reqs,
 	zip_safe=False,
 	packages=find_packages(),
 	include_package_data = True,