def create_job_for_recipes(recipes, owner=None, whiteboard=None, cc=None,product=None, retention_tag=None, group=None, submitter=None, priority=None, **kwargs): if retention_tag is None: retention_tag = RetentionTag.by_tag(u'scratch') # Don't use default, unpredictable else: retention_tag = RetentionTag.by_tag(retention_tag) if owner is None: owner = create_user() if whiteboard is None: whiteboard = unique_name(u'job %s') job = Job(whiteboard=whiteboard, ttasks=sum(r.ttasks for r in recipes), owner=owner, retention_tag=retention_tag, group=group, product=product, submitter=submitter) if cc is not None: job.cc = cc if priority is None: priority = TaskPriority.default_priority() recipe_set = RecipeSet(ttasks=sum(r.ttasks for r in recipes), priority=priority) recipe_set.recipes.extend(recipes) job.recipesets.append(recipe_set) session.add(job) session.flush() log.debug('Created %s', job.t_id) return job
def create_job_for_recipesets(recipesets, owner=None, whiteboard=None, cc=None, product=None, retention_tag=None, group=None, submitter=None, **kwargs): if retention_tag is None: retention_tag = RetentionTag.by_tag( u'scratch') # Don't use default, unpredictable else: retention_tag = RetentionTag.by_tag(retention_tag) if owner is None: owner = create_user() if whiteboard is None: whiteboard = unique_name(u'job %s') job = Job(whiteboard=whiteboard, ttasks=sum(rs.ttasks for rs in recipesets), owner=owner, retention_tag=retention_tag, group=group, product=product, submitter=submitter) if cc is not None: job.cc = cc job.recipesets.extend(recipesets) session.add(job) session.flush() log.debug('Created %s', job.t_id) return job
def _process_job_tag_product(self, retention_tag=None, product=None, *args, **kw): """ Process job retention_tag and product """ retention_tag = retention_tag or RetentionTag.get_default().tag try: tag = RetentionTag.by_tag(retention_tag.lower()) except InvalidRequestError: raise BX(_("Invalid retention_tag attribute passed. Needs to be one of %s. You gave: %s" % (','.join([x.tag for x in RetentionTag.get_all()]), retention_tag))) if product is None and tag.requires_product(): raise BX(_("You've selected a tag which needs a product associated with it, \ alternatively you could use one of the following tags %s" % ','.join([x.tag for x in RetentionTag.get_all() if not x.requires_product()]))) elif product is not None and not tag.requires_product(): raise BX(_("Cannot specify a product with tag %s, please use %s as a tag " % (retention_tag,','.join([x.tag for x in RetentionTag.get_all() if x.requires_product()])))) else: pass if tag.requires_product(): try: product = Product.by_name(product) return (tag, product) except ValueError: raise BX(_("You entered an invalid product name: %s" % product)) else: return tag, None
def _process_job_tag_product(self, retention_tag=None, product=None, *args, **kw): """ Process job retention_tag and product """ retention_tag = retention_tag or RetentionTag.get_default().tag try: tag = RetentionTag.by_tag(retention_tag.lower()) except InvalidRequestError: raise BX( _("Invalid retention_tag attribute passed. Needs to be one of %s. You gave: %s" % (','.join([x.tag for x in RetentionTag.get_all() ]), retention_tag))) if product is None and tag.requires_product(): raise BX( _("You've selected a tag which needs a product associated with it, \ alternatively you could use one of the following tags %s" % ','.join([ x.tag for x in RetentionTag.get_all() if not x.requires_product() ]))) elif product is not None and not tag.requires_product(): raise BX( _("Cannot specify a product with tag %s, please use %s as a tag " % (retention_tag, ','.join([ x.tag for x in RetentionTag.get_all() if x.requires_product() ])))) else: pass if tag.requires_product(): try: product = Product.by_name(product) return (tag, product) except ValueError: raise BX(_("You entered an invalid product name: %s" % product)) else: return tag, None