def fetch_channel(self, package_name, channel_name, with_releases=True): """ Returns an AppChannel. """ repo = _application(package_name) try: channel = appr_model.channel.get_channel(repo, channel_name, self.models_ref) except (self.models_ref.Channel.DoesNotExist, self.models_ref.Tag.DoesNotExist): raise_channel_not_found(package_name, channel_name) if with_releases: releases = appr_model.channel.get_channel_releases( repo, channel, self.models_ref) chanview = ChannelReleasesView( current=channel.linked_tag.name, name=channel.name, releases=[channel.linked_tag.name] + [c.name for c in releases], ) else: chanview = ChannelView(current=channel.linked_tag.name, name=channel.name) return chanview
def list_channels(self, package_name): """ Returns all AppChannel for a package. """ repo = _application(package_name) channels = appr_model.channel.get_repo_channels(repo, self.models_ref) return [ChannelView(name=chan.name, current=chan.linked_tag.name) for chan in channels]
def list_applications(self, namespace=None, media_type=None, search=None, username=None, with_channels=False): """ Lists all repositories that contain applications, with optional filtering to a specific namespace and view a specific user. """ limit = app.config.get("APP_REGISTRY_RESULTS_LIMIT", 50) namespace_whitelist = app.config.get( "APP_REGISTRY_PACKAGE_LIST_CACHE_WHITELIST", []) # NOTE: This caching only applies for the super-large and commonly requested results # sets. if (namespace is not None and namespace in namespace_whitelist and media_type is None and search is None and username is None and not with_channels): def _list_applications(): return [ found._asdict() for found in self._list_applications(namespace=namespace, limit=limit) ] apps_cache_key = cache_key.for_appr_applications_list( namespace, limit) results = [ CachedApplication(**found) for found in model_cache.retrieve( apps_cache_key, _list_applications) ] else: results = self._list_applications(namespace, media_type, search, username, with_channels, limit=limit) return [ ApplicationSummaryView( namespace=result.namespace, name=result.name, visibility=result.visibility, default=result.tag_names[0] if result.tag_names else None, channels=[ ChannelView(name=channel.name, current=channel.linked_tag_name) for channel in result.channels ] if result.channels is not None else None, manifests=result.manifests, releases=result.tag_names, updated_at=_timestamp_to_iso(result.latest_lifetime_start), created_at=_timestamp_to_iso(result.first_lifetime_start), ) for result in results ]
def list_release_channels(self, package_name, release, active=True): repo = _application(package_name) try: channels = appr_model.channel.get_tag_channels( repo, release, self.models_ref, active=active ) return [ChannelView(name=c.name, current=release) for c in channels] except (self.models_ref.Channel.DoesNotExist, self.models_ref.Tag.DoesNotExist): raise_package_not_found(package_name, release)
def _list_applications( self, namespace=None, media_type=None, search=None, username=None, with_channels=False, limit=None, ): limit = limit or app.config.get("APP_REGISTRY_RESULTS_LIMIT", 50) views = [] for repo in appr_model.package.list_packages_query(self.models_ref, namespace, media_type, search, username=username, limit=limit): tag_set_prefetch = getattr(repo, self.models_ref.tag_set_prefetch_name) releases = [t.name for t in tag_set_prefetch] if not releases: continue available_releases = [ str(x) for x in sorted(cnr.semver.versions(releases, False), reverse=True) ] channels = None if with_channels: channels = [ ChannelView(name=chan.name, current=chan.linked_tag.name) for chan in appr_model.channel.get_repo_channels( repo, self.models_ref) ] app_name = _join_package_name(repo.namespace_user.username, repo.name) manifests = self.list_manifests(app_name, available_releases[0]) view = ApplicationSummaryView( namespace=repo.namespace_user.username, name=app_name, visibility=data_model.repository.repository_visibility_name( repo), default=available_releases[0], channels=channels, manifests=manifests, releases=available_releases, updated_at=_timestamp_to_iso( tag_set_prefetch[-1].lifetime_start), created_at=_timestamp_to_iso( tag_set_prefetch[0].lifetime_start), ) views.append(view) return views
def update_channel(self, package_name, channel_name, release): """ Append a new release to the AppChannel Returns: A new AppChannel with the release """ if self.is_readonly: raise ReadOnlyException("Currently in read-only mode") repo = _application(package_name) channel = appr_model.channel.create_or_update_channel( repo, channel_name, release, self.models_ref) return ChannelView(current=channel.linked_tag.name, name=channel.name)
def list_applications(self, namespace=None, media_type=None, search=None, username=None, with_channels=False): """ Lists all repositories that contain applications, with optional filtering to a specific namespace and view a specific user. """ views = [] for repo in appr_model.package.list_packages_query(self.models_ref, namespace, media_type, search, username=username): tag_set_prefetch = getattr(repo, self.models_ref.tag_set_prefetch_name) releases = [t.name for t in tag_set_prefetch] if not releases: continue available_releases = [ str(x) for x in sorted(cnr.semver.versions(releases, False), reverse=True) ] channels = None if with_channels: channels = [ ChannelView(name=chan.name, current=chan.linked_tag.name) for chan in appr_model.channel.get_repo_channels( repo, self.models_ref) ] app_name = _join_package_name(repo.namespace_user.username, repo.name) manifests = self.list_manifests(app_name, available_releases[0]) view = ApplicationSummaryView( namespace=repo.namespace_user.username, name=app_name, visibility=repo.visibility.name, default=available_releases[0], channels=channels, manifests=manifests, releases=available_releases, updated_at=_timestamp_to_iso( tag_set_prefetch[-1].lifetime_start), created_at=_timestamp_to_iso( tag_set_prefetch[0].lifetime_start), ) views.append(view) return views