def create(cls, **kw): """ keywords: source content_type body returns: tuple: (ArtifactInfo key, ArtifactContent key, ArtifactSource key) raises: DuplicateDataException - if artifact already exists """ if not kw: raise IllegalArgumentException("keywords must be provided") source_name = kw.pop("source", None) content_type = kw.get("content_type") if not source_name: raise IllegalArgumentException("source keyword must be provided.") elif not content_type: raise IllegalArgumentException("content_type keyword must be provided.") # I pop "body" since I can't include it as a keyword for ArtifactInfo.create() body = kw.pop("body", None) # hashes content to avoid saving a duplicate content_md5 = cls._content_md5(source_name, content_type, body) found_artifact_key = ArtifactInfo.find_by_content_md5(content_md5, keys_only=True).get() if found_artifact_key: raise DuplicateDataException("artifact %s" % (found_artifact_key.name())) return cls._create(source_name, body, content_md5, **kw)
def find_or_create(cls, **kw): """ returns: tuple: (ArtifactInfo key, ArtifactContent key, ArtifactSource key, created) """ if not kw: raise IllegalArgumentException("keywords must be provided") source_name = kw.pop("source", None) content_type = kw.get("content_type") if not source_name: raise IllegalArgumentException("source keyword must be provided.") elif not content_type: raise IllegalArgumentException( "content_type keyword must be provided.") # I pop "body" since I can't include it as a keyword for ArtifactInfo.create() body = kw.pop("body", None) # hashes content to avoid saving a duplicate content_md5 = cls._content_md5(source_name, content_type, body) found_artifact = ArtifactInfo.find_by_content_md5(content_md5).get() if found_artifact: info_key = found_artifact.key() content_key = ArtifactContent.get_by_guid( found_artifact.guid).key() source_key = found_artifact.source.key() created = False else: info_key, content_key, source_key = cls._create( source_name, body, content_md5, **kw) created = True return (info_key, content_key, source_key, created)
def find_or_create(cls, **kw): """ returns: tuple: (ArtifactInfo key, ArtifactContent key, ArtifactSource key, created) """ if not kw: raise IllegalArgumentException("keywords must be provided") source_name = kw.pop("source", None) content_type = kw.get("content_type") if not source_name: raise IllegalArgumentException("source keyword must be provided.") elif not content_type: raise IllegalArgumentException("content_type keyword must be provided.") # I pop "body" since I can't include it as a keyword for ArtifactInfo.create() body = kw.pop("body", None) # hashes content to avoid saving a duplicate content_md5 = cls._content_md5(source_name, content_type, body) found_artifact = ArtifactInfo.find_by_content_md5(content_md5).get() if found_artifact: info_key = found_artifact.key() content_key = ArtifactContent.get_by_guid(found_artifact.guid).key() source_key = found_artifact.source.key() created = False else: info_key, content_key, source_key = cls._create(source_name, body, content_md5, **kw) created = True return (info_key, content_key, source_key, created)
def create(cls, **kw): """ keywords: source content_type body returns: tuple: (ArtifactInfo key, ArtifactContent key, ArtifactSource key) raises: DuplicateDataException - if artifact already exists """ if not kw: raise IllegalArgumentException("keywords must be provided") source_name = kw.pop("source", None) content_type = kw.get("content_type") if not source_name: raise IllegalArgumentException("source keyword must be provided.") elif not content_type: raise IllegalArgumentException( "content_type keyword must be provided.") # I pop "body" since I can't include it as a keyword for ArtifactInfo.create() body = kw.pop("body", None) # hashes content to avoid saving a duplicate content_md5 = cls._content_md5(source_name, content_type, body) found_artifact_key = ArtifactInfo.find_by_content_md5( content_md5, keys_only=True).get() if found_artifact_key: raise DuplicateDataException("artifact %s" % (found_artifact_key.name())) return cls._create(source_name, body, content_md5, **kw)