Commit 34f68552 authored by maruel@chromium.org's avatar maruel@chromium.org

Improve error message in patch application failure.

Make exception PatchApplicationFailed() self printable.

R=cmp@chromium.org
BUG=
TEST=


Review URL: https://chromiumcodereview.appspot.com/10391033

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@136091 0039d316-1c4b-4281-b951-d872f2087c98
parent 8f2d2c5a
#!/usr/bin/env python
# Copyright (c) 2011 The Chromium Authors. All rights reserved.
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
......@@ -69,7 +69,11 @@ def main():
parser.error('Couldn\'t determine the scm')
# Apply the patch.
scm_obj.apply_patch(patchset)
try:
scm_obj.apply_patch(patchset)
except checkout.PatchApplicationFailed, e:
print >> sys.stderr, str(e)
return 1
return 0
......
......@@ -49,11 +49,24 @@ def get_code_review_setting(path, key,
class PatchApplicationFailed(Exception):
"""Patch failed to be applied."""
def __init__(self, filename, status):
super(PatchApplicationFailed, self).__init__(filename, status)
self.filename = filename
def __init__(self, p, status):
super(PatchApplicationFailed, self).__init__(p, status)
self.patch = p
self.status = status
@property
def filename(self):
if self.patch:
return self.patch.filename
def __str__(self):
out = []
if self.filename:
out.append('Failed to apply patch for %s:' % self.filename)
if self.status:
out.append(self.status)
return '\n'.join(out)
class CheckoutBase(object):
# Set to None to have verbose output.
......@@ -140,12 +153,12 @@ class RawCheckout(CheckoutBase):
if p.source_filename:
if not p.is_new:
raise PatchApplicationFailed(
p.filename,
p,
'File has a source filename specified but is not new')
# Copy the file first.
if os.path.isfile(filepath):
raise PatchApplicationFailed(
p.filename, 'File exist but was about to be overwriten')
p, 'File exist but was about to be overwriten')
shutil.copy2(
os.path.join(self.project_path, p.source_filename), filepath)
if p.diff_hunks:
......@@ -160,10 +173,10 @@ class RawCheckout(CheckoutBase):
for post in post_processors:
post(self, p)
except OSError, e:
raise PatchApplicationFailed(p.filename, '%s%s' % (stdout, e))
raise PatchApplicationFailed(p, '%s%s' % (stdout, e))
except subprocess.CalledProcessError, e:
raise PatchApplicationFailed(
p.filename, '%s%s' % (stdout, getattr(e, 'stdout', None)))
p, '%s%s' % (stdout, getattr(e, 'stdout', None)))
def commit(self, commit_message, user):
"""Stubbed out."""
......@@ -307,12 +320,12 @@ class SvnCheckout(CheckoutBase, SvnMixIn):
if p.source_filename:
if not p.is_new:
raise PatchApplicationFailed(
p.filename,
p,
'File has a source filename specified but is not new')
# Copy the file first.
if os.path.isfile(filepath):
raise PatchApplicationFailed(
p.filename, 'File exist but was about to be overwriten')
p, 'File exist but was about to be overwriten')
self._check_output_svn(
[
'copy',
......@@ -347,10 +360,10 @@ class SvnCheckout(CheckoutBase, SvnMixIn):
for post in post_processors:
post(self, p)
except OSError, e:
raise PatchApplicationFailed(p.filename, '%s%s' % (stdout, e))
raise PatchApplicationFailed(p, '%s%s' % (stdout, e))
except subprocess.CalledProcessError, e:
raise PatchApplicationFailed(
p.filename,
p,
'While running %s;\n%s%s' % (
' '.join(e.cmd), stdout, getattr(e, 'stdout', '')))
......@@ -503,10 +516,10 @@ class GitCheckoutBase(CheckoutBase):
for post in post_processors:
post(self, p)
except OSError, e:
raise PatchApplicationFailed(p.filename, '%s%s' % (stdout, e))
raise PatchApplicationFailed(p, '%s%s' % (stdout, e))
except subprocess.CalledProcessError, e:
raise PatchApplicationFailed(
p.filename, '%s%s' % (stdout, getattr(e, 'stdout', None)))
p, '%s%s' % (stdout, getattr(e, 'stdout', None)))
# Once all the patches are processed and added to the index, commit the
# index.
self._check_call_git(['commit', '-m', 'Committed patch'])
......
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