Commit 1a802392 authored by Sebastien Luttringer's avatar Sebastien Luttringer
Browse files

add --purge to command repo

repo command can now purge cache of database
parent 107ef559
Loading
Loading
Loading
Loading
+13 −4
Original line number Diff line number Diff line
@@ -412,9 +412,16 @@ 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,
        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,
+1 −1
Original line number Diff line number Diff line
@@ -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)
+17 −1
Original line number Diff line number Diff line
@@ -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):
    '''