aboutsummaryrefslogtreecommitdiff
path: root/pym
diff options
context:
space:
mode:
authorBrian Harring <ferringb@gentoo.org>2005-03-09 09:10:18 +0000
committerBrian Harring <ferringb@gentoo.org>2005-03-09 09:10:18 +0000
commit3425fd7d1059ee3899674449c042fe1711b1cd2c (patch)
tree2d33f135035e17938501c56d4a023cc690449287 /pym
parentbye bye 02775, hello 0775 (diff)
downloadportage-cvs-3425fd7d1059ee3899674449c042fe1711b1cd2c.tar.gz
portage-cvs-3425fd7d1059ee3899674449c042fe1711b1cd2c.tar.bz2
portage-cvs-3425fd7d1059ee3899674449c042fe1711b1cd2c.zip
banish the old cache classes to the attic.
Diffstat (limited to 'pym')
-rw-r--r--pym/portage_db_anydbm.py64
-rw-r--r--pym/portage_db_cpickle.py79
-rw-r--r--pym/portage_db_flat.py133
-rw-r--r--pym/portage_db_template.py183
-rw-r--r--pym/portage_db_test.py21
5 files changed, 0 insertions, 480 deletions
diff --git a/pym/portage_db_anydbm.py b/pym/portage_db_anydbm.py
deleted file mode 100644
index 245baec..0000000
--- a/pym/portage_db_anydbm.py
+++ /dev/null
@@ -1,64 +0,0 @@
-# Copyright 2004 Gentoo Foundation
-# Distributed under the terms of the GNU General Public License v2
-# $Header: /local/data/ulm/cvs/history/var/cvsroot/gentoo-src/portage/pym/Attic/portage_db_anydbm.py,v 1.12 2005/02/26 06:35:20 jstubbs Exp $
-cvs_id_string="$Id: portage_db_anydbm.py,v 1.12 2005/02/26 06:35:20 jstubbs Exp $"[5:-2]
-
-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
index 91bdf55..0000000
--- a/pym/portage_db_cpickle.py
+++ /dev/null
@@ -1,79 +0,0 @@
-# Copyright 2004 Gentoo Foundation
-# Distributed under the terms of the GNU General Public License v2
-# $Header: /local/data/ulm/cvs/history/var/cvsroot/gentoo-src/portage/pym/Attic/portage_db_cpickle.py,v 1.10 2005/02/26 06:35:20 jstubbs Exp $
-cvs_id_string="$Id: portage_db_cpickle.py,v 1.10 2005/02/26 06:35:20 jstubbs Exp $"[5:-2]
-
-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"), cPickle.HIGHEST_PROTOCOL)
- 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
index d74cfd6..0000000
--- a/pym/portage_db_flat.py
+++ /dev/null
@@ -1,133 +0,0 @@
-# Copyright 2004 Gentoo Foundation
-# Distributed under the terms of the GNU General Public License v2
-# $Header: /local/data/ulm/cvs/history/var/cvsroot/gentoo-src/portage/pym/Attic/portage_db_flat.py,v 1.18 2005/02/26 06:35:20 jstubbs Exp $
-cvs_id_string="$Id: portage_db_flat.py,v 1.18 2005/02/26 06:35:20 jstubbs Exp $"[5:-2]
-
-import types
-import os
-import stat
-
-import portage_db_template
-
-class database(portage_db_template.database):
- def module_init(self):
- self.lastkey = None # Cache
- self.lastval = None # Cache
-
- self.fullpath = os.path.join(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
-
- self.flushCache()
-
- def __addMcache(self,key,val):
- del self.__mcache_list[2]
- self.__mcache_list.insert(0,val)
- del self.__mcache_keys[2]
- self.__mcache_keys.insert(0,key)
-
- def __delMache(self,key):
- i = self.__mcache_list.index(key)
- self.__mcache_list[i] = None
- self.__mcache_keys[i] = None
-
- def flushCache(self):
- portage_db_template.database.flushCache(self)
- self.__mcache_list = [None,None,None]
- self.__mcache_keys = [None,None,None]
-
- def has_key(self,key):
- if os.path.exists(os.path.join(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.beginswith(".update."):
- mykeys += [x]
- return mykeys
-
- def get_timestamp(self,key,locking=True):
- import traceback
- traceback.print_stack()
- if key in self.__mcache_keys:
- return self.__mcache_list[self.__mcache_keys.index(key)]
- lock=portage_locks.lockfile(os.path.join(self.fullpath,key),wantnewlockfile=1)
- try: x=os.stat(os.path.join(self.fullpath,key))[stat.ST_MTIME]
- except OSError: x=None
- self.__addMcache(key,x)
- portage_locks.unlockfile(lock)
- return x
-
- def get_values(self,key):
- if not key:
- raise KeyError, "key is not set to a valid value"
-
-# mylock = portage_locks.lockfile(self.fullpath+key, wantnewlockfile=1)
-# if self.has_key(key):
- try:
-# self.get_timestamp(key,locking=False)
- myf = open(os.path.join(self.fullpath,key),"r")
- mtime = os.fstat(myf.fileno()).st_mtime
- myl = myf.readlines()
- myf.close()
-
- dict = {"_mtime_":mtime}
-
- if len(myl) != len(self.dbkeys):
- raise ValueError, "Key count mismatch"
- for x in range(0,len(myl)):
- if myl[x] and myl[x][-1] == "\n":
- dict[self.dbkeys[x]] = myl[x][:-1]
- else:
- dict[self.dbkeys[x]] = myl[x]
-
- return dict
- except OSError:
- return None
-
- def set_values(self,key,val):
- 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)
- update_fp = os.path.join(self.fullpath, ".update.%i.%s" % (os.getpid(), key))
- myf = open(update_fp, "w")
- myf.writelines( [ val[x] +"\n" for x in self.dbkeys] )
- myf.close()
-
- os.chown(update_fp, self.uid, self.gid)
- os.chmod(update_fp, 0664)
- os.utime(update_fp, (-1,long(val["_mtime_"])))
- os.rename(update_fp, os.path.join(self.fullpath,key))
-
- def del_key(self,key):
- self.lastkey = None
- self.lastval = None
- try:
- os.unlink(os.path.join(self.fullpath,key))
- except OSError:
- # either someone beat us to it, or the key doesn't exist.
- # either way, it's gone, so we return false
- return False
- return True
-
- def sync(self):
- return
-
- def close(self):
- return
-
diff --git a/pym/portage_db_template.py b/pym/portage_db_template.py
deleted file mode 100644
index ebb4d82..0000000
--- a/pym/portage_db_template.py
+++ /dev/null
@@ -1,183 +0,0 @@
-# Copyright 2004 Gentoo Foundation
-# Distributed under the terms of the GNU General Public License v2
-# $Header: /local/data/ulm/cvs/history/var/cvsroot/gentoo-src/portage/pym/Attic/portage_db_template.py,v 1.13 2005/02/26 06:35:20 jstubbs Exp $
-cvs_id_string="$Id: portage_db_template.py,v 1.13 2005/02/26 06:35:20 jstubbs Exp $"[5:-2]
-
-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 get_timestamp(self,key):
- if key in self.__cacheKeyArray:
- return self.__cacheArray[self.__cacheKeyArray.index(key)]["_mtime_"]
- try:
- d = self.__getitem__(key)
- return d["_mtime_"]
- except KeyError:
- return 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
index e2a08a8..0000000
--- a/pym/portage_db_test.py
+++ /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
-# $Header: /local/data/ulm/cvs/history/var/cvsroot/gentoo-src/portage/pym/Attic/portage_db_test.py,v 1.4 2005/02/26 06:35:20 jstubbs Exp $
-cvs_id_string="$Id: portage_db_test.py,v 1.4 2005/02/26 06:35:20 jstubbs Exp $"[5:-2]
-
-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)
-