Revision 8d99a8bf

b/lib/cli.py
2950 2950
    self.feedback_fn = feedback_fn
2951 2951
    self._counter = itertools.count()
2952 2952

  
2953
  @staticmethod
2954
  def _IfName(name, fmt):
2955
    """Helper function for formatting name.
2956

  
2957
    """
2958
    if name:
2959
      return fmt % name
2960

  
2961
    return ""
2962

  
2953 2963
  def QueueJob(self, name, *ops):
2954 2964
    """Record a job for later submit.
2955 2965

  
2956 2966
    @type name: string
2957 2967
    @param name: a description of the job, will be used in WaitJobSet
2968

  
2958 2969
    """
2959 2970
    SetGenericOpcodeOpts(ops, self.opts)
2960 2971
    self.queue.append((self._counter.next(), name, ops))
2961 2972

  
2973
  def AddJobId(self, name, status, job_id):
2974
    """Adds a job ID to the internal queue.
2975

  
2976
    """
2977
    self.jobs.append((self._counter.next(), status, job_id, name))
2978

  
2962 2979
  def SubmitPending(self, each=False):
2963 2980
    """Submit all pending jobs.
2964 2981

  
......
3017 3034
    # first, remove any non-submitted jobs
3018 3035
    self.jobs, failures = compat.partition(self.jobs, lambda x: x[1])
3019 3036
    for idx, _, jid, name in failures:
3020
      ToStderr("Failed to submit job for %s: %s", name, jid)
3037
      ToStderr("Failed to submit job%s: %s", self._IfName(name, " for %s"), jid)
3021 3038
      results.append((idx, False, jid))
3022 3039

  
3023 3040
    while self.jobs:
3024 3041
      (idx, _, jid, name) = self._ChooseJob()
3025
      ToStdout("Waiting for job %s for %s...", jid, name)
3042
      ToStdout("Waiting for job %s%s ...", jid, self._IfName(name, " for %s"))
3026 3043
      try:
3027 3044
        job_result = PollJob(jid, cl=self.cl, feedback_fn=self.feedback_fn)
3028 3045
        success = True
3029 3046
      except errors.JobLost, err:
3030 3047
        _, job_result = FormatError(err)
3031
        ToStderr("Job %s for %s has been archived, cannot check its result",
3032
                 jid, name)
3048
        ToStderr("Job %s%s has been archived, cannot check its result",
3049
                 jid, self._IfName(name, " for %s"))
3033 3050
        success = False
3034 3051
      except (errors.GenericError, luxi.ProtocolError), err:
3035 3052
        _, job_result = FormatError(err)
3036 3053
        success = False
3037 3054
        # the error message will always be shown, verbose or not
3038
        ToStderr("Job %s for %s has failed: %s", jid, name, job_result)
3055
        ToStderr("Job %s%s has failed: %s",
3056
                 jid, self._IfName(name, " for %s"), job_result)
3039 3057

  
3040 3058
      results.append((idx, success, job_result))
3041 3059

  

Also available in: Unified diff