Revision b247c6fc lib/opcodes.py

b/lib/opcodes.py
393 393
                                     errors.ECODE_INVAL)
394 394

  
395 395

  
396
def _BuildJobDepCheck(relative):
397
  """Builds check for job dependencies (L{DEPEND_ATTR}).
398

  
399
  @type relative: bool
400
  @param relative: Whether to accept relative job IDs (negative)
401
  @rtype: callable
402

  
403
  """
404
  if relative:
405
    job_id = ht.TOr(ht.TJobId, ht.TRelativeJobId)
406
  else:
407
    job_id = ht.TJobId
408

  
409
  job_dep = \
410
    ht.TAnd(ht.TIsLength(2),
411
            ht.TItems([job_id,
412
                       ht.TListOf(ht.TElemOf(constants.JOBS_FINALIZED))]))
413

  
414
  return ht.TOr(ht.TNone, ht.TListOf(job_dep))
415

  
416

  
417
TNoRelativeJobDependencies = _BuildJobDepCheck(False)
418

  
419

  
396 420
class OpCode(BaseOpCode):
397 421
  """Abstract OpCode.
398 422

  
......
416 440
  # pylint: disable-msg=E1101
417 441
  # as OP_ID is dynamically defined
418 442
  WITH_LU = True
419
  _T_JOB_DEP = \
420
    ht.TAnd(ht.TIsLength(2),
421
            ht.TItems([ht.TJobId,
422
                       ht.TListOf(ht.TElemOf(constants.JOBS_FINALIZED))]))
423 443
  OP_PARAMS = [
424 444
    ("dry_run", None, ht.TMaybeBool, "Run checks only, don't execute"),
425 445
    ("debug_level", None, ht.TOr(ht.TNone, ht.TPositiveInt), "Debug level"),
426 446
    ("priority", constants.OP_PRIO_DEFAULT,
427 447
     ht.TElemOf(constants.OP_PRIO_SUBMIT_VALID), "Opcode priority"),
428
    (DEPEND_ATTR, None, ht.TOr(ht.TNone, ht.TListOf(_T_JOB_DEP)),
429
     "Job dependencies"),
448
    (DEPEND_ATTR, None, _BuildJobDepCheck(True),
449
     "Job dependencies; if used through ``SubmitManyJobs`` relative (negative)"
450
     " job IDs can be used"),
430 451
    ]
431 452

  
432 453
  def __getstate__(self):

Also available in: Unified diff