示例#1
0
 def _exists(self):
     """ Check if the channel is saved already """
     path = self._etcdpath(self.package, self.name)
     try:
         etcd_client.read(path)
     except etcd.EtcdKeyNotFound:
         return False
     return True
示例#2
0
文件: package.py 项目: ryanj/kpm
    def all(self, organization=None):
        path = ETCD_PREFIX
        r = {}
        if organization is not None:
            path += "/%s" % organization
        try:
            packages = etcd_client.read(path, recursive=True)
        except etcd.EtcdKeyNotFound:
            etcd_client.write(path, None, dir=True)

        for child in packages.children:
            m = re.match("^/%s(.+)/(.+)/releases/(.+)$" % ETCD_PREFIX,
                         child.key)
            if m is None:
                continue
            organization, name, version = (m.group(1), m.group(2), m.group(3))
            package = "%s/%s" % (organization, name)
            if package not in r:
                r[package] = {
                    "name": package,
                    'available_versions': [],
                    'version': None
                }
            r[package]['available_versions'].append(version)

        for _, v in r.iteritems():
            v['available_versions'] = [
                str(x) for x in sorted(semver.versions(v['available_versions'],
                                                       False),
                                       reverse=True)
            ]
            v['version'] = v['available_versions'][0]
        return r.values()
示例#3
0
文件: package.py 项目: ryanj/kpm
 def _fetch(self, package, version):
     path = self._etcdkey(package, str(version))
     try:
         package_data = json.loads(etcd_client.read(path).value)
     except etcd.EtcdKeyNotFound:
         self._raise_not_found(package, version)
     return package_data
示例#4
0
 def releases(self):
     """ Returns the list of versions """
     path = self._etcdpath(self.package, self.name)
     try:
         releases = etcd_client.read(path, recursive=True)
     except etcd.EtcdKeyNotFound:
         self._raise_not_found(self.package, self.name)
     result = etcd_listkeys(releases, path)
     return result
示例#5
0
文件: package.py 项目: ryanj/kpm
    def all_versions(self, package):
        path = ETCD_PREFIX + package + "/releases"
        try:
            r = etcd_client.read(path, recursive=True)
        except etcd.EtcdKeyNotFound:
            self._raise_not_found(package, None)

        versions = []
        for p in r.children:
            version = p.key.split("/")[-1]
            versions.append(version)
        return versions
示例#6
0
 def all(self, package):
     """
     Returns all available channels for a package
     """
     path = self._etcdpath(package)
     try:
         chans = etcd_client.read(path, recursive=True)
     except etcd.EtcdKeyNotFound:
         return []
     result = []
     for child in chans.children:
         m = re.match("^/%s/([a-zA-Z0-9-_]+)/?.*$" % path, child.key)
         if m is None:
             continue
         channel = m.group(1)
         result.append(channel)
     return result