Commit dc191505 authored by Simon Glass's avatar Simon Glass
Browse files

patman: Allow commands to raise on error, or not



Make raise_on_error a parameter so that we can control which commands
raise and which do not. If we get an error reading the alias file, just
continue.
Signed-off-by: default avatarSimon Glass <sjg@chromium.org>
parent a10fd93c
...@@ -42,7 +42,7 @@ class CommandResult: ...@@ -42,7 +42,7 @@ class CommandResult:
def RunPipe(pipe_list, infile=None, outfile=None, def RunPipe(pipe_list, infile=None, outfile=None,
capture=False, capture_stderr=False, oneline=False, capture=False, capture_stderr=False, oneline=False,
cwd=None, **kwargs): raise_on_error=True, cwd=None, **kwargs):
""" """
Perform a command pipeline, with optional input/output filenames. Perform a command pipeline, with optional input/output filenames.
...@@ -63,6 +63,7 @@ def RunPipe(pipe_list, infile=None, outfile=None, ...@@ -63,6 +63,7 @@ def RunPipe(pipe_list, infile=None, outfile=None,
result = CommandResult() result = CommandResult()
last_pipe = None last_pipe = None
pipeline = list(pipe_list) pipeline = list(pipe_list)
user_pipestr = '|'.join([' '.join(pipe) for pipe in pipe_list])
while pipeline: while pipeline:
cmd = pipeline.pop(0) cmd = pipeline.pop(0)
if last_pipe is not None: if last_pipe is not None:
...@@ -80,8 +81,10 @@ def RunPipe(pipe_list, infile=None, outfile=None, ...@@ -80,8 +81,10 @@ def RunPipe(pipe_list, infile=None, outfile=None,
last_pipe = cros_subprocess.Popen(cmd, cwd=cwd, **kwargs) last_pipe = cros_subprocess.Popen(cmd, cwd=cwd, **kwargs)
except Exception, err: except Exception, err:
result.exception = err result.exception = err
print 'exception', pipe_list, err if raise_on_error:
raise Exception("Error running '%s': %s" % (pipe_list, str)) raise Exception("Error running '%s': %s" % (user_pipestr, str))
result.return_code = 255
return result
if capture: if capture:
result.stdout, result.stderr, result.combined = ( result.stdout, result.stderr, result.combined = (
...@@ -91,15 +94,17 @@ def RunPipe(pipe_list, infile=None, outfile=None, ...@@ -91,15 +94,17 @@ def RunPipe(pipe_list, infile=None, outfile=None,
result.return_code = last_pipe.wait() result.return_code = last_pipe.wait()
else: else:
result.return_code = os.waitpid(last_pipe.pid, 0)[1] result.return_code = os.waitpid(last_pipe.pid, 0)[1]
if result.return_code: if raise_on_error and result.return_code:
raise Exception("Error running '%s'" % pipe_list) raise Exception("Error running '%s'" % user_pipestr)
return result return result
def Output(*cmd): def Output(*cmd):
return RunPipe([cmd], capture=True).stdout return RunPipe([cmd], capture=True, raise_on_error=False).stdout
def OutputOneLine(*cmd, **kwargs): def OutputOneLine(*cmd, **kwargs):
raise_on_error = kwargs.pop('raise_on_error', True)
return (RunPipe([cmd], capture=True, oneline=True, return (RunPipe([cmd], capture=True, oneline=True,
raise_on_error=raise_on_error,
**kwargs).stdout.strip()) **kwargs).stdout.strip())
def Run(*cmd, **kwargs): def Run(*cmd, **kwargs):
......
...@@ -359,7 +359,8 @@ def GetAliasFile(): ...@@ -359,7 +359,8 @@ def GetAliasFile():
Returns: Returns:
Filename of git alias file, or None if none Filename of git alias file, or None if none
""" """
fname = command.OutputOneLine('git', 'config', 'sendemail.aliasesfile') fname = command.OutputOneLine('git', 'config', 'sendemail.aliasesfile',
raise_on_error=False)
if fname: if fname:
fname = os.path.join(GetTopLevel(), fname.strip()) fname = os.path.join(GetTopLevel(), fname.strip())
return fname return fname
......
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