Example #1
0
 def select_images(self, patterns):
     '''
     Return a list of available images
     '''
     if len(self.onlines) == 0:
         raise ISError(u"No online repository")
     ans = {}
     for pattern in patterns:
         path, image, version = Repository.split_image_path(pattern)
         if image is None:
             if path is None or version is None:
                 image = "*"
             else:
                 # empty pattern
                 continue
         # building image list
         images = {}
         for reponame in self.onlines:
             for img in self[reponame].images():
                 imgname = u"%s/%s:%s" % (reponame, img["name"], img["version"])
                 images[imgname] = img
         # No path means only in searchable repositories
         if path is None:
             for k, v in images.items():
                 # match name
                 if v["repo"] not in self.search:
                     uuid = self[v["repo"]].uuid
                     # match uuid
                     if not [uuid for pat in self.search
                             if fnmatch.fnmatch(uuid, '%s*' % pat)]:
                         del images[k]
             path = "*"
         # No version means last version
         if version is None:
             version = "*"
             for repo in set((images[i]["repo"] for i in images)):
                 for img in set((images[i]["name"] for i in images if images[i]["repo"] == repo)):
                     versions = [ images[i]['version']
                                  for i in images if images[i]["repo"] == repo and images[i]["name"] == img ]
                     f = lambda x,y: x if istools.compare_versions(x, y) > 0 else y
                     last = reduce(f, versions)
                     versions.remove(last)
                     for rmv in versions:
                         del images[u"%s/%s:%s" % (repo, img, rmv)]
         # if 'path*' do not match a repo name, it may be an uuid, so add
         # globbing for smart uuid matching
         if not fnmatch.filter(self.onlines, "%s*" % path):
             path = "%s*" % path
         # filter with pattern on path
         filter_pattern = u"%s/%s:%s" % (path, image, version)
         for k, img in images.items():
             if not (fnmatch.fnmatch(k, filter_pattern) or
                     fnmatch.fnmatch("%s/%s" % (self[img["repo"]].uuid, k.split("/")[1]), filter_pattern)):
                 del images[k]
         ans.update(images)
     return ans
Example #2
0
 def check_min_version(version):
     '''
     Check InstallSystems min version
     '''
     if compare_versions(VERSION, version) < 0:
         raise ISError("Minimum Installsystems version not satisfied "
                       "(%s)" % version)
     # return the version, because this function is used by ConfigObj
     # validate to ensure the version is correct
     return version
Example #3
0
 def last(self, name):
     '''
     Return last version of name in repo or None if not found
     '''
     r = self.db.ask("SELECT version FROM image WHERE name = ?", (name,)).fetchall()
     # no row => no way
     if r is None:
         return None
     f = lambda x,y: x[0] if compare_versions(x[0], y[0]) > 0 else y[0]
     # return last
     return reduce(f, r)
Example #4
0
 def compare_versions(v1, v2):
     '''
     For backward compatibility, image class offer a method to compare image versions
     But code is now inside tools
     '''
     return compare_versions(v1, v2)