Coverage for appr/models/kv/package_kv_base.py: 32%

# Coverage for appr/models/kv/package_kv_base.py : 32%

## 69 statements 22 run 47 missing 0 excluded

Hot-keys on this page

r m x p toggle line displays

j k next/prev highlighted chunk

0 (zero) top of page

1 (one) first highlighted chunk

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | from __future__ import absolute_import, division, print_function import re import appr.semver as semver from appr.exception import Unsupported from appr.models.kv.models_index_base import ModelsIndexBase from appr.models.package_base import PackageBase class PackageKvBase(PackageBase): index_class = ModelsIndexBase @property def index(self): return self.index_class(self.package) @classmethod def _fetch(cls, package, release, media_type='kpm'): index = cls.index_class(package) return index.release(release, media_type) # def channels(self, channel_class, iscurrent=True): # return self.index.release_channels(self.release) @classmethod def all_releases(cls, package, media_type=None): index = cls.index_class(package) return index.releases(media_type) @classmethod def dump_all(cls, blob_cls): index = cls.index_class() result = [] for package_info in index.packages(): package_name = package_info['namespace'] + "/" + package_info['name'] releaseindex = cls.index_class(package_name) for release in releaseindex.releases(): for _, package_data in releaseindex.release_manifests(release).iteritems(): package_data['channels'] = releaseindex.release_channels(release) package_data['blob'] = releaseindex.get_blob(package_data['content']['digest']) result.append(package_data) return result @classmethod def all(cls, namespace=None, media_type=None, search=None, **kwargs): index = cls.index_class() result = [] matching = None if search: matching = cls.search(search) for package_data in index.packages(namespace): namespace, name = package_data['namespace'], package_data['name'] package_name = "%s/%s" % (namespace, name) if matching is not None and package_name not in matching: continue created_at = package_data['created_at'] releaseindex = cls.index_class(package_name) available_releases = [ str(x) for x in sorted( semver.versions(releaseindex.releases(media_type=media_type), False), reverse=True) ] # yapf: disable if not available_releases: continue if media_type is None: manifest_list = cls.manifests(package_name, available_releases[0]) else: manifest_list = [media_type] view = { 'releases': available_releases, 'default': available_releases[0], 'manifests': manifest_list, 'name': package_name, 'visibility': 'public', 'created_at': created_at} result.append(view) return result @classmethod def isdeleted_release(cls, package, release): """ TODO """ return False def _save(self, force=False, **kwargs): return self.index.add_release(self.data, self.release, self.media_type, force) @classmethod def search(cls, query, **kwargs): index = cls.index_class() searchindex = '\n'.join(index.package_names()) return re.findall(r"(.*%s.*)" % query, searchindex) @classmethod def _delete(cls, package, release, media_type): index = cls.index_class(package) return index.delete_release(release, media_type) @classmethod def reindex(cls): raise Unsupported("Reindex is not yet supported") @classmethod def manifests(cls, package, release): index = cls.index_class(package) return index.release_manifests(release).keys()