Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: cms/bin/test_server.py

Issue 29334114: issue 3546 - Add port and hostname options to CMS testing server (Closed)
Left Patch Set: Created Jan. 20, 2016, 1:39 p.m.
Right Patch Set: Fixes help text wording Created Jan. 21, 2016, 4:06 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 # coding: utf-8 1 # coding: utf-8
2 2
3 # This file is part of the Adblock Plus web scripts, 3 # This file is part of the Adblock Plus web scripts,
4 # Copyright (C) 2006-2015 Eyeo GmbH 4 # Copyright (C) 2006-2015 Eyeo GmbH
5 # 5 #
6 # Adblock Plus is free software: you can redistribute it and/or modify 6 # Adblock Plus is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 3 as 7 # it under the terms of the GNU General Public License version 3 as
8 # published by the Free Software Foundation. 8 # published by the Free Software Foundation.
9 # 9 #
10 # Adblock Plus is distributed in the hope that it will be useful, 10 # Adblock Plus is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details. 13 # GNU General Public License for more details.
14 # 14 #
15 # You should have received a copy of the GNU General Public License 15 # You should have received a copy of the GNU General Public License
16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
17 17
18 import mimetypes 18 import mimetypes
19 import os 19 import os
20 import sys 20 import sys
21 import argparse 21 import argparse
22 22
23 import jinja2 23 import jinja2
24 24
25 from cms.utils import process_page 25 from cms.utils import process_page
26 from cms.sources import FileSource 26 from cms.sources import FileSource
27 from cms.converters import converters 27 from cms.converters import converters
28 28
29 source = None 29 source = None
30 address = None
31 port = None
30 32
31 UNICODE_ENCODING = "utf-8" 33 UNICODE_ENCODING = "utf-8"
32 34
33 ERROR_TEMPLATE = """ 35 ERROR_TEMPLATE = """
34 <html> 36 <html>
35 <head> 37 <head>
36 <title>{{status}}</title> 38 <title>{{status}}</title>
37 </head> 39 </head>
38 <body> 40 <body>
39 <h1>{{status}}</h1> 41 <h1>{{status}}</h1>
(...skipping 19 matching lines...) Expand all
59 locale, page = path.split("/", 1) 61 locale, page = path.split("/", 1)
60 else: 62 else:
61 locale, page = path, "" 63 locale, page = path, ""
62 64
63 default_page = source.read_config().get("general", "defaultpage") 65 default_page = source.read_config().get("general", "defaultpage")
64 alternative_page = "/".join([page, default_page]).lstrip("/") 66 alternative_page = "/".join([page, default_page]).lstrip("/")
65 67
66 for format in converters.iterkeys(): 68 for format in converters.iterkeys():
67 for p in (page, alternative_page): 69 for p in (page, alternative_page):
68 if source.has_page(p, format): 70 if source.has_page(p, format):
69 return (p, process_page(source, locale, p, format, "http://127.0.0.1:500 0")) 71 return (p, process_page(source, locale, p, format, "http://%s:%d" % (add ress, port)))
70 if source.has_localizable_file(locale, page): 72 if source.has_localizable_file(locale, page):
71 return (page, source.read_localizable_file(locale, page)) 73 return (page, source.read_localizable_file(locale, page))
72 74
73 return (None, None) 75 return (None, None)
74 76
75 def has_conflicting_pages(page): 77 def has_conflicting_pages(page):
76 pages = [p for p, _ in source.list_pages()] 78 pages = [p for p, _ in source.list_pages()]
77 pages.extend(source.list_localizable_files()) 79 pages.extend(source.list_localizable_files())
78 80
79 if pages.count(page) > 1: 81 if pages.count(page) > 1:
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 113
112 if isinstance(data, unicode): 114 if isinstance(data, unicode):
113 data = data.encode(UNICODE_ENCODING) 115 data = data.encode(UNICODE_ENCODING)
114 mime = "%s; charset=%s" % (mime, UNICODE_ENCODING) 116 mime = "%s; charset=%s" % (mime, UNICODE_ENCODING)
115 117
116 start_response("200 OK", [("Content-Type", mime)]) 118 start_response("200 OK", [("Content-Type", mime)])
117 return [data] 119 return [data]
118 120
119 if __name__ == "__main__": 121 if __name__ == "__main__":
120 122
121 parser = argparse.ArgumentParser(description='CMS testing server.') 123 parser = argparse.ArgumentParser(description='CMS development server created t o test pages locally and on-the-fly')
122 parser.add_argument('-b', '--basepath', type=str, help='Base directory (EG: /p ath/to/web.eyeo.com)') 124 parser.add_argument('path', nargs='?', default=os.curdir)
Sebastian Noack 2016/01/20 14:35:59 Please keep the path a positional argument rather
juliandoucette 2016/01/21 13:46:23 Done.
123 parser.add_argument('-n', '--hostname', type=str, help='Server hostname (EG: l ocalhost, eyeo.com, 0.0.0.0)') 125 parser.add_argument('-a', '--address', default='localhost', help='Address of t he interface the server will listen on')
Sebastian Noack 2016/01/20 14:35:59 Specify "localhost" as default.
juliandoucette 2016/01/21 13:46:23 Done.
124 parser.add_argument('-p', '--port', type=str, help='Port number (EG: 8080, 500 0)') 126 parser.add_argument('-p', '--port', type=int, default=5000, help='TCP port the server will listen on')
Sebastian Noack 2016/01/20 14:35:59 Specify 5000 as default.
juliandoucette 2016/01/21 13:46:23 Done.
125 args = parser.parse_args() 127 args = parser.parse_args()
126 128
127 # for backwards compatibility 129 source = FileSource(args.path)
Sebastian Noack 2016/01/20 14:35:59 With the above comments addressed you don't need t
juliandoucette 2016/01/21 13:46:23 Agreed. Thank you for bringing that up.
128 if len(sys.argv) > 1 and os.path.isdir(sys.argv[1]): 130 address = args.address
129 source = FileSource(sys.argv[1]) 131 port = args.port
130 hostname = 'localhost'
131 port = 5000
132 else:
133 source = FileSource(args.basepath or os.curdir)
134 hostname = args.hostname or 'localhost'
135 port = int(args.port or '5000')
136 132
137 try: 133 try:
138 from werkzeug.serving import ThreadedWSGIServer, run_simple 134 from werkzeug.serving import ThreadedWSGIServer, run_simple
139 135
140 # see https://github.com/mitsuhiko/werkzeug/pull/770 136 # see https://github.com/mitsuhiko/werkzeug/pull/770
141 ThreadedWSGIServer.daemon_threads = True 137 ThreadedWSGIServer.daemon_threads = True
142 138
143 def run(*args, **kwargs): 139 def run(*args, **kwargs):
144 # The werkzeug logger must be configured before the 140 # The werkzeug logger must be configured before the
145 # root logger. Also we must prevent it from propagating 141 # root logger. Also we must prevent it from propagating
(...skipping 17 matching lines...) Expand all
163 try: 159 try:
164 return app(environ, start_response) 160 return app(environ, start_response)
165 except Exception, e: 161 except Exception, e:
166 return show_error(start_response, "500 Internal Server Error", 162 return show_error(start_response, "500 Internal Server Error",
167 uri=environ.get("PATH_INFO"), error=e) 163 uri=environ.get("PATH_INFO"), error=e)
168 164
169 server = make_server(host, port, wrapper, ThreadedWSGIServer) 165 server = make_server(host, port, wrapper, ThreadedWSGIServer)
170 print " * Running on http://%s:%i/" % server.server_address 166 print " * Running on http://%s:%i/" % server.server_address
171 server.serve_forever() 167 server.serve_forever()
172 168
173 run(hostname, port, handler, use_reloader=True, use_debugger=True) 169 run(address, port, handler, use_reloader=True, use_debugger=True)
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld