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: See help message not necessary Created Jan. 21, 2016, 1:50 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 = 'localhost' 30 address = None
Sebastian Noack 2016/01/21 14:14:09 Please don't define defaults redundantly. You can
juliandoucette 2016/01/21 14:41:35 Acknowledged.
31 port = '5000' 31 port = None
32 32
33 UNICODE_ENCODING = "utf-8" 33 UNICODE_ENCODING = "utf-8"
34 34
35 ERROR_TEMPLATE = """ 35 ERROR_TEMPLATE = """
36 <html> 36 <html>
37 <head> 37 <head>
38 <title>{{status}}</title> 38 <title>{{status}}</title>
39 </head> 39 </head>
40 <body> 40 <body>
41 <h1>{{status}}</h1> 41 <h1>{{status}}</h1>
(...skipping 19 matching lines...) Expand all
61 locale, page = path.split("/", 1) 61 locale, page = path.split("/", 1)
62 else: 62 else:
63 locale, page = path, "" 63 locale, page = path, ""
64 64
65 default_page = source.read_config().get("general", "defaultpage") 65 default_page = source.read_config().get("general", "defaultpage")
66 alternative_page = "/".join([page, default_page]).lstrip("/") 66 alternative_page = "/".join([page, default_page]).lstrip("/")
67 67
68 for format in converters.iterkeys(): 68 for format in converters.iterkeys():
69 for p in (page, alternative_page): 69 for p in (page, alternative_page):
70 if source.has_page(p, format): 70 if source.has_page(p, format):
71 return (p, process_page(source, locale, p, format, "http://" + address + ":" + str(port))) 71 return (p, process_page(source, locale, p, format, "http://%s:%d" % (add ress, port)))
Sebastian Noack 2016/01/21 14:14:08 Nit: Please use format strings when concatenating
juliandoucette 2016/01/21 14:41:35 Acknowledged.
72 if source.has_localizable_file(locale, page): 72 if source.has_localizable_file(locale, page):
73 return (page, source.read_localizable_file(locale, page)) 73 return (page, source.read_localizable_file(locale, page))
74 74
75 return (None, None) 75 return (None, None)
76 76
77 def has_conflicting_pages(page): 77 def has_conflicting_pages(page):
78 pages = [p for p, _ in source.list_pages()] 78 pages = [p for p, _ in source.list_pages()]
79 pages.extend(source.list_localizable_files()) 79 pages.extend(source.list_localizable_files())
80 80
81 if pages.count(page) > 1: 81 if pages.count(page) > 1:
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 113
114 if isinstance(data, unicode): 114 if isinstance(data, unicode):
115 data = data.encode(UNICODE_ENCODING) 115 data = data.encode(UNICODE_ENCODING)
116 mime = "%s; charset=%s" % (mime, UNICODE_ENCODING) 116 mime = "%s; charset=%s" % (mime, UNICODE_ENCODING)
117 117
118 start_response("200 OK", [("Content-Type", mime)]) 118 start_response("200 OK", [("Content-Type", mime)])
119 return [data] 119 return [data]
120 120
121 if __name__ == "__main__": 121 if __name__ == "__main__":
122 122
123 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')
124 parser.add_argument('path', nargs='?', default=os.curdir) 124 parser.add_argument('path', nargs='?', default=os.curdir)
125 parser.add_argument('-n', '--address', default='localhost', help='Address of t he interface the server will listen to.') 125 parser.add_argument('-a', '--address', default='localhost', help='Address of t he interface the server will listen on')
Sebastian Noack 2016/01/21 14:14:08 Nit: It's semantically not a full sentence. So no
juliandoucette 2016/01/21 14:41:36 Acknowledged.
126 parser.add_argument('-p', '--port', type=int, default=5000, help='Port number. ') 126 parser.add_argument('-p', '--port', type=int, default=5000, help='TCP port the server will listen on')
Sebastian Noack 2016/01/21 14:14:09 Nit: This help text doesn't tell anything that the
juliandoucette 2016/01/21 14:41:36 Acknowledged.
127 parser.add_argument('-l', '--listen', help='Address and port number separated by a semicolin.')
Sebastian Noack 2016/01/21 14:14:08 I didn't meant to implement both, --address/--port
juliandoucette 2016/01/21 14:41:35 - Sorry, I misunderstood - I agree - I will go wit
128 args = parser.parse_args() 127 args = parser.parse_args()
129 128
130 source = FileSource(args.path) 129 source = FileSource(args.path)
131 address = args.address 130 address = args.address
132 port = args.port 131 port = args.port
133
134 if (args.listen):
135 listen = str.split(args.listen, ':')
Sebastian Noack 2016/01/21 14:14:08 Nit: args.listen.split(":")
juliandoucette 2016/01/21 14:41:35 Acknowledged.
136 if (len(listen) > 1):
137 port = int(listen[1])
138 address = listen[0]
139 132
140 try: 133 try:
141 from werkzeug.serving import ThreadedWSGIServer, run_simple 134 from werkzeug.serving import ThreadedWSGIServer, run_simple
142 135
143 # see https://github.com/mitsuhiko/werkzeug/pull/770 136 # see https://github.com/mitsuhiko/werkzeug/pull/770
144 ThreadedWSGIServer.daemon_threads = True 137 ThreadedWSGIServer.daemon_threads = True
145 138
146 def run(*args, **kwargs): 139 def run(*args, **kwargs):
147 # The werkzeug logger must be configured before the 140 # The werkzeug logger must be configured before the
148 # root logger. Also we must prevent it from propagating 141 # root logger. Also we must prevent it from propagating
(...skipping 18 matching lines...) Expand all
167 return app(environ, start_response) 160 return app(environ, start_response)
168 except Exception, e: 161 except Exception, e:
169 return show_error(start_response, "500 Internal Server Error", 162 return show_error(start_response, "500 Internal Server Error",
170 uri=environ.get("PATH_INFO"), error=e) 163 uri=environ.get("PATH_INFO"), error=e)
171 164
172 server = make_server(host, port, wrapper, ThreadedWSGIServer) 165 server = make_server(host, port, wrapper, ThreadedWSGIServer)
173 print " * Running on http://%s:%i/" % server.server_address 166 print " * Running on http://%s:%i/" % server.server_address
174 server.serve_forever() 167 server.serve_forever()
175 168
176 run(address, 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