From 7421df8e5f2cf31022085b332d1300640ba5854b Mon Sep 17 00:00:00 2001 From: Michael Hanselmann <hansmi@google.com> Date: Tue, 26 Jul 2011 11:31:04 +0200 Subject: [PATCH] cli.JobExecutor: Feedback function for info output This will be used in the watcher where we don't want to pollute stdout unless in debug mode. Signed-off-by: Michael Hanselmann <hansmi@google.com> Reviewed-by: Iustin Pop <iustin@google.com> --- lib/cli.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/cli.py b/lib/cli.py index dcc13ad15..06c460fff 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -3016,6 +3016,10 @@ class JobExecutor(object): self.jobs = [] self.opts = opts self.feedback_fn = feedback_fn + if feedback_fn: + self._info_fn = feedback_fn + else: + self._info_fn = ToStdout self._counter = itertools.count() @staticmethod @@ -3097,31 +3101,33 @@ class JobExecutor(object): if self.verbose: ok_jobs = [row[2] for row in self.jobs if row[1]] if ok_jobs: - ToStdout("Submitted jobs %s", utils.CommaJoin(ok_jobs)) + self._info_fn("Submitted jobs %s", utils.CommaJoin(ok_jobs)) # first, remove any non-submitted jobs self.jobs, failures = compat.partition(self.jobs, lambda x: x[1]) for idx, _, jid, name in failures: - ToStderr("Failed to submit job%s: %s", self._IfName(name, " for %s"), jid) + self._info_fn("Failed to submit job%s: %s", + self._IfName(name, " for %s"), jid) results.append((idx, False, jid)) while self.jobs: (idx, _, jid, name) = self._ChooseJob() - ToStdout("Waiting for job %s%s ...", jid, self._IfName(name, " for %s")) + self._info_fn("Waiting for job %s%s ...", + jid, self._IfName(name, " for %s")) try: job_result = PollJob(jid, cl=self.cl, feedback_fn=self.feedback_fn) success = True except errors.JobLost, err: _, job_result = FormatError(err) - ToStderr("Job %s%s has been archived, cannot check its result", - jid, self._IfName(name, " for %s")) + self._info_fn("Job %s%s has been archived, cannot check its result", + jid, self._IfName(name, " for %s")) success = False except (errors.GenericError, luxi.ProtocolError), err: _, job_result = FormatError(err) success = False # the error message will always be shown, verbose or not - ToStderr("Job %s%s has failed: %s", - jid, self._IfName(name, " for %s"), job_result) + self._info_fn("Job %s%s has failed: %s", + jid, self._IfName(name, " for %s"), job_result) results.append((idx, success, job_result)) @@ -3145,9 +3151,9 @@ class JobExecutor(object): self.SubmitPending() for _, status, result, name in self.jobs: if status: - ToStdout("%s: %s", result, name) + self._info_fn("%s: %s", result, name) else: - ToStderr("Failure for %s: %s", name, result) + self._info_fn("Failure for %s: %s", name, result) return [row[1:3] for row in self.jobs] -- GitLab