Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(285)

Side by Side Diff: gm/rebaseline_server/server.py

Issue 25774002: HTTP GM baseline viewer: server should serve files from gm/rebaseline_server dir (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 2
3 ''' 3 '''
4 Copyright 2013 Google Inc. 4 Copyright 2013 Google Inc.
5 5
6 Use of this source code is governed by a BSD-style license that can be 6 Use of this source code is governed by a BSD-style license that can be
7 found in the LICENSE file. 7 found in the LICENSE file.
8 ''' 8 '''
9 9
10 ''' 10 '''
11 HTTP server for our HTML rebaseline viewer. 11 HTTP server for our HTML rebaseline viewer.
12 ''' 12 '''
13 13
14 # System-level imports 14 # System-level imports
15 import argparse 15 import argparse
16 import BaseHTTPServer 16 import BaseHTTPServer
17 import json 17 import json
18 import os 18 import os
19 import posixpath 19 import posixpath
20 import re 20 import re
21 import shutil 21 import shutil
22 import sys 22 import sys
23 23
24 # Imports from within Skia 24 # Imports from within Skia
25 # 25 #
26 # We need to add the 'tools' directory, so that we can import svn.py within 26 # We need to add the 'tools' directory, so that we can import svn.py within
27 # that directory. 27 # that directory.
28 # Make sure that the 'tools' dir is in the PYTHONPATH, but add it at the *end* 28 # Make sure that the 'tools' dir is in the PYTHONPATH, but add it at the *end*
29 # so any dirs that are already in the PYTHONPATH will be preferred. 29 # so any dirs that are already in the PYTHONPATH will be preferred.
30 TRUNK_DIRECTORY = os.path.dirname(os.path.dirname(os.path.dirname( 30 PARENT_DIRECTORY = os.path.dirname(os.path.realpath(__file__))
31 os.path.realpath(__file__)))) 31 TRUNK_DIRECTORY = os.path.dirname(os.path.dirname(PARENT_DIRECTORY))
32 TOOLS_DIRECTORY = os.path.join(TRUNK_DIRECTORY, 'tools') 32 TOOLS_DIRECTORY = os.path.join(TRUNK_DIRECTORY, 'tools')
33 if TOOLS_DIRECTORY not in sys.path: 33 if TOOLS_DIRECTORY not in sys.path:
34 sys.path.append(TOOLS_DIRECTORY) 34 sys.path.append(TOOLS_DIRECTORY)
35 import svn 35 import svn
36 36
37 # Imports from local dir 37 # Imports from local dir
38 import results 38 import results
39 39
40 ACTUALS_SVN_REPO = 'http://skia-autogen.googlecode.com/svn/gm-actual' 40 ACTUALS_SVN_REPO = 'http://skia-autogen.googlecode.com/svn/gm-actual'
41 PATHSPLIT_RE = re.compile('/([^/]+)/(.+)') 41 PATHSPLIT_RE = re.compile('/([^/]+)/(.+)')
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 TODO(epoger): Unless we start making use of result_type, remove that 150 TODO(epoger): Unless we start making use of result_type, remove that
151 parameter.""" 151 parameter."""
152 print 'do_GET_results: sending results of type "%s"' % result_type 152 print 'do_GET_results: sending results of type "%s"' % result_type
153 response_dict = _SERVER.results.GetAll() 153 response_dict = _SERVER.results.GetAll()
154 if response_dict: 154 if response_dict:
155 self.send_json_dict(response_dict) 155 self.send_json_dict(response_dict)
156 else: 156 else:
157 self.send_error(404) 157 self.send_error(404)
158 158
159 def do_GET_static(self, path): 159 def do_GET_static(self, path):
160 """ Handle a GET request for a file under the 'static' directory. """ 160 """ Handle a GET request for a file under the 'static' directory.
161 Only allow serving of files within the 'static' directory that is a
162 filesystem sibling of this script. """
161 print 'do_GET_static: sending file "%s"' % path 163 print 'do_GET_static: sending file "%s"' % path
162 self.send_file(posixpath.join('static', path)) 164 static_dir = os.path.realpath(os.path.join(PARENT_DIRECTORY, 'static'))
epoger 2013/10/02 18:39:56 Main purpose of this CL: make the server retrieve
165 full_path = os.path.realpath(os.path.join(static_dir, path))
166 if full_path.startswith(static_dir):
167 self.send_file(full_path)
168 else:
169 print ('Attempted do_GET_static() of path [%s] outside of static dir [%s]'
epoger 2013/10/02 18:39:56 While I was at it, put in some double-checking to
170 % (full_path, static_dir))
171 self.send_error(404)
163 172
164 def redirect_to(self, url): 173 def redirect_to(self, url):
165 """ Redirect the HTTP client to a different url. """ 174 """ Redirect the HTTP client to a different url. """
166 self.send_response(301) 175 self.send_response(301)
167 self.send_header('Location', url) 176 self.send_header('Location', url)
168 self.end_headers() 177 self.end_headers()
169 178
170 def send_file(self, path): 179 def send_file(self, path):
171 """ Send the contents of the file at this path, with a mimetype based 180 """ Send the contents of the file at this path, with a mimetype based
172 on the filename extension. """ 181 on the filename extension. """
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 'defaults to %(default)s'), 228 'defaults to %(default)s'),
220 default=DEFAULT_PORT) 229 default=DEFAULT_PORT)
221 args = parser.parse_args() 230 args = parser.parse_args()
222 global _SERVER 231 global _SERVER
223 _SERVER = Server(expectations_dir=args.expectations_dir, 232 _SERVER = Server(expectations_dir=args.expectations_dir,
224 port=args.port, export=args.export) 233 port=args.port, export=args.export)
225 _SERVER.run() 234 _SERVER.run()
226 235
227 if __name__ == '__main__': 236 if __name__ == '__main__':
228 main() 237 main()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698