Skip to content

Instantly share code, notes, and snippets.

@kamyar1979
Created October 1, 2012 10:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kamyar1979/3810809 to your computer and use it in GitHub Desktop.
Save kamyar1979/3810809 to your computer and use it in GitHub Desktop.
Python script for making WSGI isapi for Bazaar DVCS smart server
from bzrlib.transport.http import wsgi
import sys
import os
import isapi_wsgi
if hasattr(sys, 'isapidllhandle'):
import win32traceutil
path_strip = 0 # Strip this many path elements off (when using url rewrite)
path_prefix = 0 # This many path elements are prefixes (depends on the
# virtual path of the IIS application).
root_dir = r'D:\Repository\bzr'
def application(environ, start_response):
# Translate IIS's weird URLs
url = environ['SCRIPT_NAME'] + environ['PATH_INFO']
paths = url[1:].split('/')[path_strip:]
script_name = '/' + '/'.join(paths[:path_prefix])
path_info = '/'.join(paths[path_prefix:])
if path_info:
path_info = '/' + path_info
environ['SCRIPT_NAME'] = script_name
environ['PATH_INFO'] = path_info
if '/.bzr' in path_info and path_info[-11:] != '/.bzr/smart':
with open(root_dir + path_info.replace('/',os.sep),'rt') as f:
response_body = f.read()
status = '200 OK'
response_headers = [('Content-Type', 'application/octet-stream'),
('Content-Length', str(len(response_body)))]
start_response(status, response_headers)
return [response_body]
else:
app = wsgi.make_app(
root=root_dir,
prefix='',
path_var='PATH_INFO',
readonly=False,
enable_logging=False)
return app(environ, start_response)
def __ExtensionFactory__():
return isapi_wsgi.ISAPISimpleHandler(application)
if __name__=='__main__':
from isapi.install import *
params = ISAPIParameters()
HandleCommandLine(params)
@kamyar1979
Copy link
Author

use this script just like Mercurial. No need to follow the canonical site bad document.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment