Commit 31cb48a4 authored by maruel@chromium.org's avatar maruel@chromium.org

First pass to transition away for gclient_utils.Error and gclient_utils.CheckedCallError.

Make sure every site that catches gclient_utils.Error also catch
subprocess2.CalledProcessError.

BUG=
TEST=

Review URL: http://codereview.chromium.org/6691034

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@80339 0039d316-1c4b-4281-b951-d872f2087c98
parent 9ce0dff6
...@@ -39,6 +39,7 @@ from scm import SVN ...@@ -39,6 +39,7 @@ from scm import SVN
import fix_encoding import fix_encoding
import gclient_utils import gclient_utils
import presubmit_support import presubmit_support
import subprocess2
__version__ = '1.2' __version__ = '1.2'
...@@ -136,7 +137,7 @@ def GetCachedFile(filename, max_age=60*60*24*3, use_root=False): ...@@ -136,7 +137,7 @@ def GetCachedFile(filename, max_age=60*60*24*3, use_root=False):
# First we check if we have a cached version. # First we check if we have a cached version.
try: try:
cached_file = os.path.join(GetCacheDir(), filename) cached_file = os.path.join(GetCacheDir(), filename)
except gclient_utils.Error: except (gclient_utils.Error, subprocess2.CalledProcessError):
return None return None
if (not os.path.exists(cached_file) or if (not os.path.exists(cached_file) or
(time.time() - os.stat(cached_file).st_mtime) > max_age): (time.time() - os.stat(cached_file).st_mtime) > max_age):
...@@ -168,7 +169,7 @@ def GetCachedFile(filename, max_age=60*60*24*3, use_root=False): ...@@ -168,7 +169,7 @@ def GetCachedFile(filename, max_age=60*60*24*3, use_root=False):
# Exit the loop if the file was found. Override content. # Exit the loop if the file was found. Override content.
content = '\n'.join(content_array) content = '\n'.join(content_array)
break break
except gclient_utils.Error: except (gclient_utils.Error, subprocess2.CalledProcessError):
if content_array[0].startswith( if content_array[0].startswith(
'svn: Can\'t get username or password'): 'svn: Can\'t get username or password'):
ErrorExit('Your svn credentials expired. Please run svn update ' ErrorExit('Your svn credentials expired. Please run svn update '
...@@ -1425,7 +1426,7 @@ def main(argv): ...@@ -1425,7 +1426,7 @@ def main(argv):
try: try:
GetRepositoryRoot() GetRepositoryRoot()
except gclient_utils.Error: except (gclient_utils.Error, subprocess2.CalledProcessError):
print >> sys.stderr, 'To use gcl, you need to be in a subversion checkout.' print >> sys.stderr, 'To use gcl, you need to be in a subversion checkout.'
return 1 return 1
...@@ -1443,7 +1444,7 @@ def main(argv): ...@@ -1443,7 +1444,7 @@ def main(argv):
return command(argv[1:]) return command(argv[1:])
# Unknown command, try to pass that to svn # Unknown command, try to pass that to svn
return CMDpassthru(argv) return CMDpassthru(argv)
except gclient_utils.Error, e: except (gclient_utils.Error, subprocess2.CalledProcessError), e:
print >> sys.stderr, 'Got an exception' print >> sys.stderr, 'Got an exception'
print >> sys.stderr, str(e) print >> sys.stderr, str(e)
return 1 return 1
......
...@@ -68,6 +68,7 @@ import fix_encoding ...@@ -68,6 +68,7 @@ import fix_encoding
import gclient_scm import gclient_scm
import gclient_utils import gclient_utils
from third_party.repo.progress import Progress from third_party.repo.progress import Progress
import subprocess2
def attr(attribute, data): def attr(attribute, data):
...@@ -453,7 +454,7 @@ class Dependency(GClientKeywords, gclient_utils.WorkItem): ...@@ -453,7 +454,7 @@ class Dependency(GClientKeywords, gclient_utils.WorkItem):
try: try:
gclient_utils.CheckCallAndFilterAndHeader( gclient_utils.CheckCallAndFilterAndHeader(
command, cwd=self.root_dir(), always=True) command, cwd=self.root_dir(), always=True)
except gclient_utils.Error, e: except (gclient_utils.Error, subprocess2.CalledProcessError), e:
# Use a discrete exit status code of 2 to indicate that a hook action # Use a discrete exit status code of 2 to indicate that a hook action
# failed. Users of this script may wish to treat hook action failures # failed. Users of this script may wish to treat hook action failures
# differently from VC failures. # differently from VC failures.
...@@ -1261,7 +1262,7 @@ def Main(argv): ...@@ -1261,7 +1262,7 @@ def Main(argv):
# Not a known command. Default to help. # Not a known command. Default to help.
GenUsage(parser, 'help') GenUsage(parser, 'help')
return CMDhelp(parser, argv) return CMDhelp(parser, argv)
except gclient_utils.Error, e: except (gclient_utils.Error, subprocess2.CalledProcessError), e:
print >> sys.stderr, 'Error: %s' % str(e) print >> sys.stderr, 'Error: %s' % str(e)
return 1 return 1
......
...@@ -11,8 +11,9 @@ import re ...@@ -11,8 +11,9 @@ import re
import sys import sys
import time import time
import scm
import gclient_utils import gclient_utils
import scm
import subprocess2
class DiffFilterer(object): class DiffFilterer(object):
...@@ -495,7 +496,7 @@ class GitWrapper(SCMWrapper): ...@@ -495,7 +496,7 @@ class GitWrapper(SCMWrapper):
try: try:
self._Run(clone_cmd, options, cwd=self._root_dir) self._Run(clone_cmd, options, cwd=self._root_dir)
break break
except gclient_utils.Error, e: except (gclient_utils.Error, subprocess2.CalledProcessError), e:
# TODO(maruel): Hackish, should be fixed by moving _Run() to # TODO(maruel): Hackish, should be fixed by moving _Run() to
# CheckCall(). # CheckCall().
# Too bad we don't have access to the actual output. # Too bad we don't have access to the actual output.
...@@ -750,7 +751,7 @@ class SVNWrapper(SCMWrapper): ...@@ -750,7 +751,7 @@ class SVNWrapper(SCMWrapper):
# Get the existing scm url and the revision number of the current checkout. # Get the existing scm url and the revision number of the current checkout.
try: try:
from_info = scm.SVN.CaptureInfo(os.path.join(self.checkout_path, '.')) from_info = scm.SVN.CaptureInfo(os.path.join(self.checkout_path, '.'))
except gclient_utils.Error: except (gclient_utils.Error, subprocess2.CalledProcessError):
raise gclient_utils.Error( raise gclient_utils.Error(
('Can\'t update/checkout %s if an unversioned directory is present. ' ('Can\'t update/checkout %s if an unversioned directory is present. '
'Delete the directory and try again.') % self.checkout_path) 'Delete the directory and try again.') % self.checkout_path)
...@@ -772,7 +773,7 @@ class SVNWrapper(SCMWrapper): ...@@ -772,7 +773,7 @@ class SVNWrapper(SCMWrapper):
# The repository url changed, need to switch. # The repository url changed, need to switch.
try: try:
to_info = scm.SVN.CaptureInfo(url) to_info = scm.SVN.CaptureInfo(url)
except gclient_utils.Error: except (gclient_utils.Error, subprocess2.CalledProcessError):
# The url is invalid or the server is not accessible, it's safer to bail # The url is invalid or the server is not accessible, it's safer to bail
# out right now. # out right now.
raise gclient_utils.Error('This url is unreachable: %s' % url) raise gclient_utils.Error('This url is unreachable: %s' % url)
...@@ -889,7 +890,7 @@ class SVNWrapper(SCMWrapper): ...@@ -889,7 +890,7 @@ class SVNWrapper(SCMWrapper):
"""Display revision""" """Display revision"""
try: try:
return scm.SVN.CaptureRevision(self.checkout_path) return scm.SVN.CaptureRevision(self.checkout_path)
except gclient_utils.Error: except (gclient_utils.Error, subprocess2.CalledProcessError):
return None return None
def runhooks(self, options, args, file_list): def runhooks(self, options, args, file_list):
......
...@@ -17,6 +17,8 @@ import time ...@@ -17,6 +17,8 @@ import time
import xml.dom.minidom import xml.dom.minidom
import gclient_utils import gclient_utils
import subprocess2
def ValidateEmail(email): def ValidateEmail(email):
return (re.match(r"^[a-zA-Z0-9._%-+]+@[a-zA-Z0-9._%-]+.[a-zA-Z]{2,6}$", email) return (re.match(r"^[a-zA-Z0-9._%-+]+@[a-zA-Z0-9._%-]+.[a-zA-Z]{2,6}$", email)
...@@ -270,25 +272,25 @@ class GIT(object): ...@@ -270,25 +272,25 @@ class GIT(object):
try: try:
upstream_branch = GIT.Capture( upstream_branch = GIT.Capture(
['config', 'branch.%s.merge' % branch], cwd=cwd).strip() ['config', 'branch.%s.merge' % branch], cwd=cwd).strip()
except gclient_utils.Error: except (gclient_utils.Error, subprocess2.CalledProcessError):
upstream_branch = None upstream_branch = None
if upstream_branch: if upstream_branch:
try: try:
remote = GIT.Capture( remote = GIT.Capture(
['config', 'branch.%s.remote' % branch], cwd=cwd).strip() ['config', 'branch.%s.remote' % branch], cwd=cwd).strip()
except gclient_utils.Error: except (gclient_utils.Error, subprocess2.CalledProcessError):
pass pass
else: else:
try: try:
upstream_branch = GIT.Capture( upstream_branch = GIT.Capture(
['config', 'rietveld.upstream-branch'], cwd=cwd).strip() ['config', 'rietveld.upstream-branch'], cwd=cwd).strip()
except gclient_utils.Error: except (gclient_utils.Error, subprocess2.CalledProcessError):
upstream_branch = None upstream_branch = None
if upstream_branch: if upstream_branch:
try: try:
remote = GIT.Capture( remote = GIT.Capture(
['config', 'rietveld.upstream-remote'], cwd=cwd).strip() ['config', 'rietveld.upstream-remote'], cwd=cwd).strip()
except gclient_utils.Error: except (gclient_utils.Error, subprocess2.CalledProcessError):
pass pass
else: else:
# Fall back on trying a git-svn upstream branch. # Fall back on trying a git-svn upstream branch.
...@@ -459,7 +461,7 @@ class SVN(object): ...@@ -459,7 +461,7 @@ class SVN(object):
always=verbose, always=verbose,
filter_fn=CaptureMatchingLines, filter_fn=CaptureMatchingLines,
stdout=stdout) stdout=stdout)
except gclient_utils.Error: except (gclient_utils.Error, subprocess2.CalledProcessError):
def IsKnownFailure(): def IsKnownFailure():
for x in failure: for x in failure:
if (x.startswith('svn: OPTIONS of') or if (x.startswith('svn: OPTIONS of') or
...@@ -659,7 +661,7 @@ class SVN(object): ...@@ -659,7 +661,7 @@ class SVN(object):
""" """
try: try:
return SVN.Capture(['propget', property_name, filename]) return SVN.Capture(['propget', property_name, filename])
except gclient_utils.Error: except (gclient_utils.Error, subprocess2.CalledProcessError):
return '' return ''
@staticmethod @staticmethod
...@@ -840,7 +842,7 @@ class SVN(object): ...@@ -840,7 +842,7 @@ class SVN(object):
"""Retrieves the svn account which we assume is an email address.""" """Retrieves the svn account which we assume is an email address."""
try: try:
infos = SVN.CaptureInfo(repo_root) infos = SVN.CaptureInfo(repo_root)
except gclient_utils.Error: except (gclient_utils.Error, subprocess2.CalledProcessError):
return None return None
# Should check for uuid but it is incorrectly saved for https creds. # Should check for uuid but it is incorrectly saved for https creds.
...@@ -902,7 +904,7 @@ class SVN(object): ...@@ -902,7 +904,7 @@ class SVN(object):
info = SVN.CaptureInfo(directory) info = SVN.CaptureInfo(directory)
cur_dir_repo_root = info['Repository Root'] cur_dir_repo_root = info['Repository Root']
url = info['URL'] url = info['URL']
except gclient_utils.Error: except (gclient_utils.Error, subprocess2.CalledProcessError):
return None return None
while True: while True:
parent = os.path.dirname(directory) parent = os.path.dirname(directory)
...@@ -912,7 +914,7 @@ class SVN(object): ...@@ -912,7 +914,7 @@ class SVN(object):
info['URL'] != os.path.dirname(url)): info['URL'] != os.path.dirname(url)):
break break
url = info['URL'] url = info['URL']
except gclient_utils.Error: except (gclient_utils.Error, subprocess2.CalledProcessError):
break break
directory = parent directory = parent
return GetCasedPath(directory) return GetCasedPath(directory)
......
...@@ -94,8 +94,8 @@ class GclUnittest(GclTestsBase): ...@@ -94,8 +94,8 @@ class GclUnittest(GclTestsBase):
'gclient_utils', 'getpass', 'gclient_utils', 'getpass',
'json', 'main', 'need_change', 'need_change_and_args', 'no_args', 'json', 'main', 'need_change', 'need_change_and_args', 'no_args',
'optparse', 'os', 'presubmit_support', 'random', 're', 'optparse', 'os', 'presubmit_support', 'random', 're',
'string', 'subprocess', 'sys', 'tempfile', 'time', 'upload', 'string', 'subprocess', 'subprocess2', 'sys', 'tempfile', 'time',
'urllib2', 'upload', 'urllib2',
] ]
# If this test fails, you should add the relevant test. # If this test fails, you should add the relevant test.
self.compareMembers(gcl, members) self.compareMembers(gcl, members)
......
...@@ -44,7 +44,8 @@ class RootTestCase(BaseSCMTestCase): ...@@ -44,7 +44,8 @@ class RootTestCase(BaseSCMTestCase):
members = [ members = [
'GetCasedPath', 'GenFakeDiff', 'GIT', 'SVN', 'ValidateEmail', 'GetCasedPath', 'GenFakeDiff', 'GIT', 'SVN', 'ValidateEmail',
'cStringIO', 'determine_scm', 'gclient_utils', 'glob', 'logging', 'os', 'cStringIO', 'determine_scm', 'gclient_utils', 'glob', 'logging', 'os',
're', 'shutil', 'subprocess', 'sys', 'tempfile', 'time', 'xml', 're', 'shutil', 'subprocess', 'subprocess2', 'sys', 'tempfile', 'time',
'xml',
] ]
# If this test fails, you should add the relevant test. # If this test fails, you should add the relevant test.
self.compareMembers(scm, members) self.compareMembers(scm, members)
......
...@@ -48,7 +48,7 @@ class TryChangeUnittest(TryChangeTestsBase): ...@@ -48,7 +48,7 @@ class TryChangeUnittest(TryChangeTestsBase):
'breakpad', 'datetime', 'errno', 'fix_encoding', 'gcl', 'gclient_utils', 'breakpad', 'datetime', 'errno', 'fix_encoding', 'gcl', 'gclient_utils',
'getpass', 'getpass',
'json', 'logging', 'optparse', 'os', 'posixpath', 're', 'scm', 'shutil', 'json', 'logging', 'optparse', 'os', 'posixpath', 're', 'scm', 'shutil',
'sys', 'tempfile', 'urllib', 'subprocess2', 'sys', 'tempfile', 'urllib',
] ]
# If this test fails, you should add the relevant test. # If this test fails, you should add the relevant test.
self.compareMembers(trychange, members) self.compareMembers(trychange, members)
......
...@@ -37,6 +37,8 @@ import gcl ...@@ -37,6 +37,8 @@ import gcl
import fix_encoding import fix_encoding
import gclient_utils import gclient_utils
import scm import scm
import subprocess2
__version__ = '1.2' __version__ = '1.2'
...@@ -758,7 +760,7 @@ def TryChange(argv, ...@@ -758,7 +760,7 @@ def TryChange(argv,
return 1 return 1
print >> sys.stderr, e print >> sys.stderr, e
return 1 return 1
except gclient_utils.Error, e: except (gclient_utils.Error, subprocess2.CalledProcessError), e:
print >> sys.stderr, e print >> sys.stderr, e
return 1 return 1
return 0 return 0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment