Diff
Modified: trunk/Tools/ChangeLog (100591 => 100592)
--- trunk/Tools/ChangeLog 2011-11-17 10:58:56 UTC (rev 100591)
+++ trunk/Tools/ChangeLog 2011-11-17 11:01:53 UTC (rev 100592)
@@ -1,5 +1,22 @@
2011-11-17 Adam Barth <aba...@webkit.org>
+ Move test_results_uploader.py out of layout_package
+ https://bugs.webkit.org/show_bug.cgi?id=72590
+
+ Reviewed by Eric Seidel.
+
+ Most of the lines of code in this file are wrong, but I've restrained
+ myself and only changed a few of them to generalized this class to the
+ common package.
+
+ This is part of a series of patches to remove layout_package.
+
+ * Scripts/webkitpy/common/net/file_uploader.py: Copied from Tools/Scripts/webkitpy/layout_tests/layout_package/test_results_uploader.py.
+ * Scripts/webkitpy/layout_tests/layout_package/json_results_generator.py:
+ * Scripts/webkitpy/layout_tests/layout_package/test_results_uploader.py: Removed.
+
+2011-11-17 Adam Barth <aba...@webkit.org>
+
Unreviewed. Fix style nits in printing.py.
* Scripts/webkitpy/layout_tests/views/printing.py:
Copied: trunk/Tools/Scripts/webkitpy/common/net/file_uploader.py (from rev 100591, trunk/Tools/Scripts/webkitpy/layout_tests/layout_package/test_results_uploader.py) (0 => 100592)
--- trunk/Tools/Scripts/webkitpy/common/net/file_uploader.py (rev 0)
+++ trunk/Tools/Scripts/webkitpy/common/net/file_uploader.py 2011-11-17 11:01:53 UTC (rev 100592)
@@ -0,0 +1,114 @@
+#!/usr/bin/env python
+# Copyright (C) 2010 Google Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+from __future__ import with_statement
+
+import codecs
+import mimetypes
+import socket
+import urllib2
+
+from webkitpy.common.net.networktransaction import NetworkTransaction
+
+
+def get_mime_type(filename):
+ return mimetypes.guess_type(filename)[0] or 'application/octet-stream'
+
+
+# FIXME: Rather than taking tuples, this function should take more structured data.
+def _encode_multipart_form_data(fields, files):
+ """Encode form fields for multipart/form-data.
+
+ Args:
+ fields: A sequence of (name, value) elements for regular form fields.
+ files: A sequence of (name, filename, value) elements for data to be
+ uploaded as files.
+ Returns:
+ (content_type, body) ready for httplib.HTTP instance.
+
+ Source:
+ http://code.google.com/p/rietveld/source/browse/trunk/upload.py
+ """
+ BOUNDARY = '-M-A-G-I-C---B-O-U-N-D-A-R-Y-'
+ CRLF = '\r\n'
+ lines = []
+
+ for key, value in fields:
+ lines.append('--' + BOUNDARY)
+ lines.append('Content-Disposition: form-data; name="%s"' % key)
+ lines.append('')
+ if isinstance(value, unicode):
+ value = value.encode('utf-8')
+ lines.append(value)
+
+ for key, filename, value in files:
+ lines.append('--' + BOUNDARY)
+ lines.append('Content-Disposition: form-data; name="%s"; filename="%s"' % (key, filename))
+ lines.append('Content-Type: %s' % get_mime_type(filename))
+ lines.append('')
+ if isinstance(value, unicode):
+ value = value.encode('utf-8')
+ lines.append(value)
+
+ lines.append('--' + BOUNDARY + '--')
+ lines.append('')
+ body = CRLF.join(lines)
+ content_type = 'multipart/form-data; boundary=%s' % BOUNDARY
+ return content_type, body
+
+
+class FileUploader(object):
+ def __init__(self, url):
+ self._url = url
+
+ def _upload_files(self, attrs, file_objs):
+ # FIXME: We should use the same variable names for the formal and actual parameters.
+ content_type, data = "" file_objs)
+ headers = {
+ "Content-Type": content_type,
+ }
+ # FIXME: We should talk to the network via a Host object.
+ request = urllib2.Request(self._url, data, headers)
+ urllib2.urlopen(request)
+
+ def upload(self, params, files, timeout_seconds):
+ file_objs = []
+ for filename, path in files:
+ # FIXME: We should talk to the filesytem via a Host object.
+ with codecs.open(path, "rb") as file:
+ file_objs.append(('file', filename, file.read()))
+
+ orig_timeout = socket.getdefaulttimeout()
+ try:
+ # FIXME: We shouldn't mutate global static state.
+ socket.setdefaulttimeout(timeout_seconds)
+ NetworkTransaction(timeout_seconds=timeout_seconds).run(
+ lambda: self._upload_files(params, file_objs))
+ finally:
+ socket.setdefaulttimeout(orig_timeout)
Modified: trunk/Tools/Scripts/webkitpy/layout_tests/layout_package/json_results_generator.py (100591 => 100592)
--- trunk/Tools/Scripts/webkitpy/layout_tests/layout_package/json_results_generator.py 2011-11-17 10:58:56 UTC (rev 100591)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/layout_package/json_results_generator.py 2011-11-17 11:01:53 UTC (rev 100592)
@@ -34,7 +34,7 @@
import urllib2
import xml.dom.minidom
-from webkitpy.layout_tests.layout_package import test_results_uploader
+from webkitpy.common.net.file_uploader import FileUploader
try:
import json
@@ -317,8 +317,8 @@
files = [(file, self._fs.join(self._results_directory, file))
for file in json_files]
- uploader = test_results_uploader.TestResultsUploader(
- self._test_results_server)
+ url = "" % self._test_results_server
+ uploader = FileUploader(url)
try:
# Set uploading timeout in case appengine server is having problem.
# 120 seconds are more than enough to upload test results.
@@ -418,6 +418,7 @@
urllib2.quote(self._test_type)))
try:
+ # FIXME: We should talk to the network via a Host object.
results_file = urllib2.urlopen(results_file_url)
info = results_file.info()
old_results = results_file.read()
Deleted: trunk/Tools/Scripts/webkitpy/layout_tests/layout_package/test_results_uploader.py (100591 => 100592)
--- trunk/Tools/Scripts/webkitpy/layout_tests/layout_package/test_results_uploader.py 2011-11-17 10:58:56 UTC (rev 100591)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/layout_package/test_results_uploader.py 2011-11-17 11:01:53 UTC (rev 100592)
@@ -1,107 +0,0 @@
-#!/usr/bin/env python
-# Copyright (C) 2010 Google Inc. All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are
-# met:
-#
-# * Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-# * Redistributions in binary form must reproduce the above
-# copyright notice, this list of conditions and the following disclaimer
-# in the documentation and/or other materials provided with the
-# distribution.
-# * Neither the name of Google Inc. nor the names of its
-# contributors may be used to endorse or promote products derived from
-# this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-from __future__ import with_statement
-
-import codecs
-import mimetypes
-import socket
-import urllib2
-
-from webkitpy.common.net.networktransaction import NetworkTransaction
-
-def get_mime_type(filename):
- return mimetypes.guess_type(filename)[0] or 'application/octet-stream'
-
-
-def _encode_multipart_form_data(fields, files):
- """Encode form fields for multipart/form-data.
-
- Args:
- fields: A sequence of (name, value) elements for regular form fields.
- files: A sequence of (name, filename, value) elements for data to be
- uploaded as files.
- Returns:
- (content_type, body) ready for httplib.HTTP instance.
-
- Source:
- http://code.google.com/p/rietveld/source/browse/trunk/upload.py
- """
- BOUNDARY = '-M-A-G-I-C---B-O-U-N-D-A-R-Y-'
- CRLF = '\r\n'
- lines = []
-
- for key, value in fields:
- lines.append('--' + BOUNDARY)
- lines.append('Content-Disposition: form-data; name="%s"' % key)
- lines.append('')
- if isinstance(value, unicode):
- value = value.encode('utf-8')
- lines.append(value)
-
- for key, filename, value in files:
- lines.append('--' + BOUNDARY)
- lines.append('Content-Disposition: form-data; name="%s"; filename="%s"' % (key, filename))
- lines.append('Content-Type: %s' % get_mime_type(filename))
- lines.append('')
- if isinstance(value, unicode):
- value = value.encode('utf-8')
- lines.append(value)
-
- lines.append('--' + BOUNDARY + '--')
- lines.append('')
- body = CRLF.join(lines)
- content_type = 'multipart/form-data; boundary=%s' % BOUNDARY
- return content_type, body
-
-
-class TestResultsUploader:
- def __init__(self, host):
- self._host = host
-
- def _upload_files(self, attrs, file_objs):
- url = "" % self._host
- content_type, data = "" file_objs)
- headers = {"Content-Type": content_type}
- request = urllib2.Request(url, data, headers)
- urllib2.urlopen(request)
-
- def upload(self, params, files, timeout_seconds):
- file_objs = []
- for filename, path in files:
- with codecs.open(path, "rb") as file:
- file_objs.append(('file', filename, file.read()))
-
- orig_timeout = socket.getdefaulttimeout()
- try:
- socket.setdefaulttimeout(timeout_seconds)
- NetworkTransaction(timeout_seconds=timeout_seconds).run(
- lambda: self._upload_files(params, file_objs))
- finally:
- socket.setdefaulttimeout(orig_timeout)