#! /usr/bin/env python # copy old pyraf.Database cache to new clcache directory # # If your iraf directory is not ~/iraf, run this from the # directory where your login.cl is found. # # R. White, 2000 Sept 26 import dirdbm, anydbm, os, sys trydirs = ['.', './pyraf', '~/iraf/pyraf'] for dir in trydirs: dir = os.path.expanduser(dir) oldfile = os.path.join(dir,'pyraf.Database') if os.path.exists(oldfile): break else: print 'Error: cannot find old pyraf.Database' print 'Checked', for dir in trydirs: print dir, print print 'Run this script from your iraf directory' sys.exit(1) newfile = os.path.join(dir,'clcache') old = anydbm.open(oldfile, 'r') new = dirdbm.open(newfile, 'c') keys = old.keys() i = 0 nskip = 0 nkeys = len(keys) print 'Copying',nkeys,'clcache entries' for key in keys: if not new.has_key(key): new[key] = old[key] else: nskip = nskip + 1 i = i+1 sys.stdout.write("Finished %d of %d%s" % (i,nkeys,chr(13))) sys.stdout.flush() old.close() new.close() print if nskip>0: print 'Skipped',nskip,'entries already found in',newfile print 'Successfully created %s' % newfile print 'Old CL cache (%s) can be deleted' % oldfile