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

Unified 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: Address Piotr's comments. Created 5 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | mojo/devtools/common/devtoolslib/shell_arguments.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/devtools/common/devtoolslib/http_server.py
diff --git a/mojo/devtools/common/devtoolslib/http_server.py b/mojo/devtools/common/devtoolslib/http_server.py
index d8a275770135205263026d3cba56a3aa733ddf77..6267af9531d1a062fee5eb75bb7555bc7dedce11 100644
--- a/mojo/devtools/common/devtoolslib/http_server.py
+++ b/mojo/devtools/common/devtoolslib/http_server.py
@@ -6,15 +6,14 @@ import atexit
import datetime
import email.utils
import errno
-import gzip
import hashlib
import logging
import math
import os.path
-import shutil
import socket
-import threading
+import subprocess
import tempfile
+import threading
import SimpleHTTPServer
import SocketServer
@@ -146,24 +145,30 @@ def _get_handler_class_for_path(mappings):
SimpleHTTPServer.SimpleHTTPRequestHandler.translate_path(self, path))
for prefix, local_base_path_list in mappings:
- if normalized_path.startswith(prefix):
- for local_base_path in local_base_path_list:
- candidate = os.path.join(local_base_path,
- normalized_path[len(prefix):])
- if os.path.isfile(candidate):
- if gzipped:
- if not self.gzipped_file:
- self.gzipped_file = tempfile.NamedTemporaryFile(delete=False)
- self.original_file_name = candidate
- with open(candidate, 'rb') as source:
- with gzip.GzipFile(fileobj=self.gzipped_file) as target:
- shutil.copyfileobj(source, target)
- self.gzipped_file.close()
- return self.gzipped_file.name
- return candidate
- else:
- self.send_response(404)
- return None
+ if not normalized_path.startswith(prefix):
+ continue
+
+ for local_base_path in local_base_path_list:
+ candidate = os.path.join(local_base_path,
+ normalized_path[len(prefix):])
+ if os.path.isfile(candidate):
+ if gzipped:
+ if not self.gzipped_file:
+ self.gzipped_file = tempfile.NamedTemporaryFile(delete=False)
piotrt 2015/08/25 11:55:23 I would consider extracting lines 157-166? to a se
ppi 2015/08/25 12:07:43 Good point, done.
+ self.original_file_name = candidate
+ try:
+ subprocess.check_call(['gzip', '-c', candidate],
+ stdout=self.gzipped_file)
+ except Exception:
+ print ('http_server: call to gzip failed, make sure that '
+ 'gzip is installed on the host.')
+ raise
+ self.gzipped_file.close()
+ return self.gzipped_file.name
+ return candidate
+ else:
+ self.send_response(404)
+ return None
self.send_response(404)
return None
« 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