Commits

Anonymous committed 5ffdf5e

Adding scripting that works to host MoinMoin on IIS

Comments (0)

Files changed (3)

+
+import isapi.threaded_extension
+import functools
+import win32api
+from isapi import isapicon
+
+class PathExclusionFilter(list):
+	def wrap(self, extension):
+		"""
+		Wrap an ISAPI extension's Dispatch method to bypass
+		the extension's behavior if the URL matches one of
+		the URLs in this filter.
+		"""
+		assert isinstance(extension, isapi.threaded_extension.ThreadPoolExtension)
+		original_dispatch = extension.Dispatch
+		@functools.wraps(extension.Dispatch)
+		def Dispatch(ecb):
+			print '"%s"' % (ecb.GetServerVariable("URL"),)
+			url = ecb.GetServerVariable("URL").decode("ascii")
+			if self.matches(url):
+				print 'excluding %s' % url
+				assert ecb.Version >= 0x60000, "IIS 6.0 required"
+				ecb.IOCompletion(self.on_completion, url)
+				params = [None]*5
+				params.append(isapicon.HSE_EXEC_URL_IGNORE_CURRENT_INTERCEPTOR)
+				ecb.ExecURL(*params)
+				return isapicon.HSE_STATUS_PENDING
+			return original_dispatch(ecb)
+		extension.Dispatch = Dispatch
+
+	def matches(self, url):
+		url = url.lower()
+		for exclude in self:
+			if url.startswith(exclude):
+				return True
+		return False
+		
+	def on_completion(self, ecb, url, cbIO, errcode):
+		"""An "io completion" function, called when ecb.ExecURL completes..."""
+		# Get the status of our ExecURL
+		httpstatus, substatus, win32 = ecb.GetExecURLStatus()
+		print "ExecURL of %r finished with http status %d.%d, win32 status %d (%s)" % (
+			   url, httpstatus, substatus, win32, win32api.FormatMessage(win32).strip())
+		# nothing more to do!
+		ecb.DoneWithSession()

moin-isapi-wsgi.py

+# -*- coding: utf-8 -*-
+"""
+    MoinMoin - isapi-wsgi driver script
+
+    Put directions here.
+"""
+
+import sys
+import os
+
+appdir = os.path.dirname(__file__)
+os.chdir(appdir)
+
+# a) Configuration of Python's code search path
+#    If you already have set up the PYTHONPATH environment variable for the
+#    stuff you see below, you don't need to do a1) and a2).
+
+# a1) Path of the directory where the MoinMoin code package is located.
+#     Needed if you installed with --prefix=PREFIX or you didn't use setup.py.
+#sys.path.insert(0, 'PREFIX/lib/python2.3/site-packages')
+
+# a2) Path of the directory where wikiconfig.py / farmconfig.py is located.
+#     See wiki/config/... for some sample config files.
+#sys.path.insert(0, '/path/to/wikiconfigdir')
+#sys.path.insert(0, '/path/to/farmconfigdir')
+sys.path.insert(0, os.path.join(appdir, 'config'))
+
+# b) Configuration of moin's logging
+#    If you have set up MOINLOGGINGCONF environment variable, you don't need this!
+#    You also don't need this if you are happy with the builtin defaults.
+#    See wiki/config/logging/... for some sample config files.
+#from MoinMoin import log
+#log.load_config('/path/to/logging_configuration_file')
+
+# Debug mode - show detailed error reports
+#os.environ['MOIN_DEBUG'] = '1'
+
+
+def factory():
+	"The entry point for when the ISAPIDLL is triggered"
+	try:
+		import isapi_wsgi
+		from MoinMoin.server.server_wsgi import moinmoinApp
+		extension =  isapi_wsgi.ISAPIThreadPoolHandler(moinmoinApp)
+		from isapi_exclude import PathExclusionFilter
+		filter = PathExclusionFilter(['/moin_static'])
+		filter.wrap(extension)
+		return extension
+	except:
+		import traceback
+		print("Traceback occurred starting up the application")
+		traceback.print_exc()
+
+__ExtensionFactory__ = factory
+
+def handle_command_line():
+	"Install or remove the extension to the virtual directory"
+	import isapi.install
+	params = isapi.install.ISAPIParameters()
+	# Setup the virtual directories - this is a list of directories our
+	# extension uses - in this case only 1.
+	# Each extension has a "script map" - this is the mapping of ISAPI
+	# extensions.
+	sm = [
+		isapi.install.ScriptMapParams(Extension="*", Flags=0)
+	]
+	vd = isapi.install.VirtualDirParameters(
+		Server="Chai and Chaat Wiki",
+		Name="/",
+		Description = "MoinMoin Application",
+		ScriptMaps = sm,
+		ScriptMapUpdate = "end",
+		)
+	params.VirtualDirs = [vd]
+	isapi.install.HandleCommandLine(params)
+
+if __name__ == '__main__': handle_command_line()
+To install this site:
+
+1) Create a web site called "Chai and Chaat Wiki".
+2) In that site, create a virtual directory '/moin_static185' that points to htdocs.
+3) Assign Full Control (or at least write) permissions for the "Chai and Chaat Wiki" application pool account (probably 'IIS AppPool\Chai and Chaat Wiki') to .
+4) Install the ISAPI extension using "./moin-isapi-wsgi.py install".
+
+Eventually, I'll write a script to do these things.