From 1a802392aa917a921b347ca47447eb5d06b5e367 Mon Sep 17 00:00:00 2001 From: Sebastien Luttringer <sebastien.luttringer@smartjog.com> Date: Wed, 14 Dec 2011 18:18:06 +0100 Subject: [PATCH] add --purge to command repo repo command can now purge cache of database --- bin/is | 17 +++++++++++++---- completion/bash/is | 2 +- installsystems/repository.py | 18 +++++++++++++++++- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/bin/is b/bin/is index ebff7b4..8477730 100755 --- a/bin/is +++ b/bin/is @@ -412,10 +412,17 @@ def c_repo(parser, args): ''' Get information about repositories ''' + # in cleaning mode we doesn't needs to get repositories + if args.purge: + args.force_offline = True repoman = load_repositories(args) for pattern in args.repository: - show_repositories(repoman, pattern, online=args.online, local=args.local, - url=args.url, state=args.state) + if args.purge: + repoman.purge_cache(pattern) + else: + show_repositories(repoman, pattern, + online=args.online, local=args.local, + url=args.url, state=args.state) def c_search(parser, args): ''' @@ -675,8 +682,6 @@ p_prepare_chroot.set_defaults(func=c_prepare_chroot) # repo command parser p_repo = subparsers.add_parser("repo", help=c_repo.__doc__.lower()) -p_repo.add_argument("--force-offline", action="store_true", default=False, - help="force repository to be offline") p_repo_mgroup = p_repo.add_mutually_exclusive_group() p_repo_mgroup.add_argument("-l", "--local", action="store_true", default=None, help="list local repository (filter)") @@ -687,6 +692,10 @@ p_repo_mgroup.add_argument("-o", "--online", action="store_true", default=None, help="list online repository (filter)") p_repo_mgroup.add_argument("-O", "--offline", action="store_false", dest="online", help="list offline repository (filter)") +p_repo.add_argument("--purge", action="store_true", default=False, + help="remove cache databases") +p_repo.add_argument("--force-offline", action="store_true", default=False, + help="force repository to be offline") p_repo.add_argument("-s", "--state", action="store_true", default=False, help="display repository state (online/offline/local/remote)") p_repo.add_argument("-u", "--url", action="store_true", default=False, diff --git a/completion/bash/is b/completion/bash/is index 66bcfd6..9572036 100644 --- a/completion/bash/is +++ b/completion/bash/is @@ -139,7 +139,7 @@ _is() { _filedir -d ;; repo) - [[ "$cur" == -* ]] && _opt '-h --help -l --local -r --remote -o --online -O --offline -s --state --force-offline -u --url' && return 0 + [[ "$cur" == -* ]] && _opt '-h --help -l --local -r --remote -o --online -O --offline -s --state --force-offline --purge -u --url' && return 0 _repo ;; search) diff --git a/installsystems/repository.py b/installsystems/repository.py index cfa0d4d..80fe9a5 100644 --- a/installsystems/repository.py +++ b/installsystems/repository.py @@ -528,7 +528,7 @@ class RepositoryManager(object): ''' try: if temp and nosync: - raise IOError("unable to cache, sync is disabled") + raise IOError("Unable to cache, sync is disabled") # Ensure destination file exists if temp is True or self.cache_path is None: # this is a forced temporary repository or without name repo @@ -663,6 +663,22 @@ class RepositoryManager(object): arrow(repo.config.name) repo.search(pattern) + def purge_cache(self, pattern): + ''' + Remove local cached repository files + ''' + for reponame in fnmatch.filter(self.names, pattern): + arrow("Purging cache of repository %s" % reponame) + db = os.path.join(self.cache_path, reponame) + if os.path.exists(db): + try: + os.unlink(db) + arrow("done", 1) + except: + arrow("failed", 1) + else: + arrow("nothing to do", 1) + class RepositoryConfig(object): ''' -- GitLab