Loading bin/is +17 −5 Original line number Diff line number Diff line Loading @@ -61,15 +61,27 @@ def get_images(patterns, repoman, local=True, min=None, max=None): Return the repository as second argument ''' ans = [] for pattern in patterns: # check if image is a local file if local and istools.isfile(pattern) and os.path.isfile(pattern): yield PackageImage(pattern), None # we need to find image in a repository ans.append((pattern, None)) else: # we need to find image in a repository ans += sorted(repoman.select_images([pattern]).items()) # check selected images cound if min is not None and len(ans) < min: raise Exception("%s images found. Should be at least %s" % ( len(ans), min)) # check max selected images if max is not None and len(ans) > max: raise Exception("Too many selected images: %s. Max is %s" % ( ", ".join([n[0] for n in ans]), max)) for item in ans: if item[1] is None: yield PackageImage(item[0]), None else: for i in repoman.get_images(pattern, min=min, max=max): yield i r = item[1] yield repoman[r["repo"]].get(r["name"], r["version"]), r["repo"] ################################################################################ # Commands functions Loading installsystems/repository.py +39 −53 Original line number Diff line number Diff line Loading @@ -660,16 +660,19 @@ class RepositoryManager(object): ''' return [ r.config.name for r in self.repos if r.config.offline ] def select_images(self, pattern, min=None, max=None): def select_images(self, patterns): ''' Return a list of available images ''' if len(self.onlines) == 0: raise Exception("No online repository") ans = {} for pattern in patterns: path, image, version = Repository.split_image_path(pattern) # no image name => get away # no image name, skip it if image is None: raise Exception("No given image name") warn("No image name in pattern %s, skipped" % pattern) continue # building image list images = {} for reponame in self.onlines: Loading @@ -696,26 +699,11 @@ class RepositoryManager(object): del images["%s/%s:%s" % (repo, img, rmv)] # filter with pattern on path filter_pattern = "%s/%s:%s" % (path, image, version) debug("select_image filter is %s with search %s" % (filter_pattern, self.search)) for k in images.keys(): if not fnmatch.fnmatch(k, filter_pattern): del images[k] # check selected images cound if min is not None and len(images) < min: raise Exception("%s images found by pattern %s. Should be at least %s" % ( len(images), pattern, min)) # check max selected images if max is not None and len(images) > max: raise Exception("Too many selected images: %s. Max is %s" % ( ", ".join(images.keys()), max)) return images def get_images(self, pattern, min=None, max=None): ''' Get image object ''' for path, image in self.select_images(pattern, min=min, max=max).items(): yield self[image["repo"]].get(image["name"], image["version"]), self[image["repo"]] ans.update(images) return ans def search_image(self, pattern): ''' Loading @@ -732,9 +720,7 @@ class RepositoryManager(object): Show images inside manager ''' # get images list images = {} for pattern in patterns: images.update(self.select_images(pattern)) images = self.select_images(patterns) # display result if o_json: s = json.dumps(images) Loading Loading
bin/is +17 −5 Original line number Diff line number Diff line Loading @@ -61,15 +61,27 @@ def get_images(patterns, repoman, local=True, min=None, max=None): Return the repository as second argument ''' ans = [] for pattern in patterns: # check if image is a local file if local and istools.isfile(pattern) and os.path.isfile(pattern): yield PackageImage(pattern), None # we need to find image in a repository ans.append((pattern, None)) else: # we need to find image in a repository ans += sorted(repoman.select_images([pattern]).items()) # check selected images cound if min is not None and len(ans) < min: raise Exception("%s images found. Should be at least %s" % ( len(ans), min)) # check max selected images if max is not None and len(ans) > max: raise Exception("Too many selected images: %s. Max is %s" % ( ", ".join([n[0] for n in ans]), max)) for item in ans: if item[1] is None: yield PackageImage(item[0]), None else: for i in repoman.get_images(pattern, min=min, max=max): yield i r = item[1] yield repoman[r["repo"]].get(r["name"], r["version"]), r["repo"] ################################################################################ # Commands functions Loading
installsystems/repository.py +39 −53 Original line number Diff line number Diff line Loading @@ -660,16 +660,19 @@ class RepositoryManager(object): ''' return [ r.config.name for r in self.repos if r.config.offline ] def select_images(self, pattern, min=None, max=None): def select_images(self, patterns): ''' Return a list of available images ''' if len(self.onlines) == 0: raise Exception("No online repository") ans = {} for pattern in patterns: path, image, version = Repository.split_image_path(pattern) # no image name => get away # no image name, skip it if image is None: raise Exception("No given image name") warn("No image name in pattern %s, skipped" % pattern) continue # building image list images = {} for reponame in self.onlines: Loading @@ -696,26 +699,11 @@ class RepositoryManager(object): del images["%s/%s:%s" % (repo, img, rmv)] # filter with pattern on path filter_pattern = "%s/%s:%s" % (path, image, version) debug("select_image filter is %s with search %s" % (filter_pattern, self.search)) for k in images.keys(): if not fnmatch.fnmatch(k, filter_pattern): del images[k] # check selected images cound if min is not None and len(images) < min: raise Exception("%s images found by pattern %s. Should be at least %s" % ( len(images), pattern, min)) # check max selected images if max is not None and len(images) > max: raise Exception("Too many selected images: %s. Max is %s" % ( ", ".join(images.keys()), max)) return images def get_images(self, pattern, min=None, max=None): ''' Get image object ''' for path, image in self.select_images(pattern, min=min, max=max).items(): yield self[image["repo"]].get(image["name"], image["version"]), self[image["repo"]] ans.update(images) return ans def search_image(self, pattern): ''' Loading @@ -732,9 +720,7 @@ class RepositoryManager(object): Show images inside manager ''' # get images list images = {} for pattern in patterns: images.update(self.select_images(pattern)) images = self.select_images(patterns) # display result if o_json: s = json.dumps(images) Loading