bye bye you decrepit POS cache implementation.
authorBrian Harring <ferringb@gentoo.org>
Sat, 5 Nov 2005 06:14:41 +0000 (06:14 -0000)
committerBrian Harring <ferringb@gentoo.org>
Sat, 5 Nov 2005 06:14:41 +0000 (06:14 -0000)
svn path=/main/branches/2.0/; revision=2259

pym/portage_db_anydbm.py [deleted file]
pym/portage_db_cpickle.py [deleted file]
pym/portage_db_flat.py [deleted file]
pym/portage_db_flat_hash.py [deleted file]
pym/portage_db_metadata.py [deleted file]
pym/portage_db_template.py [deleted file]
pym/portage_db_test.py [deleted file]

diff --git a/pym/portage_db_anydbm.py b/pym/portage_db_anydbm.py
deleted file mode 100644 (file)
index 5f0e229..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-# Copyright 2004 Gentoo Foundation
-# Distributed under the terms of the GNU General Public License v2
-# $Id: /var/cvsroot/gentoo-src/portage/pym/Attic/portage_db_anydbm.py,v 1.11.2.1 2005/01/16 02:35:33 carpaski Exp $
-
-
-import anydbm,cPickle,types,os
-
-import portage_db_template
-
-class database(portage_db_template.database):
-       def module_init(self):
-               prevmask=os.umask(0)
-               if not os.path.exists(self.path):
-                       current_path="/"
-                       for mydir in self.path.split("/"):
-                               current_path += "/"+mydir
-                               if not os.path.exists(current_path):
-                                       os.mkdir(current_path)
-
-               self.filename = self.path + "/" + self.category + ".anydbm"
-               
-               try:
-                       # open it read/write
-                       self.db = anydbm.open(self.filename, "c", 0664)
-               except SystemExit, e:
-                       raise
-               except:
-                       # Create a new db... DB type not supported anymore?
-                       self.db = anydbm.open(self.filename, "n", 0664)
-
-               os.umask(prevmask)
-
-       def has_key(self,key):
-               self.check_key(key)
-               if self.db.has_key(key):
-                       return 1
-               return 0
-               
-       def keys(self):
-               return self.db.keys()
-       
-       def get_values(self,key):
-               self.check_key(key)
-               if self.db.has_key(key):
-                       myval = cPickle.loads(self.db[key])
-                       return myval
-               return None
-       
-       def set_values(self,key,val):
-               self.check_key(key)
-               self.db[key] = cPickle.dumps(val,cPickle.HIGHEST_PROTOCOL)
-       
-       def del_key(self,key):
-               if self.has_key(key):
-                       del self.db[key]
-                       return True
-               return False
-                       
-       def sync(self):
-               self.db.sync()
-       
-       def close(self):
-               self.db.close()
-       
diff --git a/pym/portage_db_cpickle.py b/pym/portage_db_cpickle.py
deleted file mode 100644 (file)
index dd30588..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-# Copyright 2004 Gentoo Foundation
-# Distributed under the terms of the GNU General Public License v2
-# $Id: /var/cvsroot/gentoo-src/portage/pym/Attic/portage_db_cpickle.py,v 1.9.2.2 2005/04/23 07:26:04 jstubbs Exp $
-
-
-import anydbm,cPickle,types
-from os import chown,access,R_OK,unlink
-import os
-
-import portage_db_template
-
-class database(portage_db_template.database):
-       def module_init(self):
-               self.modified = False
-               
-               prevmask=os.umask(0)
-               if not os.path.exists(self.path):
-                       os.makedirs(self.path, 02775)
-
-               self.filename = self.path + "/" + self.category + ".cpickle"
-               
-               if access(self.filename, R_OK):
-                       try:
-                               mypickle=cPickle.Unpickler(open(self.filename,"r"))
-                               mypickle.find_global=None
-                               self.db = mypickle.load()
-                       except SystemExit, e:
-                               raise
-                       except:
-                               self.db = {}
-               else:
-                       self.db = {}
-
-               os.umask(prevmask)
-
-       def has_key(self,key):
-               self.check_key(key)
-               if self.db.has_key(key):
-                       return 1
-               return 0
-               
-       def keys(self):
-               return self.db.keys()
-       
-       def get_values(self,key):
-               self.check_key(key)
-               if self.db.has_key(key):
-                       return self.db[key]
-               return None
-       
-       def set_values(self,key,val):
-               self.modified = True
-               self.check_key(key)
-               self.db[key] = val
-       
-       def del_key(self,key):
-               if self.has_key(key):
-                       del self.db[key]
-                       self.modified = True
-                       return True
-               return False
-                       
-       def sync(self):
-               if self.modified:
-                       try:
-                               if os.path.exists(self.filename):
-                                       unlink(self.filename)
-                               cPickle.dump(self.db, open(self.filename,"w"), -1)
-                               os.chown(self.filename,self.uid,self.gid)
-                               os.chmod(self.filename, 0664)
-                       except SystemExit, e:
-                               raise
-                       except:
-                               pass
-       
-       def close(self):
-               self.sync()
-               self.db = None;
-       
diff --git a/pym/portage_db_flat.py b/pym/portage_db_flat.py
deleted file mode 100644 (file)
index 4fc220b..0000000
+++ /dev/null
@@ -1,124 +0,0 @@
-# Copyright 2004 Gentoo Foundation
-# Distributed under the terms of the GNU General Public License v2
-# $Id: /var/cvsroot/gentoo-src/portage/pym/Attic/portage_db_flat.py,v 1.13.2.6 2005/04/19 07:14:17 ferringb Exp $
-
-
-import types
-import os
-import stat
-
-import portage_db_template
-
-# since this format is massively deprecated, 
-# we're hardcoding the previously weird line count
-magic_line_count = 22
-
-class database(portage_db_template.database):
-       def module_init(self):
-               self.lastkey  = None # Cache
-               self.lastval  = None # Cache
-
-               self.fullpath = self.path + "/" + self.category + "/"
-
-               if not os.path.exists(self.fullpath):
-                       prevmask=os.umask(0)
-                       os.makedirs(self.fullpath, 02775)
-                       os.umask(prevmask)
-                       try:
-                               os.chown(self.fullpath, self.uid, self.gid)
-                               os.chmod(self.fullpath, 02775)
-                       except SystemExit, e:
-                               raise
-                       except:
-                               pass
-               
-       def has_key(self,key):
-               if os.path.exists(self.fullpath+key):
-                       return 1
-               return 0
-       
-       def keys(self):
-               # XXX: NEED TOOLS SEPERATED
-               # return portage.listdir(self.fullpath,filesonly=1)
-               mykeys = []
-               for x in os.listdir(self.fullpath):
-                       if os.path.isfile(self.fullpath+x) and not x.startswith(".update."):
-                               mykeys += [x]
-               return mykeys
-
-       def get_values(self,key, data=None):
-               """ do not use data unless you know what it does."""
-
-               if not key:
-                       raise KeyError, "key is not set to a valid value"
-
-               mydict = {}
-               if data == None:
-                       try:
-                               # give buffering a hint of the pretty much maximal cache size we deal with
-                               myf = open(self.fullpath+key, "r", 8192)
-                       except OSError:
-                               # either the file didn't exist, or it was removed under our feet.
-                               raise KeyError("failed reading key")
-
-                       # nuke the newlines right off the batt.
-                       data = myf.read().splitlines()
-                       mydict["_mtime_"] = os.fstat(myf.fileno()).st_mtime
-                       myf.close()
-               else:
-                       mydict["_mtime_"] = data.pop(-1)
-
-               # rely on exceptions to note differing line counts.
-               try:
-                       for x in range(magic_line_count):
-                               mydict[self.dbkeys[x]] = data[x]
-
-               except IndexError:
-                       raise ValueError, "Key count mistmatch"
-
-               return mydict
-       
-       def set_values(self,key, val, raw=False):
-               if not key:
-                       raise KeyError, "No key provided. key:%s val:%s" % (key,val)
-               if not val:
-                       raise ValueError, "No value provided. key:%s val:%s" % (key,val)
-                       
-               # XXX threaded cache updates won't play nice with this.
-               # need a synchronization primitive, or locking (of the fileno, not a seperate file)
-               # to correctly handle threading.
-
-               update_fp = self.fullpath + ".update." + str(os.getpid()) + "." + key
-               myf = open(update_fp,"w")
-               if not raw:
-                       myf.writelines( [ str(val[x]) +"\n" for x in self.dbkeys] )
-                       if len(self.dbkeys) != magic_line_count:
-                               myf.writelines(["\n"] * len(self.dbkeys) - magic_line_count)
-                       mtime = val["_mtime_"]
-               else:
-                       mtime = val.pop(-1)
-                       myf.writelines(val)
-               myf.close()
-               
-               os.chown(update_fp, self.uid, self.gid)
-               os.chmod(update_fp, 0664)
-               os.utime(update_fp, (-1,long(mtime)))
-               os.rename(update_fp, self.fullpath+key)
-
-       def del_key(self,key):
-               try:
-                       os.unlink(self.fullpath+key)
-               except OSError, oe:
-                       # just attempt it without checking, due to the fact that
-                       # a cache update could be in progress.
-                       self.lastkey = None
-                       self.lastval = None
-                       return 0
-               return 1
-                       
-       def sync(self):
-               return
-       
-       def close(self):
-               return
-       
diff --git a/pym/portage_db_flat_hash.py b/pym/portage_db_flat_hash.py
deleted file mode 100644 (file)
index 44ed59d..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-# Copyright 2004 Gentoo Foundation
-# Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo-src/portage/pym/Attic/portage_db_flat.py,v 1.13.2.6 2005/04/19 07:14:17 ferringb Exp $
-cvs_id_string="$Id: portage_db_flat.py,v 1.13.2.6 2005/04/19 07:14:17 ferringb Exp $"[5:-2]
-
-import portage_db_flat, os
-
-class database(portage_db_flat.database):
-       
-       def get_values(self, key, data=None):
-               """ do not specify data unless you know what it does"""
-               if not key:
-                       raise KeyError("key is not valid")
-               
-               if data == None:
-                       try:
-                               myf = open(self.fullpath + key, "r")
-                       except OSError:
-                               raise KeyError("failed pulling key")
-
-                       data = dict(map(lambda x: x.split("=",1), myf.read().splitlines()))
-                       data["_mtime_"] = os.fstat(myf.fileno()).st_mtime
-                       myf.close()
-
-               mydict = {}
-               for x in self.dbkeys:
-                       mydict[x] = str(data.get(x, ""))
-               mydict["_mtime_"] = long(data["_mtime_"])
-               return mydict
-               
-       def set_values(self, key, values):
-               l = []
-               for x in values.keys():
-                       if values[x] not in (None, '') and x != "_mtime_":
-                               l.append("%s=%s\n" % (x, values[x]))
-               l.append(values["_mtime_"])
-               portage_db_flat.database.set_values(self, key, l, raw=True)
-               
diff --git a/pym/portage_db_metadata.py b/pym/portage_db_metadata.py
deleted file mode 100644 (file)
index 60d87b2..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-# Copyright 2004 Gentoo Foundation
-# Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo-src/portage/pym/Attic/portage_db_flat.py,v 1.13.2.6 2005/04/19 07:14:17 ferringb Exp $
-cvs_id_string="$Id: portage_db_flat.py,v 1.13.2.6 2005/04/19 07:14:17 ferringb Exp $"[5:-2]
-
-import os, portage_db_flat_hash, portage_db_flat
-
-class database(portage_db_flat_hash.database):
-       
-       def get_values(self, key):
-               if not key:
-                       raise KeyError("key is not valid")
-               
-               try:
-                       myf = open(self.fullpath + key, "r")
-               except OSError:
-                       raise KeyError("key is not valid")
-               mtime = os.fstat(myf.fileno()).st_mtime
-               data = myf.read().splitlines()
-               
-               # easy attempt first.
-               if len(data) != portage_db_flat.magic_line_count:
-                       d = dict(map(lambda x: x.split("=",1), data))
-                       d["_mtime_"] = mtime
-                       return portage_db_flat_hash.database.get_values(self, key, d)
-               # this one's interesting.
-               d = {}
-
-               for line in data:
-                       # yes, meant to iterate over a string.
-                       hashed = False
-                       for idx, c in enumerate(line):
-                               if not c.isalpha():
-                                       if c == "=" and idx > 0:
-                                               hashed = True
-                                               d[line[:idx]] = line[idx + 1:]
-                                       elif c == "_" or c.isdigit():
-                                               continue
-                                       break
-                               elif not c.isupper():
-                                       break
-
-                       if not hashed:
-                               # non hashed.
-                               data.append(mtime)
-                               return portage_db_flat.database.get_values(self, key, data=data)
-
-               d["_mtime_"] = mtime
-               return portage_db_flat_hash.database.get_values(self, key, data=d)
diff --git a/pym/portage_db_template.py b/pym/portage_db_template.py
deleted file mode 100644 (file)
index e0ae7f2..0000000
+++ /dev/null
@@ -1,174 +0,0 @@
-# Copyright 2004 Gentoo Foundation
-# Distributed under the terms of the GNU General Public License v2
-# $Id: /var/cvsroot/gentoo-src/portage/pym/Attic/portage_db_template.py,v 1.11.2.1 2005/01/16 02:35:33 carpaski Exp $
-
-
-import os.path,string
-from portage_util import getconfig, ReadOnlyConfig
-from portage_exception import CorruptionError
-
-class database:
-       def __init__(self,path,category,dbkeys,uid,gid,config_path="/etc/portage/module_configs/"):
-               self.__cacheArray = [None, None, None]
-               self.__cacheKeyArray = [None, None, None]
-               self.__template_init_called = True
-               self.path     = path
-               self.category = category
-               self.dbkeys   = dbkeys
-               self.uid      = uid
-               self.gid      = gid
-
-               self.config   = None
-               self.__load_config(config_path)
-
-               self.module_init()
-       
-       def getModuleName(self):
-               return self.__module__+"."+self.__class__.__name__[:]
-
-       def __load_config(self,config_path):
-               config_file = config_path + "/" + self.getModuleName()
-               self.config = ReadOnlyConfig(config_file)
-
-       def __check_init(self):
-               try:
-                       if self.__template_init_called:
-                               pass
-               except SystemExit, e:
-                       raise
-               except:
-                       raise NotImplementedError("db_template.__init__ was overridden")
-
-       def check_key(self,key):
-               if (not key) or not isinstance(key, str):
-                       raise KeyError, "No key provided. key: %s" % (key)
-       
-       def clear(self):
-               for x in self.keys():
-                       self.del_key(x)
-
-       def __addCache(self,key,val):
-               del self.__cacheArray[2]
-               self.__cacheArray.insert(0,val)
-               del self.__cacheKeyArray[2]
-               self.__cacheKeyArray.insert(0,key)
-
-       def __delCache(self,key):
-               i = self.__cacheKeyArray.index(key)
-               self.__cacheArray[i] = None
-               self.__cacheKeyArray[i] = None
-
-       def flushCache(self):
-               self.__cacheArray = [None, None, None]
-               self.__cacheKeyArray = [None, None, None]
-
-       def __getitem__(self,key):
-               if key in self.__cacheKeyArray:
-                       i = self.__cacheKeyArray.index(key)
-                       return self.__cacheArray[i]
-
-               self.check_key(key)
-               if self.has_key(key):
-                       try:
-                               values = self.get_values(key)
-                               self.__addCache(key,values)
-                               return values
-                       except SystemExit, e:
-                               raise
-                       except Exception, e:
-                               raise CorruptionError("Corruption detected when reading key '%s': %s" % (key,str(e)))
-               raise KeyError("Key not in db: '%s'" % (key))
-       
-       def __setitem__(self,key,values):
-               self.check_key(key)
-               self.__addCache(key,values)
-               return self.set_values(key,values)
-
-       def __delitem__(self,key):
-               self.__delCache(key)
-               return self.del_key(key)
-
-       def has_key(self,key):
-               raise NotImplementedError("Method not defined")
-       
-       def keys(self):
-               raise NotImplementedError("Method not defined")
-
-       def get_values(self,key):
-               raise NotImplementedError("Method not defined")
-       
-       def set_values(self,key,val):
-               raise NotImplementedError("Method not defined")
-
-       def del_key(self,key):
-               raise NotImplementedError("Method not defined")
-                       
-       def sync(self):
-               raise NotImplementedError("Method not defined")
-       
-       def close(self):
-               raise NotImplementedError("Method not defined")
-
-
-       
-def test_database(db_class,path,category,dbkeys,uid,gid):
-       if "_mtime_" not in dbkeys:
-               dbkeys+=["_mtime_"]
-       d = db_class(path,category,dbkeys,uid,gid)
-
-       print "Module: "+str(d.__module__)
-
-       # XXX: Need a way to do this that actually works.
-       for x in dir(database):
-               if x not in dir(d):
-                       print "FUNCTION MISSING:",str(x)
-
-       list = d.keys()
-       if(len(list) == 0):
-               values = {}
-               for x in dbkeys:
-                       values[x] = x[:]
-               values["_mtime_"] = "1079903037"
-               d.set_values("test-2.2.3-r1", values)
-               d.set_values("test-2.2.3-r2", values)
-               d.set_values("test-2.2.3-r3", values)
-               d.set_values("test-2.2.3-r4", values)
-
-       list = d.keys()
-       print "Key count:",len(list)
-
-       values = d.get_values(list[0])
-       print "value count:",len(values)
-       
-       mykey = "foobar-1.2.3-r4"
-       
-       d.check_key(mykey)
-       d.set_values(mykey, values)
-       d.sync()
-       del d
-
-       d = db_class(path,category,dbkeys,uid,gid)
-       new_vals = d.get_values(mykey)
-
-       if dbkeys and new_vals:
-               for x in dbkeys:
-                       if x not in new_vals.keys():
-                               print "---",x
-               for x in new_vals.keys():
-                       if x not in dbkeys:
-                               print "+++",x
-       else:
-               print "Mismatched:",dbkeys,new_vals
-       
-       d.del_key(mykey)
-       
-       print "Should be None:",d.get_values(mykey)
-
-       d.clear()
-
-       d.sync
-       d.close
-       
-       del d
-       
-       print "Done."
diff --git a/pym/portage_db_test.py b/pym/portage_db_test.py
deleted file mode 100644 (file)
index 61857fe..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-#!/usr/bin/python -O
-# Copyright 2004 Gentoo Foundation
-# Distributed under the terms of the GNU General Public License v2
-# $Id: /var/cvsroot/gentoo-src/portage/pym/Attic/portage_db_test.py,v 1.3.2.1 2005/01/16 02:35:33 carpaski Exp $
-
-
-import portage
-import portage_db_template
-import portage_db_anydbm
-import portage_db_flat
-import portage_db_cpickle
-
-import os
-
-uid = os.getuid()
-gid = os.getgid()
-
-portage_db_template.test_database(portage_db_flat.database,"/var/cache/edb/dep",   "sys-apps",portage.auxdbkeys,uid,gid)
-portage_db_template.test_database(portage_db_cpickle.database,"/var/cache/edb/dep","sys-apps",portage.auxdbkeys,uid,gid)
-portage_db_template.test_database(portage_db_anydbm.database,"/var/cache/edb/dep", "sys-apps",portage.auxdbkeys,uid,gid)
-