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-2016 Sune Foldager <cyano@me.com> |
3 # |
3 # |
4 # This software may be used and distributed according to the terms of the |
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. |
5 # GNU General Public License version 2 or any later version. |
6 # |
6 # |
7 # Requirements: |
7 # Requirements: |
8 # - Python 2.6 |
8 # - Python 2.7, preferably 64 bit |
9 # - PyWin32 build 214 or newer |
9 # - PyWin32 for Python 2.7 (32 or 64 bit) |
10 # - Mercurial installed from source (python setup.py install) |
10 # - Mercurial installed from source (python setup.py install) or download the |
11 # - IIS 7 |
11 # python module installer from https://www.mercurial-scm.org/wiki/Download |
12 # |
12 # - IIS 7 or newer |
13 # Earlier versions will in general work as well, but the PyWin32 version is |
|
14 # necessary for win32traceutil to work correctly. |
|
15 # |
13 # |
16 # |
14 # |
17 # Installation and use: |
15 # Installation and use: |
18 # |
16 # |
19 # - Download the isapi-wsgi source and run python setup.py install: |
17 # - Download or clone the isapi-wsgi source and run python setup.py install. |
20 # http://code.google.com/p/isapi-wsgi/ |
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 # - Run this script (i.e. python hgwebdir_wsgi.py) to get a shim dll. The |
24 # - Run this script (i.e. python hgwebdir_wsgi.py) to get a shim dll. The |
23 # shim is identical for all scripts, so you can just copy and rename one |
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. |
25 # |
28 # |
26 # - Setup an IIS application where your hgwebdir is to be served from. |
29 # - Start IIS manager and create a new app pool: |
27 # On 64-bit systems, make sure it's assigned a 32-bit 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. |
28 # |
34 # |
29 # - In the application, setup a wildcard script handler mapping of type |
35 # - Create an IIS application where your hgwebdir is to be served from. |
30 # IsapiModule with the shim dll as its executable. This file MUST reside |
36 # Assign it the app pool you just created and point its physical path to the |
31 # in the same directory as the shim. Remove all other handlers, if you wish. |
37 # directory you created. |
32 # |
38 # |
33 # - Make sure the ISAPI and CGI restrictions (configured globally on the |
39 # - In the application, remove all handler mappings and setup a wildcard script |
34 # web server) includes the shim dll, to allow it to run. |
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: |
35 # |
44 # |
36 # - Adjust the configuration variables below to match your needs. |
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. |
|
62 # |
|
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 |
|
71 # |
|
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 # Configuration file location |
82 # Configuration file location |
40 hgweb_config = r'c:\src\iis\hg\hgweb.config' |
83 hgweb_config = r'c:\your\directory\wsgi.config' |
41 |
84 |
42 # Global settings for IIS path translation |
85 # Global settings for IIS path translation |
43 path_strip = 0 # Strip this many path elements off (when using url rewrite) |
86 path_strip = 0 # Strip this many path elements off (when using url rewrite) |
44 path_prefix = 1 # This many path elements are prefixes (depends on the |
87 path_prefix = 1 # This many path elements are prefixes (depends on the |
45 # virtual path of the IIS application). |
88 # virtual path of the IIS application). |
46 |
89 |
47 import sys |
90 import sys |
48 |
91 |
49 # Adjust python path if this is not a system-wide install |
92 # Adjust python path if this is not a system-wide install |
50 #sys.path.insert(0, r'c:\path\to\python\lib') |
93 #sys.path.insert(0, r'C:\your\custom\hg\build\lib.win32-2.7') |
51 |
94 |
52 # Enable tracing. Run 'python -m win32traceutil' to debug |
95 # Enable tracing. Run 'python -m win32traceutil' to debug |
53 if getattr(sys, 'isapidllhandle', None) is not None: |
96 if getattr(sys, 'isapidllhandle', None) is not None: |
54 import win32traceutil |
97 import win32traceutil |
55 win32traceutil.SetupForPrint # silence unused import warning |
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 import isapi_wsgi |
100 import isapi_wsgi |
63 from mercurial import demandimport; demandimport.enable() |
|
64 from mercurial.hgweb.hgwebdir_mod import hgwebdir |
101 from mercurial.hgweb.hgwebdir_mod import hgwebdir |
65 |
102 |
66 # Example tweak: Replace isapi_wsgi's handler to provide better error message |
103 # Example tweak: Replace isapi_wsgi's handler to provide better error message |
67 # Other stuff could also be done here, like logging errors etc. |
104 # Other stuff could also be done here, like logging errors etc. |
68 class WsgiHandler(isapi_wsgi.IsapiWsgiHandler): |
105 class WsgiHandler(isapi_wsgi.IsapiWsgiHandler): |