This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/data/appr_model/channel.py

65 lines
2.1 KiB
Python
Raw Normal View History

2018-05-23 21:08:00 +00:00
from data.appr_model import tag as tag_model
2017-03-23 01:51:28 +00:00
def get_channel_releases(repo, channel, models_ref):
2017-03-23 01:51:28 +00:00
""" Return all previously linked tags.
This works based upon Tag lifetimes.
"""
Channel = models_ref.Channel
Tag = models_ref.Tag
2017-03-23 01:51:28 +00:00
tag_kind_id = Channel.tag_kind.get_id('channel')
channel_name = channel.name
return (Tag
.select(Tag, Channel)
.join(Channel, on=(Tag.id == Channel.linked_tag))
.where(Channel.repository == repo,
Channel.name == channel_name,
Channel.tag_kind == tag_kind_id, Channel.lifetime_end != None)
.order_by(Tag.lifetime_end))
def get_channel(repo, channel_name, models_ref):
2017-03-23 01:51:28 +00:00
""" Find a Channel by name. """
channel = tag_model.get_tag(repo, channel_name, models_ref, "channel")
2017-03-23 01:51:28 +00:00
return channel
def get_tag_channels(repo, tag_name, models_ref, active=True):
2017-03-23 01:51:28 +00:00
""" Find the Channels associated with a Tag. """
Tag = models_ref.Tag
tag = tag_model.get_tag(repo, tag_name, models_ref, "release")
2017-03-23 01:51:28 +00:00
query = tag.tag_parents
if active:
query = tag_model.tag_is_alive(query, Tag)
2017-03-23 01:51:28 +00:00
return query
def delete_channel(repo, channel_name, models_ref):
2017-03-23 01:51:28 +00:00
""" Delete a channel by name. """
return tag_model.delete_tag(repo, channel_name, models_ref, "channel")
2017-03-23 01:51:28 +00:00
def create_or_update_channel(repo, channel_name, tag_name, models_ref):
2017-03-23 01:51:28 +00:00
""" Creates or updates a channel to include a particular tag. """
tag = tag_model.get_tag(repo, tag_name, models_ref, 'release')
return tag_model.create_or_update_tag(repo, channel_name, models_ref, linked_tag=tag,
tag_kind="channel")
2017-03-23 01:51:28 +00:00
def get_repo_channels(repo, models_ref):
2017-03-23 01:51:28 +00:00
""" Creates or updates a channel to include a particular tag. """
Channel = models_ref.Channel
Tag = models_ref.Tag
2017-03-23 01:51:28 +00:00
tag_kind_id = Channel.tag_kind.get_id('channel')
query = (Channel
.select(Channel, Tag)
.join(Tag, on=(Tag.id == Channel.linked_tag))
.where(Channel.repository == repo,
Channel.tag_kind == tag_kind_id))
return tag_model.tag_is_alive(query, Channel)