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
import fix_encoding
import gclient_utils
import presubmit_support
import subprocess2
__version__ = '1.2'
......@@ -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.
try:
cached_file = os.path.join(GetCacheDir(), filename)
except gclient_utils.Error:
except (gclient_utils.Error, subprocess2.CalledProcessError):
return None
if (not os.path.exists(cached_file) or
(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):
# Exit the loop if the file was found. Override content.
content = '\n'.join(content_array)
break
except gclient_utils.Error:
except (gclient_utils.Error, subprocess2.CalledProcessError):
if content_array[0].startswith(
'svn: Can\'t get username or password'):
ErrorExit('Your svn credentials expired. Please run svn update '
......@@ -1425,7 +1426,7 @@ def main(argv):
try:
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.'
return 1
......@@ -1443,7 +1444,7 @@ def main(argv):
return command(argv[1:])
# Unknown command, try to pass that to svn
return CMDpassthru(argv)
except gclient_utils.Error, e:
except (gclient_utils.Error, subprocess2.CalledProcessError), e:
print >> sys.stderr, 'Got an exception'
print >> sys.stderr, str(e)
return 1
......
......@@ -68,6 +68,7 @@ import fix_encoding
import gclient_scm
import gclient_utils
from third_party.repo.progress import Progress
import subprocess2
def attr(attribute, data):
......@@ -453,7 +454,7 @@ class Dependency(GClientKeywords, gclient_utils.WorkItem):
try:
gclient_utils.CheckCallAndFilterAndHeader(
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
# failed. Users of this script may wish to treat hook action failures
# differently from VC failures.
......@@ -1261,7 +1262,7 @@ def Main(argv):
# Not a known command. Default to help.
GenUsage(parser, 'help')
return CMDhelp(parser, argv)
except gclient_utils.Error, e:
except (gclient_utils.Error, subprocess2.CalledProcessError), e:
print >> sys.stderr, 'Error: %s' % str(e)
return 1
......
......@@ -11,8 +11,9 @@ import re
import sys
import time
import scm
import gclient_utils
import scm
import subprocess2
class DiffFilterer(object):
......@@ -495,7 +496,7 @@ class GitWrapper(SCMWrapper):
try:
self._Run(clone_cmd, options, cwd=self._root_dir)
break
except gclient_utils.Error, e:
except (gclient_utils.Error, subprocess2.CalledProcessError), e:
# TODO(maruel): Hackish, should be fixed by moving _Run() to
# CheckCall().
# Too bad we don't have access to the actual output.
......@@ -750,7 +751,7 @@ class SVNWrapper(SCMWrapper):
# Get the existing scm url and the revision number of the current checkout.
try:
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(
('Can\'t update/checkout %s if an unversioned directory is present. '
'Delete the directory and try again.') % self.checkout_path)
......@@ -772,7 +773,7 @@ class SVNWrapper(SCMWrapper):
# The repository url changed, need to switch.
try:
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
# out right now.
raise gclient_utils.Error('This url is unreachable: %s' % url)
......@@ -889,7 +890,7 @@ class SVNWrapper(SCMWrapper):
"""Display revision"""
try:
return scm.SVN.CaptureRevision(self.checkout_path)
except gclient_utils.Error:
except (gclient_utils.Error, subprocess2.CalledProcessError):
return None
def runhooks(self, options, args, file_list):
......
......@@ -17,6 +17,8 @@ import time
import xml.dom.minidom
import gclient_utils
import subprocess2
def ValidateEmail(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):
try:
upstream_branch = GIT.Capture(
['config', 'branch.%s.merge' % branch], cwd=cwd).strip()
except gclient_utils.Error:
except (gclient_utils.Error, subprocess2.CalledProcessError):
upstream_branch = None
if upstream_branch:
try:
remote = GIT.Capture(
['config', 'branch.%s.remote' % branch], cwd=cwd).strip()
except gclient_utils.Error:
except (gclient_utils.Error, subprocess2.CalledProcessError):
pass
else:
try:
upstream_branch = GIT.Capture(
['config', 'rietveld.upstream-branch'], cwd=cwd).strip()
except gclient_utils.Error:
except (gclient_utils.Error, subprocess2.CalledProcessError):
upstream_branch = None
if upstream_branch:
try:
remote = GIT.Capture(
['config', 'rietveld.upstream-remote'], cwd=cwd).strip()
except gclient_utils.Error:
except (gclient_utils.Error, subprocess2.CalledProcessError):
pass
else:
# Fall back on trying a git-svn upstream branch.
......@@ -459,7 +461,7 @@ class SVN(object):
always=verbose,
filter_fn=CaptureMatchingLines,
stdout=stdout)
except gclient_utils.Error:
except (gclient_utils.Error, subprocess2.CalledProcessError):
def IsKnownFailure():
for x in failure:
if (x.startswith('svn: OPTIONS of') or
......@@ -659,7 +661,7 @@ class SVN(object):
"""
try:
return SVN.Capture(['propget', property_name, filename])
except gclient_utils.Error:
except (gclient_utils.Error, subprocess2.CalledProcessError):
return ''
@staticmethod
......@@ -840,7 +842,7 @@ class SVN(object):
"""Retrieves the svn account which we assume is an email address."""
try:
infos = SVN.CaptureInfo(repo_root)
except gclient_utils.Error:
except (gclient_utils.Error, subprocess2.CalledProcessError):
return None
# Should check for uuid but it is incorrectly saved for https creds.
......@@ -902,7 +904,7 @@ class SVN(object):
info = SVN.CaptureInfo(directory)
cur_dir_repo_root = info['Repository Root']
url = info['URL']
except gclient_utils.Error:
except (gclient_utils.Error, subprocess2.CalledProcessError):
return None
while True:
parent = os.path.dirname(directory)
......@@ -912,7 +914,7 @@ class SVN(object):
info['URL'] != os.path.dirname(url)):
break
url = info['URL']
except gclient_utils.Error:
except (gclient_utils.Error, subprocess2.CalledProcessError):
break
directory = parent
return GetCasedPath(directory)
......
......@@ -94,8 +94,8 @@ class GclUnittest(GclTestsBase):
'gclient_utils', 'getpass',
'json', 'main', 'need_change', 'need_change_and_args', 'no_args',
'optparse', 'os', 'presubmit_support', 'random', 're',
'string', 'subprocess', 'sys', 'tempfile', 'time', 'upload',
'urllib2',
'string', 'subprocess', 'subprocess2', 'sys', 'tempfile', 'time',
'upload', 'urllib2',
]
# If this test fails, you should add the relevant test.
self.compareMembers(gcl, members)
......
......@@ -44,7 +44,8 @@ class RootTestCase(BaseSCMTestCase):
members = [
'GetCasedPath', 'GenFakeDiff', 'GIT', 'SVN', 'ValidateEmail',
'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.
self.compareMembers(scm, members)
......
......@@ -48,7 +48,7 @@ class TryChangeUnittest(TryChangeTestsBase):
'breakpad', 'datetime', 'errno', 'fix_encoding', 'gcl', 'gclient_utils',
'getpass',
'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.
self.compareMembers(trychange, members)
......
......@@ -37,6 +37,8 @@ import gcl
import fix_encoding
import gclient_utils
import scm
import subprocess2
__version__ = '1.2'
......@@ -758,7 +760,7 @@ def TryChange(argv,
return 1
print >> sys.stderr, e
return 1
except gclient_utils.Error, e:
except (gclient_utils.Error, subprocess2.CalledProcessError), e:
print >> sys.stderr, e
return 1
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