data.oci_model: fix imports

This commit is contained in:
Jimmy Zelinskie 2017-03-23 00:21:21 -04:00
parent 069208f2f1
commit e872c310d0
5 changed files with 45 additions and 32 deletions

View file

@ -0,0 +1,9 @@
from data.oci_model import (
blob,
channel,
manifest,
manifest_list,
package,
release,
tag,
)

View file

@ -1,5 +1,5 @@
from data.oci_model import tag as tag_model
from data.database import Tag, Channel
from data.oci_model import tag as tag_model
def get_channel_releases(repo, channel):

View file

@ -4,8 +4,8 @@ import json
from cnr.models.package_base import get_media_type
from data import oci_model
from data.database import db_transaction, Manifest, ManifestListManifest, MediaType, Blob, Tag
from data.oci_model import tag as tag_model
logger = logging.getLogger(__name__)
@ -38,14 +38,14 @@ def get_or_create_manifest(manifest_json, media_type_name):
def get_manifest_types(repo, release=None):
""" Returns an array of MediaTypes.name for a repo, can filter by tag """
query = oci_model.tag.tag_alive_oci(Tag
.select(MediaType.name)
.join(ManifestListManifest,
on=(ManifestListManifest.manifest_list == Tag.manifest_list))
.join(MediaType,
on=(ManifestListManifest.media_type == MediaType.id))
.where(Tag.repository == repo,
Tag.tag_kind == Tag.tag_kind.get_id('release')))
query = tag_model.tag_alive_oci(Tag
.select(MediaType.name)
.join(ManifestListManifest,
on=(ManifestListManifest.manifest_list == Tag.manifest_list))
.join(MediaType,
on=(ManifestListManifest.media_type == MediaType.id))
.where(Tag.repository == repo,
Tag.tag_kind == Tag.tag_kind.get_id('release')))
if release:
query = query.where(Tag.name == release)

View file

@ -1,8 +1,10 @@
from cnr.models.package_base import get_media_type, manifest_media_type
from peewee import prefetch
from data import model, oci_model
from data import model
from data.database import Repository, Namespace, Tag, ManifestListManifest
from data.oci_model import tag as tag_model
def list_packages_query(namespace=None, media_type=None, search_query=None, username=None):
@ -32,9 +34,9 @@ def list_packages_query(namespace=None, media_type=None, search_query=None, user
.order_by(Tag.lifetime_start))
if media_type:
tag_query = oci_model.tag.filter_tags_by_media_type(tag_query, media_type)
tag_query = tag_model.filter_tags_by_media_type(tag_query, media_type)
tag_query = oci_model.tag.tag_alive_oci(tag_query)
tag_query = tag_model.tag_alive_oci(tag_query)
query = prefetch(repo_query, tag_query)
return query

View file

