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