Created
October 1, 2012 10:33
-
-
Save kamyar1979/3810809 to your computer and use it in GitHub Desktop.
Python script for making WSGI isapi for Bazaar DVCS smart server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
use this script just like Mercurial. No need to follow the canonical site bad document.