@ -3,9 +3,11 @@ import bisect
from cnr.exception import PackageAlreadyExists
from cnr.models.package_base import manifest_media_type
from data import oci_model
from data.database import (db_transaction, get_epoch_timestamp, Manifest, ManifestList, Tag,
ManifestListManifest, Blob, ManifestBlob)
from data.oci_model import (blob as blob_model, manifest as manifest_model,
manifest_list as manifest_list_model,
tag as tag_model)
LIST_MEDIA_TYPE = 'application/vnd.cnr.manifest.list.v0.json'
@ -14,7 +16,7 @@ SCHEMA_VERSION = 'v0'
def get_app_release(repo, tag_name, media_type):
""" Returns (tag, manifest, blob) given a repo object, tag_name, and media_type). """
tag = oci_model.tag.get_tag(repo, tag_name, tag_kind='release')
tag = tag_model.get_tag(repo, tag_name, tag_kind='release')
media_type_id = ManifestListManifest.media_type.get_id(manifest_media_type(media_type))
manifestlistmanifest = (tag.manifest_list.manifestlistmanifest_set
.join(Manifest)
@ -33,16 +35,16 @@ def create_app_release(repo, tag_name, manifest, digest):
"""
with db_transaction():
# Create/get the package manifest
manifest = oci_model.manifest.get_or_create_manifest(manifest, manifest['mediaType'])
manifest = manifest_model.get_or_create_manifest(manifest, manifest['mediaType'])
# get the tag
tag = oci_model.tag.get_or_initialize_tag(repo, tag_name)
tag = tag_model.get_or_initialize_tag(repo, tag_name)
if tag.manifest_list is None:
tag.manifest_list = ManifestList(media_type=ManifestList.media_type.get_id(LIST_MEDIA_TYPE),
schema_version=SCHEMA_VERSION,
manifest_list_json=[])
elif oci_model.tag.tag_media_type_exists(tag, manifest.media_type):
elif tag_model.tag_media_type_exists(tag, manifest.media_type):
raise PackageAlreadyExists("package exists already")
list_json = tag.manifest_list.manifest_list_json
@ -53,12 +55,12 @@ def create_app_release(repo, tag_name, manifest, digest):
insert_point = bisect.bisect_left(list_manifest_ids, manifest.id)
list_json.insert(insert_point, manifest.manifest_json)
list_manifest_ids.insert(insert_point, manifest.id)
manifestlist = oci_model.manifest_list.get_or_create_manifest_list(list_json, LIST_MEDIA_TYPE,
manifestlist = manifest_list_model.get_or_create_manifest_list(list_json, LIST_MEDIA_TYPE,
SCHEMA_VERSION)
oci_model.manifest_list.create_manifestlistmanifest(manifestlist, list_manifest_ids, list_json)
manifest_list_model.create_manifestlistmanifest(manifestlist, list_manifest_ids, list_json)
tag = oci_model.tag.create_or_update_tag(repo, tag_name, manifest_list=manifestlist,
tag_kind="release")
tag = tag_model.create_or_update_tag(repo, tag_name, manifest_list=manifestlist,
tag_kind="release")
blob_digest = digest
try:
@ -67,7 +69,7 @@ def create_app_release(repo, tag_name, manifest, digest):
.join(Blob)
.where(ManifestBlob.manifest == manifest, Blob.digest == blob_digest).get())
except ManifestBlob.DoesNotExist:
blob = oci_model.blob.get_blob(blob_digest)
blob = blob_model.get_blob(blob_digest)
ManifestBlob.create(manifest=manifest, blob=blob)
return tag
@ -77,7 +79,7 @@ def delete_app_release(repo, tag_name, media_type):
media_type_id = ManifestListManifest.media_type.get_id(manifest_media_type(media_type))
with db_transaction():
tag = oci_model.tag.get_tag(repo, tag_name)
tag = tag_model.get_tag(repo, tag_name)
manifest_list = tag.manifest_list
list_json = manifest_list.manifest_list_json
mlm_query = (ManifestListManifest
@ -96,12 +98,12 @@ def delete_app_release(repo, tag_name, media_type):
tag.lifetime_end = get_epoch_timestamp()
tag.save()
else:
manifestlist = oci_model.manifest_list.get_or_create_manifest_list(list_json, LIST_MEDIA_TYPE,
SCHEMA_VERSION)
oci_model.manifest_list.create_manifestlistmanifest(manifestlist, list_manifest_ids,
list_json)
tag = oci_model.tag.create_or_update_tag(repo, tag_name, manifest_list=manifestlist,
tag_kind="release")
manifestlist = manifest_list_model.get_or_create_manifest_list(list_json, LIST_MEDIA_TYPE,
SCHEMA_VERSION)
manifest_list_model.create_manifestlistmanifest(manifestlist, list_manifest_ids,
list_json)
tag = tag_model.create_or_update_tag(repo, tag_name, manifest_list=manifestlist,
tag_kind="release")
return tag
@ -112,5 +114,5 @@ def get_releases(repo, media_type=None):
.where(Tag.repository == repo,
Tag.tag_kind == Tag.tag_kind.get_id("release")))
if media_type:
release_query = oci_model.tag.filter_tags_by_media_type(release_query, media_type)
return [t.name for t in oci_model.tag.tag_alive_oci(release_query)]
release_query = tag_model.filter_tags_by_media_type(release_query, media_type)
return [t.name for t in tag_model.tag_alive_oci(release_query)]