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

Side by Side Diff: mojo/devtools/common/devtoolslib/http_server.py

Issue 1316443002: Call `gzip` in subprocess instead of gzipping in Python in http_server. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 3 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
« no previous file with comments | « no previous file | mojo/devtools/common/devtoolslib/shell_arguments.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import atexit 5 import atexit
6 import datetime 6 import datetime
7 import email.utils 7 import email.utils
8 import errno 8 import errno
9 import gzip
10 import hashlib 9 import hashlib
11 import logging 10 import logging
12 import math 11 import math
13 import os.path 12 import os.path
14 import shutil
15 import socket 13 import socket
14 import subprocess
15 import tempfile
16 import threading 16 import threading
17 import tempfile
18 17
19 import SimpleHTTPServer 18 import SimpleHTTPServer
20 import SocketServer 19 import SocketServer
21 20
22 _ZERO = datetime.timedelta(0) 21 _ZERO = datetime.timedelta(0)
23 22
24 23
25 class UTC_TZINFO(datetime.tzinfo): 24 class UTC_TZINFO(datetime.tzinfo):
26 """UTC time zone representation.""" 25 """UTC time zone representation."""
27 26
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 for prefix, local_base_path_list in mappings: 147 for prefix, local_base_path_list in mappings:
149 if normalized_path.startswith(prefix): 148 if normalized_path.startswith(prefix):
150 for local_base_path in local_base_path_list: 149 for local_base_path in local_base_path_list:
151 candidate = os.path.join(local_base_path, 150 candidate = os.path.join(local_base_path,
152 normalized_path[len(prefix):]) 151 normalized_path[len(prefix):])
153 if os.path.isfile(candidate): 152 if os.path.isfile(candidate):
154 if gzipped: 153 if gzipped:
155 if not self.gzipped_file: 154 if not self.gzipped_file:
156 self.gzipped_file = tempfile.NamedTemporaryFile(delete=False) 155 self.gzipped_file = tempfile.NamedTemporaryFile(delete=False)
157 self.original_file_name = candidate 156 self.original_file_name = candidate
158 with open(candidate, 'rb') as source: 157 subprocess.check_call(['gzip', '-c', candidate],
piotrt 2015/08/25 09:23:36 Maybe it would be good to handle errors here? the
ppi 2015/08/25 11:34:36 Done.
159 with gzip.GzipFile(fileobj=self.gzipped_file) as target: 158 stdout=self.gzipped_file)
160 shutil.copyfileobj(source, target)
161 self.gzipped_file.close() 159 self.gzipped_file.close()
162 return self.gzipped_file.name 160 return self.gzipped_file.name
163 return candidate 161 return candidate
164 else: 162 else:
165 self.send_response(404) 163 self.send_response(404)
166 return None 164 return None
167 self.send_response(404) 165 self.send_response(404)
168 return None 166 return None
169 167
170 def guess_type(self, path): 168 def guess_type(self, path):
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 except socket.error as v: 218 except socket.error as v:
221 error_code = v[0] 219 error_code = v[0]
222 print 'Failed to start http server for %s on port %d: %s.' % ( 220 print 'Failed to start http server for %s on port %d: %s.' % (
223 str(mappings), host_port, os.strerror(error_code)) 221 str(mappings), host_port, os.strerror(error_code))
224 if error_code == errno.EADDRINUSE: 222 if error_code == errno.EADDRINUSE:
225 print (' Run `fuser %d/tcp` to find out which process is using the port;' 223 print (' Run `fuser %d/tcp` to find out which process is using the port;'
226 % host_port) 224 % host_port)
227 print (' or `fuser -k %d/tcp` terminate it.' % host_port) 225 print (' or `fuser -k %d/tcp` terminate it.' % host_port)
228 print '---' 226 print '---'
229 raise 227 raise
OLDNEW
« no previous file with comments | « no previous file | mojo/devtools/common/devtoolslib/shell_arguments.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698