diff --git a/bin/is b/bin/is index b5db6449791d3d83577176d8968a2d3667705ea8..499c862d16c296644f2a0a8289222e8c38f63089 100755 --- a/bin/is +++ b/bin/is @@ -37,7 +37,7 @@ def load_repositories(args): if hasattr(args, "no_cache") and args.no_cache: args.cache = None # split filter in list - args.repo_filter = split_repository_list(args.repo_filter) + args.repo_filter = Repository.split_repository_list(args.repo_filter) # init repo cache object repoman = RepositoryManager(args.cache, timeout=args.timeout, filter=args.repo_filter) # register repositories (order matter) @@ -51,14 +51,6 @@ def load_repositories(args): repoman.register(repoconf, nosync=args.no_sync) return repoman -def split_repository_list(repolist, filter=None): - ''' - Return a list of repository from an comma/spaces separated names of repo - ''' - if filter is None: - filter = Repository.is_repository_name - return [r for r in re.split("[ ,\n\t\v]+", repolist) if filter(r)] - def show_repositories(repoman, pattern, local=None, online=None, url=False, state=True): ''' @@ -108,7 +100,7 @@ def select_image(name, repoman, search=None, best=False): else: if len(repoman.onlines) == 0: raise Exception('No online repository') - (repo, image, version) = istools.split_image_path(name) + (repo, image, version) = Repository.split_image_path(name) debug("Requested image: %s v%s in %s" % (image, version, repo)) # repo is not specified, we need to crawl in path if repo is None: @@ -371,7 +363,7 @@ def c_list(args): if args.repo_search == "": search = repoman.onlines else: - search = split_repository_list(args.repo_search, lambda x: x in repoman.onlines) + search = Repository.split_repository_list(args.repo_search, lambda x: x in repoman.onlines) for pattern in args.image: show_images(repoman, pattern, all_version=args.all_version, search=search, diff --git a/installsystems/repository.py b/installsystems/repository.py index d676a6c0ee7b9acebb790bdb190a770c23c80409..e3ce497c7539959354773333d4f8f6f7a452467a 100644 --- a/installsystems/repository.py +++ b/installsystems/repository.py @@ -41,6 +41,26 @@ class Repository(object): raise Exception("Invalid repository name %s" % name) return name + @staticmethod + def split_image_path(path): + ''' + Split an image path (repo/image:version) + in a tuple (repo, image, version) + ''' + x = re.match(u"^(?:([^/]+)/)?([^:]+)?(?::v?(.+))?$", path) + if x is None: + raise Exception("invalid image path: %s" % path) + return x.group(1, 2, 3) + + @staticmethod + def split_repository_list(repolist, filter=None): + ''' + Return a list of repository from an comma/spaces separated names of repo + ''' + if filter is None: + filter = Repository.is_repository_name + return [r for r in re.split("[ ,\n\t\v]+", repolist) if filter(r)] + @classmethod def diff(cls, repo1, repo2): ''' diff --git a/installsystems/tools.py b/installsystems/tools.py index 021e748bf83d58c691c0873a01e835a32670ef02..1a4556ab4a12401d636b23f9ee9e5489d254d355 100644 --- a/installsystems/tools.py +++ b/installsystems/tools.py @@ -567,13 +567,3 @@ def compare_versions(v1, v2): fv1 = get_ver(v1) fv2 = get_ver(v2) return fv1 - fv2 - -def split_image_path(path): - ''' - Split an image path (repo/image:version) - in a tuple (repo, image, version) - ''' - x = re.match(u"^(?:([-_\w]+)/)?([-_\w]+)(?::v?(\d+))?$", path) - if x is None: - raise Exception("invalid image path: %s" % path) - return x.group(1,2,3)