Show More
@@ -1,92 +1,95 b'' | |||||
1 | # An example WSGI script for IIS/isapi-wsgi to export multiple hgweb repos |
|
1 | # An example WSGI script for IIS/isapi-wsgi to export multiple hgweb repos | |
2 | # Copyright 2010 Sune Foldager <cryo@cyanite.org> |
|
2 | # Copyright 2010 Sune Foldager <cryo@cyanite.org> | |
3 | # |
|
3 | # | |
|
4 | # This software may be used and distributed according to the terms of the | |||
|
5 | # GNU General Public License version 2 or any later version. | |||
|
6 | # | |||
4 | # Requirements: |
|
7 | # Requirements: | |
5 | # - Python 2.6 |
|
8 | # - Python 2.6 | |
6 | # - IIS 7 |
|
9 | # - IIS 7 | |
7 | # - PyWin32 build 214 or newer |
|
10 | # - PyWin32 build 214 or newer | |
8 | # |
|
11 | # | |
9 | # Earlier versions will in general work as well, but the PyWin32 version is |
|
12 | # Earlier versions will in general work as well, but the PyWin32 version is | |
10 | # necessary for win32traceutil to work correctly. |
|
13 | # necessary for win32traceutil to work correctly. | |
11 | # |
|
14 | # | |
12 | # |
|
15 | # | |
13 | # Installation and use: |
|
16 | # Installation and use: | |
14 | # |
|
17 | # | |
15 | # - Download the isapi-wsgi source and run python setup.py install: |
|
18 | # - Download the isapi-wsgi source and run python setup.py install: | |
16 | # http://code.google.com/p/isapi-wsgi/ |
|
19 | # http://code.google.com/p/isapi-wsgi/ | |
17 | # |
|
20 | # | |
18 | # - Run this script (i.e. python hgwebdir_wsgi.py) to get a shim dll. The |
|
21 | # - Run this script (i.e. python hgwebdir_wsgi.py) to get a shim dll. The | |
19 | # shim is identical for all scripts, so you can just copy and rename one |
|
22 | # shim is identical for all scripts, so you can just copy and rename one | |
20 | # from an earlier run instead. |
|
23 | # from an earlier run instead. | |
21 | # |
|
24 | # | |
22 | # - Setup an IIS application where your hgwebdir is to be served from. |
|
25 | # - Setup an IIS application where your hgwebdir is to be served from. | |
23 | # Make sure it's assigned a 32-bit app pool. |
|
26 | # Make sure it's assigned a 32-bit app pool. | |
24 | # |
|
27 | # | |
25 | # - In the application, setup a wildcard script handler mapping of type |
|
28 | # - In the application, setup a wildcard script handler mapping of type | |
26 | # IpsapiModule, with the shim dll as its executable. This file MUST reside |
|
29 | # IpsapiModule, with the shim dll as its executable. This file MUST reside | |
27 | # in the same directory as the shim. Remove all other handlers, if you wish. |
|
30 | # in the same directory as the shim. Remove all other handlers, if you wish. | |
28 | # |
|
31 | # | |
29 | # - Make sure the ISAPI and CGI restrictions (configured globally on the |
|
32 | # - Make sure the ISAPI and CGI restrictions (configured globally on the | |
30 | # web server) includes the shim dll, to allow it to run. |
|
33 | # web server) includes the shim dll, to allow it to run. | |
31 | # |
|
34 | # | |
32 | # - Adjust the configuration variables below to match your needs. |
|
35 | # - Adjust the configuration variables below to match your needs. | |
33 | # |
|
36 | # | |
34 |
|
37 | |||
35 | # Configuration file location |
|
38 | # Configuration file location | |
36 | hgweb_config = r'c:\src\iis\hg\hgweb.config' |
|
39 | hgweb_config = r'c:\src\iis\hg\hgweb.config' | |
37 |
|
40 | |||
38 | # Global settings for IIS path translation |
|
41 | # Global settings for IIS path translation | |
39 | path_strip = 0 # Strip this many path elements off (when using url rewrite) |
|
42 | path_strip = 0 # Strip this many path elements off (when using url rewrite) | |
40 | path_prefix = 1 # This many path elements are prefixes (depends on the |
|
43 | path_prefix = 1 # This many path elements are prefixes (depends on the | |
41 | # virtual path of the IIS application). |
|
44 | # virtual path of the IIS application). | |
42 |
|
45 | |||
43 | import sys |
|
46 | import sys | |
44 |
|
47 | |||
45 | # To stop serving pages in UTF-8, remove the two lines below |
|
48 | # To stop serving pages in UTF-8, remove the two lines below | |
46 | import os |
|
49 | import os | |
47 | os.environ['HGENCODING'] = 'UTF-8' |
|
50 | os.environ['HGENCODING'] = 'UTF-8' | |
48 |
|
51 | |||
49 | # Adjust python path if this is not a system-wide install |
|
52 | # Adjust python path if this is not a system-wide install | |
50 | #sys.path.insert(0, "/path/to/python/lib") |
|
53 | #sys.path.insert(0, "/path/to/python/lib") | |
51 |
|
54 | |||
52 |
|
55 | |||
53 | # Enable tracing. Run 'python -m win32traceutil' to debug |
|
56 | # Enable tracing. Run 'python -m win32traceutil' to debug | |
54 | if hasattr(sys, 'isapidllhandle'): |
|
57 | if hasattr(sys, 'isapidllhandle'): | |
55 | import win32traceutil |
|
58 | import win32traceutil | |
56 |
|
59 | |||
57 | import isapi_wsgi |
|
60 | import isapi_wsgi | |
58 |
|
61 | |||
59 | from mercurial import demandimport; demandimport.enable() |
|
62 | from mercurial import demandimport; demandimport.enable() | |
60 | from mercurial.hgweb.hgwebdir_mod import hgwebdir |
|
63 | from mercurial.hgweb.hgwebdir_mod import hgwebdir | |
61 |
|
64 | |||
62 | # Example tweak: Replace isapi_wsgi's handler to provide better error message |
|
65 | # Example tweak: Replace isapi_wsgi's handler to provide better error message | |
63 | # Other stuff could also be done here, like logging errors etc. |
|
66 | # Other stuff could also be done here, like logging errors etc. | |
64 | class WsgiHandler(isapi_wsgi.IsapiWsgiHandler): |
|
67 | class WsgiHandler(isapi_wsgi.IsapiWsgiHandler): | |
65 | error_status = '500 Internal Server Error' # less silly error message |
|
68 | error_status = '500 Internal Server Error' # less silly error message | |
66 |
|
69 | |||
67 | isapi_wsgi.IsapiWsgiHandler = WsgiHandler |
|
70 | isapi_wsgi.IsapiWsgiHandler = WsgiHandler | |
68 |
|
71 | |||
69 | # Only create the hgwebdir instance once |
|
72 | # Only create the hgwebdir instance once | |
70 | application = hgwebdir(hgweb_config) |
|
73 | application = hgwebdir(hgweb_config) | |
71 |
|
74 | |||
72 | def handler(environ, start_response): |
|
75 | def handler(environ, start_response): | |
73 |
|
76 | |||
74 | # Translate IIS's weird URLs |
|
77 | # Translate IIS's weird URLs | |
75 | url = environ['SCRIPT_NAME'] + environ['PATH_INFO'] |
|
78 | url = environ['SCRIPT_NAME'] + environ['PATH_INFO'] | |
76 | paths = url[1:].split('/')[path_strip:] |
|
79 | paths = url[1:].split('/')[path_strip:] | |
77 | script_name = '/' + '/'.join(paths[:path_prefix]) |
|
80 | script_name = '/' + '/'.join(paths[:path_prefix]) | |
78 | path_info = '/'.join(paths[path_prefix:]) |
|
81 | path_info = '/'.join(paths[path_prefix:]) | |
79 | if path_info: |
|
82 | if path_info: | |
80 | path_info = '/' + path_info |
|
83 | path_info = '/' + path_info | |
81 | environ['SCRIPT_NAME'] = script_name |
|
84 | environ['SCRIPT_NAME'] = script_name | |
82 | environ['PATH_INFO'] = path_info |
|
85 | environ['PATH_INFO'] = path_info | |
83 |
|
86 | |||
84 | return application(environ, start_response) |
|
87 | return application(environ, start_response) | |
85 |
|
88 | |||
86 | def __ExtensionFactory__(): |
|
89 | def __ExtensionFactory__(): | |
87 | return isapi_wsgi.ISAPISimpleHandler(handler) |
|
90 | return isapi_wsgi.ISAPISimpleHandler(handler) | |
88 |
|
91 | |||
89 | if __name__=='__main__': |
|
92 | if __name__=='__main__': | |
90 | from isapi.install import * |
|
93 | from isapi.install import * | |
91 | params = ISAPIParameters() |
|
94 | params = ISAPIParameters() | |
92 | HandleCommandLine(params) |
|
95 | HandleCommandLine(params) |
General Comments 0
You need to be logged in to leave comments.
Login now