Show More
@@ -1,96 +1,133 b'' | |||
|
1 | 1 | # An example WSGI script for IIS/isapi-wsgi to export multiple hgweb repos |
|
2 |
# Copyright 2010 Sune Foldager <c |
|
|
2 | # Copyright 2010-2016 Sune Foldager <cyano@me.com> | |
|
3 | 3 | # |
|
4 | 4 | # This software may be used and distributed according to the terms of the |
|
5 | 5 | # GNU General Public License version 2 or any later version. |
|
6 | 6 | # |
|
7 | 7 | # Requirements: |
|
8 | # - Python 2.6 | |
|
9 | # - PyWin32 build 214 or newer | |
|
10 | # - Mercurial installed from source (python setup.py install) | |
|
11 | # - IIS 7 | |
|
12 | # | |
|
13 | # Earlier versions will in general work as well, but the PyWin32 version is | |
|
14 | # necessary for win32traceutil to work correctly. | |
|
8 | # - Python 2.7, preferably 64 bit | |
|
9 | # - PyWin32 for Python 2.7 (32 or 64 bit) | |
|
10 | # - Mercurial installed from source (python setup.py install) or download the | |
|
11 | # python module installer from https://www.mercurial-scm.org/wiki/Download | |
|
12 | # - IIS 7 or newer | |
|
15 | 13 | # |
|
16 | 14 | # |
|
17 | 15 | # Installation and use: |
|
18 | 16 | # |
|
19 |
# - Download the isapi-wsgi source and run python setup.py install |
|
|
20 |
# http |
|
|
17 | # - Download or clone the isapi-wsgi source and run python setup.py install. | |
|
18 | # https://github.com/hexdump42/isapi-wsgi | |
|
19 | # | |
|
20 | # - Create a directory to hold the shim dll, config files etc. This can reside | |
|
21 | # inside the standard IIS directory, C:\inetpub, or anywhere else. Copy this | |
|
22 | # script there. | |
|
21 | 23 | # |
|
22 | 24 | # - Run this script (i.e. python hgwebdir_wsgi.py) to get a shim dll. The |
|
23 | 25 | # shim is identical for all scripts, so you can just copy and rename one |
|
24 | # from an earlier run, if you wish. | |
|
26 | # from an earlier run, if you wish. The shim needs to reside in the same | |
|
27 | # directory as this script. | |
|
28 | # | |
|
29 | # - Start IIS manager and create a new app pool: | |
|
30 | # .NET CLR Version: No Managed Code | |
|
31 | # Advanced Settings: Enable 32 Bit Applications, if using 32 bit Python. | |
|
32 | # You can adjust the identity and maximum worker processes if you wish. This | |
|
33 | # setup works fine with multiple worker processes. | |
|
25 | 34 | # |
|
26 |
# - |
|
|
27 | # On 64-bit systems, make sure it's assigned a 32-bit app pool. | |
|
35 | # - Create an IIS application where your hgwebdir is to be served from. | |
|
36 | # Assign it the app pool you just created and point its physical path to the | |
|
37 | # directory you created. | |
|
38 | # | |
|
39 | # - In the application, remove all handler mappings and setup a wildcard script | |
|
40 | # handler mapping of type IsapiModule with the shim dll as its executable. | |
|
41 | # This file MUST reside in the same directory as the shim. The easiest way | |
|
42 | # to do all this is to close IIS manager, place a web.config file in your | |
|
43 | # directory and start IIS manager again. The file should contain: | |
|
28 | 44 | # |
|
29 | # - In the application, setup a wildcard script handler mapping of type | |
|
30 | # IsapiModule with the shim dll as its executable. This file MUST reside | |
|
31 | # in the same directory as the shim. Remove all other handlers, if you wish. | |
|
45 | # <?xml version="1.0" encoding="UTF-8"?> | |
|
46 | # <configuration> | |
|
47 | # <system.webServer> | |
|
48 | # <handlers accessPolicy="Read, Script"> | |
|
49 | # <clear /> | |
|
50 | # <add name="hgwebdir" path="*" verb="*" modules="IsapiModule" | |
|
51 | # scriptProcessor="C:\your\directory\_hgwebdir_wsgi.dll" | |
|
52 | # resourceType="Unspecified" requireAccess="None" | |
|
53 | # preCondition="bitness64" /> | |
|
54 | # </handlers> | |
|
55 | # </system.webServer> | |
|
56 | # </configuration> | |
|
57 | # | |
|
58 | # Where "bitness64" should be replaced with "bitness32" for 32 bit Python. | |
|
59 | # | |
|
60 | # - Edit ISAPI And CGI Restrictions on the web server (global setting). Add a | |
|
61 | # restriction pointing to your shim dll and allow it to run. | |
|
32 | 62 | # |
|
33 | # - Make sure the ISAPI and CGI restrictions (configured globally on the | |
|
34 | # web server) includes the shim dll, to allow it to run. | |
|
63 | # - Create a configuration file in your directory and adjust the configuration | |
|
64 | # variables below to match your needs. Example configuration: | |
|
65 | # | |
|
66 | # [web] | |
|
67 | # style = gitweb | |
|
68 | # push_ssl = false | |
|
69 | # allow_push = * | |
|
70 | # encoding = utf8 | |
|
35 | 71 | # |
|
36 | # - Adjust the configuration variables below to match your needs. | |
|
72 | # [server] | |
|
73 | # validate = true | |
|
74 | # | |
|
75 | # [paths] | |
|
76 | # repo1 = c:\your\directory\repo1 | |
|
77 | # repo2 = c:\your\directory\repo2 | |
|
78 | # | |
|
79 | # - Restart the web server and see if things are running. | |
|
37 | 80 | # |
|
38 | 81 | |
|
39 | 82 | # Configuration file location |
|
40 |
hgweb_config = r'c:\ |
|
|
83 | hgweb_config = r'c:\your\directory\wsgi.config' | |
|
41 | 84 | |
|
42 | 85 | # Global settings for IIS path translation |
|
43 | 86 | path_strip = 0 # Strip this many path elements off (when using url rewrite) |
|
44 | 87 | path_prefix = 1 # This many path elements are prefixes (depends on the |
|
45 | 88 | # virtual path of the IIS application). |
|
46 | 89 | |
|
47 | 90 | import sys |
|
48 | 91 | |
|
49 | 92 | # Adjust python path if this is not a system-wide install |
|
50 |
#sys.path.insert(0, r' |
|
|
93 | #sys.path.insert(0, r'C:\your\custom\hg\build\lib.win32-2.7') | |
|
51 | 94 | |
|
52 | 95 | # Enable tracing. Run 'python -m win32traceutil' to debug |
|
53 | 96 | if getattr(sys, 'isapidllhandle', None) is not None: |
|
54 | 97 | import win32traceutil |
|
55 | 98 | win32traceutil.SetupForPrint # silence unused import warning |
|
56 | 99 | |
|
57 | # To serve pages in local charset instead of UTF-8, remove the two lines below | |
|
58 | import os | |
|
59 | os.environ['HGENCODING'] = 'UTF-8' | |
|
60 | ||
|
61 | ||
|
62 | 100 | import isapi_wsgi |
|
63 | from mercurial import demandimport; demandimport.enable() | |
|
64 | 101 | from mercurial.hgweb.hgwebdir_mod import hgwebdir |
|
65 | 102 | |
|
66 | 103 | # Example tweak: Replace isapi_wsgi's handler to provide better error message |
|
67 | 104 | # Other stuff could also be done here, like logging errors etc. |
|
68 | 105 | class WsgiHandler(isapi_wsgi.IsapiWsgiHandler): |
|
69 | 106 | error_status = '500 Internal Server Error' # less silly error message |
|
70 | 107 | |
|
71 | 108 | isapi_wsgi.IsapiWsgiHandler = WsgiHandler |
|
72 | 109 | |
|
73 | 110 | # Only create the hgwebdir instance once |
|
74 | 111 | application = hgwebdir(hgweb_config) |
|
75 | 112 | |
|
76 | 113 | def handler(environ, start_response): |
|
77 | 114 | |
|
78 | 115 | # Translate IIS's weird URLs |
|
79 | 116 | url = environ['SCRIPT_NAME'] + environ['PATH_INFO'] |
|
80 | 117 | paths = url[1:].split('/')[path_strip:] |
|
81 | 118 | script_name = '/' + '/'.join(paths[:path_prefix]) |
|
82 | 119 | path_info = '/'.join(paths[path_prefix:]) |
|
83 | 120 | if path_info: |
|
84 | 121 | path_info = '/' + path_info |
|
85 | 122 | environ['SCRIPT_NAME'] = script_name |
|
86 | 123 | environ['PATH_INFO'] = path_info |
|
87 | 124 | |
|
88 | 125 | return application(environ, start_response) |
|
89 | 126 | |
|
90 | 127 | def __ExtensionFactory__(): |
|
91 | 128 | return isapi_wsgi.ISAPISimpleHandler(handler) |
|
92 | 129 | |
|
93 | 130 | if __name__=='__main__': |
|
94 | 131 | from isapi.install import ISAPIParameters, HandleCommandLine |
|
95 | 132 | params = ISAPIParameters() |
|
96 | 133 | HandleCommandLine(params) |
General Comments 0
You need to be logged in to leave comments.
Login now