summaryrefslogtreecommitdiff
path: root/Tools/Scripts/webkitpy/common/system
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@nokia.com>2012-02-09 14:16:12 +0100
committerSimon Hausmann <simon.hausmann@nokia.com>2012-02-09 14:16:12 +0100
commit03e12282df9aa1e1fb05a8b90f1cfc2e08764cec (patch)
tree52599cd0ab782b1768e23ad176f7618f98333cb6 /Tools/Scripts/webkitpy/common/system
parentcd44dc59cdfc39534aef4d417e9f3c412e3be139 (diff)
downloadqtwebkit-03e12282df9aa1e1fb05a8b90f1cfc2e08764cec.tar.gz
Imported WebKit commit e09a82039aa4273ab318b71122e92d8e5f233525 (http://svn.webkit.org/repository/webkit/trunk@107223)
Diffstat (limited to 'Tools/Scripts/webkitpy/common/system')
-rwxr-xr-xTools/Scripts/webkitpy/common/system/autoinstall.py41
-rw-r--r--Tools/Scripts/webkitpy/common/system/crashlogs.py2
-rw-r--r--Tools/Scripts/webkitpy/common/system/deprecated_logging.py2
-rw-r--r--Tools/Scripts/webkitpy/common/system/fileset.py2
-rw-r--r--Tools/Scripts/webkitpy/common/system/filesystem.py6
-rw-r--r--Tools/Scripts/webkitpy/common/system/filesystem_mock.py31
-rw-r--r--Tools/Scripts/webkitpy/common/system/filesystem_unittest.py2
-rw-r--r--Tools/Scripts/webkitpy/common/system/ospath.py85
-rw-r--r--Tools/Scripts/webkitpy/common/system/ospath_unittest.py62
-rw-r--r--Tools/Scripts/webkitpy/common/system/outputcapture.py13
-rw-r--r--Tools/Scripts/webkitpy/common/system/path.py1
11 files changed, 39 insertions, 208 deletions
diff --git a/Tools/Scripts/webkitpy/common/system/autoinstall.py b/Tools/Scripts/webkitpy/common/system/autoinstall.py
index 4ffcccc64..a928db63a 100755
--- a/Tools/Scripts/webkitpy/common/system/autoinstall.py
+++ b/Tools/Scripts/webkitpy/common/system/autoinstall.py
@@ -31,8 +31,6 @@
"""Support for automatically downloading Python packages from an URL."""
-from __future__ import with_statement
-
import codecs
import logging
import new
@@ -261,43 +259,6 @@ class AutoInstaller(object):
return target_path
- # This is a replacement for ZipFile.extractall(), which is
- # available in Python 2.6 but not in earlier versions.
- def _extract_all(self, zip_file, target_dir):
- self._log_transfer("Extracting zip file...", zip_file, target_dir)
-
- # This is helpful for debugging purposes.
- _log.debug("Listing zip file contents...")
- for name in zip_file.namelist():
- _log.debug(' * "%s"' % name)
-
- for name in zip_file.namelist():
- path = os.path.join(target_dir, name)
- self._log_transfer("Extracting...", name, path)
-
- if not os.path.basename(path):
- # Then the path ends in a slash, so it is a directory.
- self._create_directory(path)
- continue
- # Otherwise, it is a file.
-
- try:
- # We open this file w/o encoding, as we're reading/writing
- # the raw byte-stream from the zip file.
- outfile = open(path, 'wb')
- except IOError, err:
- # Not all zip files seem to list the directories explicitly,
- # so try again after creating the containing directory.
- _log.debug("Got IOError: retrying after creating directory...")
- dir = os.path.dirname(path)
- self._create_directory(dir)
- outfile = open(path, 'wb')
-
- try:
- outfile.write(zip_file.read(name))
- finally:
- outfile.close()
-
def _unzip(self, path, scratch_dir):
# zipfile.extractall() extracts to a path without the
# trailing ".zip".
@@ -315,7 +276,7 @@ class AutoInstaller(object):
raise Exception(message)
try:
- self._extract_all(zip_file, scratch_dir)
+ zip_file.extractall(scratch_dir)
finally:
zip_file.close()
diff --git a/Tools/Scripts/webkitpy/common/system/crashlogs.py b/Tools/Scripts/webkitpy/common/system/crashlogs.py
index 06b0d12d7..a6b6575f6 100644
--- a/Tools/Scripts/webkitpy/common/system/crashlogs.py
+++ b/Tools/Scripts/webkitpy/common/system/crashlogs.py
@@ -26,8 +26,6 @@
# (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 os
import re
import sys
diff --git a/Tools/Scripts/webkitpy/common/system/deprecated_logging.py b/Tools/Scripts/webkitpy/common/system/deprecated_logging.py
index 9e6b5298f..137535438 100644
--- a/Tools/Scripts/webkitpy/common/system/deprecated_logging.py
+++ b/Tools/Scripts/webkitpy/common/system/deprecated_logging.py
@@ -41,7 +41,7 @@ def log(string):
def error(string):
log("ERROR: %s" % string)
- exit(1)
+ sys.exit(1)
# Simple class to split output between multiple destinations
diff --git a/Tools/Scripts/webkitpy/common/system/fileset.py b/Tools/Scripts/webkitpy/common/system/fileset.py
index 598c1c595..57e9a284e 100644
--- a/Tools/Scripts/webkitpy/common/system/fileset.py
+++ b/Tools/Scripts/webkitpy/common/system/fileset.py
@@ -21,8 +21,6 @@
# (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
-
from webkitpy.common.system.filesystem import FileSystem
diff --git a/Tools/Scripts/webkitpy/common/system/filesystem.py b/Tools/Scripts/webkitpy/common/system/filesystem.py
index 7de41a424..60b680c06 100644
--- a/Tools/Scripts/webkitpy/common/system/filesystem.py
+++ b/Tools/Scripts/webkitpy/common/system/filesystem.py
@@ -28,8 +28,6 @@
"""Wrapper object for the file system / source tree."""
-from __future__ import with_statement
-
import codecs
import errno
import exceptions
@@ -41,8 +39,6 @@ import sys
import tempfile
import time
-from webkitpy.common.system import ospath
-
class FileSystem(object):
"""FileSystem interface for webkitpy.
@@ -229,7 +225,7 @@ class FileSystem(object):
return hashlib.sha1(contents).hexdigest()
def relpath(self, path, start='.'):
- return ospath.relpath(path, start)
+ return os.path.relpath(path, start)
class _WindowsError(exceptions.OSError):
"""Fake exception for Linux and Mac."""
diff --git a/Tools/Scripts/webkitpy/common/system/filesystem_mock.py b/Tools/Scripts/webkitpy/common/system/filesystem_mock.py
index e91d6682a..6e106dd83 100644
--- a/Tools/Scripts/webkitpy/common/system/filesystem_mock.py
+++ b/Tools/Scripts/webkitpy/common/system/filesystem_mock.py
@@ -33,7 +33,6 @@ import os
import re
from webkitpy.common.system import path
-from webkitpy.common.system import ospath
class MockFileSystem(object):
@@ -180,7 +179,7 @@ class MockFileSystem(object):
# to a different thread and potentially modifying the dict in
# mid-iteration.
files = self.files.keys()[:]
- result = any(f.startswith(path) for f in files)
+ result = any(f.startswith(path) and len(self.split(f)[0]) >= len(path) for f in files)
if result:
self.dirs.add(path)
return result
@@ -303,7 +302,33 @@ class MockFileSystem(object):
return hashlib.sha1(contents).hexdigest()
def relpath(self, path, start='.'):
- return ospath.relpath(path, start, self.abspath, self.sep)
+ # Since os.path.relpath() calls os.path.normpath()
+ # (see http://docs.python.org/library/os.path.html#os.path.abspath )
+ # it also removes trailing slashes and converts forward and backward
+ # slashes to the preferred slash os.sep.
+ start = self.abspath(start)
+ path = self.abspath(path)
+
+ if not path.lower().startswith(start.lower()):
+ # Then path is outside the directory given by start.
+ return None # FIXME: os.relpath still returns a path here.
+
+ rel_path = path[len(start):]
+
+ if not rel_path:
+ # Then the paths are the same.
+ pass
+ elif rel_path[0] == self.sep:
+ # It is probably sufficient to remove just the first character
+ # since os.path.normpath() collapses separators, but we use
+ # lstrip() just to be sure.
+ rel_path = rel_path.lstrip(self.sep)
+ else:
+ # We are in the case typified by the following example:
+ # path = "/tmp/foobar", start = "/tmp/foo" -> rel_path = "bar"
+ return None
+
+ return rel_path
def remove(self, path):
if self.files[path] is None:
diff --git a/Tools/Scripts/webkitpy/common/system/filesystem_unittest.py b/Tools/Scripts/webkitpy/common/system/filesystem_unittest.py
index c24344c76..4859f7294 100644
--- a/Tools/Scripts/webkitpy/common/system/filesystem_unittest.py
+++ b/Tools/Scripts/webkitpy/common/system/filesystem_unittest.py
@@ -31,8 +31,6 @@
# important; without it, Python will choke while trying to parse the file,
# since it includes non-ASCII characters.
-from __future__ import with_statement
-
import os
import stat
import sys
diff --git a/Tools/Scripts/webkitpy/common/system/ospath.py b/Tools/Scripts/webkitpy/common/system/ospath.py
deleted file mode 100644
index 2504645c0..000000000
--- a/Tools/Scripts/webkitpy/common/system/ospath.py
+++ /dev/null
@@ -1,85 +0,0 @@
-# Copyright (C) 2010 Chris Jerdonek (cjerdonek@webkit.org)
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-# 2. 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.
-#
-# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS 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 APPLE INC. OR ITS 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.
-
-"""Contains a substitute for Python 2.6's os.path.relpath()."""
-
-import os
-
-
-# This function is a replacement for os.path.relpath(), which is only
-# available in Python 2.6:
-#
-# http://docs.python.org/library/os.path.html#os.path.relpath
-#
-# It should behave essentially the same as os.path.relpath(), except for
-# returning None on paths not contained in abs_start_path.
-def relpath(path, start_path, os_path_abspath=None, sep=None):
- """Return a path relative to the given start path, or None.
-
- Returns None if the path is not contained in the directory start_path.
-
- Args:
- path: An absolute or relative path to convert to a relative path.
- start_path: The path relative to which the given path should be
- converted.
- os_path_abspath: A replacement function for unit testing. This
- function should strip trailing slashes just like
- os.path.abspath(). Defaults to os.path.abspath.
- sep: Path separator. Defaults to os.path.sep
-
- """
- if os_path_abspath is None:
- os_path_abspath = os.path.abspath
- sep = sep or os.sep
-
- # Since os_path_abspath() calls os.path.normpath()--
- #
- # (see http://docs.python.org/library/os.path.html#os.path.abspath )
- #
- # it also removes trailing slashes and converts forward and backward
- # slashes to the preferred slash os.sep.
- start_path = os_path_abspath(start_path)
- path = os_path_abspath(path)
-
- if not path.lower().startswith(start_path.lower()):
- # Then path is outside the directory given by start_path.
- return None
-
- rel_path = path[len(start_path):]
-
- if not rel_path:
- # Then the paths are the same.
- pass
- elif rel_path[0] == sep:
- # It is probably sufficient to remove just the first character
- # since os.path.normpath() collapses separators, but we use
- # lstrip() just to be sure.
- rel_path = rel_path.lstrip(sep)
- else:
- # We are in the case typified by the following example:
- #
- # start_path = "/tmp/foo"
- # path = "/tmp/foobar"
- # rel_path = "bar"
- return None
-
- return rel_path
diff --git a/Tools/Scripts/webkitpy/common/system/ospath_unittest.py b/Tools/Scripts/webkitpy/common/system/ospath_unittest.py
deleted file mode 100644
index d84c2c64c..000000000
--- a/Tools/Scripts/webkitpy/common/system/ospath_unittest.py
+++ /dev/null
@@ -1,62 +0,0 @@
-# Copyright (C) 2010 Chris Jerdonek (cjerdonek@webkit.org)
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-# 2. 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.
-#
-# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS 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 APPLE INC. OR ITS 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.
-
-"""Unit tests for ospath.py."""
-
-import os
-import unittest
-
-from webkitpy.common.system.ospath import relpath
-
-
-# Make sure the tests in this class are platform independent.
-class RelPathTest(unittest.TestCase):
-
- """Tests relpath()."""
-
- os_path_abspath = lambda self, path: path
-
- def _rel_path(self, path, abs_start_path):
- return relpath(path, abs_start_path, self.os_path_abspath)
-
- def test_same_path(self):
- rel_path = self._rel_path("WebKit", "WebKit")
- self.assertEquals(rel_path, "")
-
- def test_long_rel_path(self):
- start_path = "WebKit"
- expected_rel_path = os.path.join("test", "Foo.txt")
- path = os.path.join(start_path, expected_rel_path)
-
- rel_path = self._rel_path(path, start_path)
- self.assertEquals(expected_rel_path, rel_path)
-
- def test_none_rel_path(self):
- """Test _rel_path() with None return value."""
- start_path = "WebKit"
- path = os.path.join("other_dir", "foo.txt")
-
- rel_path = self._rel_path(path, start_path)
- self.assertTrue(rel_path is None)
-
- rel_path = self._rel_path("Tools", "WebKit")
- self.assertTrue(rel_path is None)
diff --git a/Tools/Scripts/webkitpy/common/system/outputcapture.py b/Tools/Scripts/webkitpy/common/system/outputcapture.py
index cb6edbec7..66188c0cb 100644
--- a/Tools/Scripts/webkitpy/common/system/outputcapture.py
+++ b/Tools/Scripts/webkitpy/common/system/outputcapture.py
@@ -74,11 +74,14 @@ class OutputCapture(object):
def assert_outputs(self, testcase, function, args=[], kwargs={}, expected_stdout="", expected_stderr="", expected_exception=None, expected_logs=None):
self.capture_output()
- if expected_exception:
- return_value = testcase.assertRaises(expected_exception, function, *args, **kwargs)
- else:
- return_value = function(*args, **kwargs)
- (stdout_string, stderr_string, logs_string) = self.restore_output()
+ try:
+ if expected_exception:
+ return_value = testcase.assertRaises(expected_exception, function, *args, **kwargs)
+ else:
+ return_value = function(*args, **kwargs)
+ finally:
+ (stdout_string, stderr_string, logs_string) = self.restore_output()
+
testcase.assertEqual(stdout_string, expected_stdout)
testcase.assertEqual(stderr_string, expected_stderr)
if expected_logs is not None:
diff --git a/Tools/Scripts/webkitpy/common/system/path.py b/Tools/Scripts/webkitpy/common/system/path.py
index 09787d7e8..b7ad3723a 100644
--- a/Tools/Scripts/webkitpy/common/system/path.py
+++ b/Tools/Scripts/webkitpy/common/system/path.py
@@ -27,7 +27,6 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""generic routines to convert platform-specific paths to URIs."""
-from __future__ import with_statement
import atexit
import subprocess