Fix cleanup so we don't have to clobber as much when failures occur

Change-Id: I120c49a38d2a17a2216296a68378fee7345f616a

TBR=petkov

Review URL: http://codereview.chromium.org/3255004
This commit is contained in:
Chris Sosa 2010-08-30 22:37:28 -07:00
parent ae26a5cbbf
commit e13960240b
2 changed files with 18 additions and 10 deletions

View File

@ -216,6 +216,7 @@ def _FullCheckout(buildroot, rw_checkout=True, retries=_DEFAULT_RETRIES):
def _IncrementalCheckout(buildroot, rw_checkout=True,
retries=_DEFAULT_RETRIES):
"""Performs a checkout without clobbering previous checkout."""
_UprevCleanup(buildroot, error_ok=True)
RepoSync(buildroot, rw_checkout, retries)
@ -281,12 +282,12 @@ def _UprevPackages(buildroot, revisionfile, board):
_UprevAllPackages(buildroot)
def _UprevCleanup(buildroot):
def _UprevCleanup(buildroot, error_ok=False):
"""Clean up after a previous uprev attempt."""
cwd = os.path.join(buildroot, 'src', 'scripts')
RunCommand(['./cros_mark_as_stable', '--srcroot=..',
'--tracking_branch="cros/master"', 'clean'],
cwd=cwd)
cwd=cwd, error_ok=error_ok)
def _UprevPush(buildroot):

View File

@ -34,6 +34,7 @@ def RunCommand(cmd, print_cmd=True, error_ok=False, error_message=None,
stdout = None
stderr = None
stdin = None
output = ''
# Modify defaults based on parameters.
if redirect_stdout: stdout = subprocess.PIPE
@ -45,15 +46,21 @@ def RunCommand(cmd, print_cmd=True, error_ok=False, error_message=None,
if print_cmd:
Info('RunCommand: %s' % ' '.join(cmd))
proc = subprocess.Popen(cmd, cwd=cwd, stdin=stdin,
stdout=stdout, stderr=stderr)
(output, error) = proc.communicate(input)
if exit_code:
return proc.returncode
try:
proc = subprocess.Popen(cmd, cwd=cwd, stdin=stdin,
stdout=stdout, stderr=stderr)
(output, error) = proc.communicate(input)
if exit_code:
return proc.returncode
if not error_ok and proc.returncode:
raise Exception('Command "%s" failed.\n' % (' '.join(cmd)) +
(error_message or error or output or ''))
if not error_ok and proc.returncode:
raise Exception('Command "%s" failed.\n' % (' '.join(cmd)) +
(error_message or error or output or ''))
except Exception,e:
if not error_ok:
raise
else:
Warning(str(e))
return output