diff options
author | Brian Harring <ferringb@gentoo.org> | 2005-08-03 00:53:17 +0000 |
---|---|---|
committer | Brian Harring <ferringb@gentoo.org> | 2005-08-03 00:53:17 +0000 |
commit | 48bc2fb4f6533555c31956c8cb829b758832a912 (patch) | |
tree | 98d3e42657d437816988752b13d7675fba4738d2 | |
parent | ver_cmp info (diff) | |
download | portage-cvs-48bc2fb4f6533555c31956c8cb829b758832a912.tar.gz portage-cvs-48bc2fb4f6533555c31956c8cb829b758832a912.tar.bz2 portage-cvs-48bc2fb4f6533555c31956c8cb829b758832a912.zip |
useful little utility for converting between cache backends without having to do a regen.
-rwxr-xr-x | rewrite-misc/utilities/clone_cache.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/rewrite-misc/utilities/clone_cache.py b/rewrite-misc/utilities/clone_cache.py new file mode 100755 index 0000000..da09e46 --- /dev/null +++ b/rewrite-misc/utilities/clone_cache.py @@ -0,0 +1,44 @@ +#!/usr/bin/python +import portage.config, sys, time + +if __name__ == "__main__": + verbose = 0 + if len(sys.argv) not in (3,4): + print "I need 2 args, cache label to read from, cache label to write to, with -v optional for verbose" + elif len(sys.argv) == 4: + verbose = 1 + c=portage.config.load_config() + try: cache1 = c.cache[sys.argv[1]] + except KeyError: + print "read cache label '%s' isn't defined." % sys.argv[1] + sys.exit(1) + try: cache2 = c.cache[sys.argv[2]] + except KeyError: + print "write cache label '%s' isn't defined." % sys.argv[2] + sys.exit(1) + + if cache2.readonly: + print "can't update cache label '%s', it's marked readonly." % sys.argv[2] + sys.exit(2) + if not cache2.autocommits: + cache2.sync_rate = 1000 + if verbose: print "grabbing cache2's existing keys" + valid = {} + start = time.time() + if verbose: + for k,v in cache1.iteritems(): + print "updating %s" % k + cache2[k] = v + valid[k] = True + else: + for k,v in cache1.iteritems(): + cache2[k] = v + valid[k] = True + + for x in cache2.iterkeys(): + if not x in valid: + if verbose: print "deleting %s" % x + del cache2[x] + + if verbose: + print "took %i seconds" % int(time.time() - start) |