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
|
|
|
|
|
|
|
|
2018-05-24 21:54:51 +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.
|
|
|
|
"""
|
2018-05-24 21:54:51 +00:00
|
|
|
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))
|
|
|
|
|
|
|
|
|
2018-05-24 21:54:51 +00:00
|
|
|
def get_channel(repo, channel_name, models_ref):
|
2017-03-23 01:51:28 +00:00
|
|
|
""" Find a Channel by name. """
|
2018-05-24 21:54:51 +00:00
|
|
|
channel = tag_model.get_tag(repo, channel_name, models_ref, "channel")
|
2017-03-23 01:51:28 +00:00
|
|
|
return channel
|
|
|
|
|
|
|
|
|
2018-05-24 21:54:51 +00:00
|
|
|
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. """
|
2018-05-24 21:54:51 +00:00
|
|
|
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:
|
2018-05-24 21:54:51 +00:00
|
|
|
query = tag_model.tag_is_alive(query, Tag)
|
2017-03-23 01:51:28 +00:00
|
|
|
|
|
|
|
return query
|
|
|
|
|
|
|
|
|
2018-05-24 21:54:51 +00:00
|
|
|
def delete_channel(repo, channel_name, models_ref):
|
2017-03-23 01:51:28 +00:00
|
|
|
""" Delete a channel by name. """
|
2018-05-24 21:54:51 +00:00
|
|
|
return tag_model.delete_tag(repo, channel_name, models_ref, "channel")
|
2017-03-23 01:51:28 +00:00
|
|
|
|
|
|
|
|
2018-05-24 21:54:51 +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. """
|
2018-05-24 21:54:51 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
2018-05-24 21:54:51 +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. """
|
2018-05-24 21:54:51 +00:00
|
|
|
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))
|
2018-05-24 21:54:51 +00:00
|
|
|
return tag_model.tag_is_alive(query, Channel)
|