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