/[gentoo-src]/portage/pym/portage_db_anydbm.py
Gentoo

Contents of /portage/pym/portage_db_anydbm.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.13 - (show annotations) (download) (as text)
Wed Mar 9 09:10:18 2005 UTC (9 years, 6 months ago) by ferringb
Branch: MAIN
CVS Tags: HEAD
Changes since 1.12: +2 -2 lines
File MIME type: text/x-python
FILE REMOVED
banish the old cache classes to the attic.

1 # Copyright 2004 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-src/portage/pym/portage_db_anydbm.py,v 1.12 2005/02/26 06:35:20 jstubbs Exp $
4 cvs_id_string="$Id: portage_db_anydbm.py,v 1.12 2005/02/26 06:35:20 jstubbs Exp $"[5:-2]
5
6 import anydbm,cPickle,types,os
7
8 import portage_db_template
9
10 class database(portage_db_template.database):
11 def module_init(self):
12 prevmask=os.umask(0)
13 if not os.path.exists(self.path):
14 current_path="/"
15 for mydir in self.path.split("/"):
16 current_path += "/"+mydir
17 if not os.path.exists(current_path):
18 os.mkdir(current_path)
19
20 self.filename = self.path + "/" + self.category + ".anydbm"
21
22 try:
23 # open it read/write
24 self.db = anydbm.open(self.filename, "c", 0664)
25 except SystemExit, e:
26 raise
27 except:
28 # Create a new db... DB type not supported anymore?
29 self.db = anydbm.open(self.filename, "n", 0664)
30
31 os.umask(prevmask)
32
33 def has_key(self,key):
34 self.check_key(key)
35 if self.db.has_key(key):
36 return 1
37 return 0
38
39 def keys(self):
40 return self.db.keys()
41
42 def get_values(self,key):
43 self.check_key(key)
44 if self.db.has_key(key):
45 myval = cPickle.loads(self.db[key])
46 return myval
47 return None
48
49 def set_values(self,key,val):
50 self.check_key(key)
51 self.db[key] = cPickle.dumps(val,cPickle.HIGHEST_PROTOCOL)
52
53 def del_key(self,key):
54 if self.has_key(key):
55 del self.db[key]
56 return True
57 return False
58
59 def sync(self):
60 self.db.sync()
61
62 def close(self):
63 self.db.close()
64

  ViewVC Help
Powered by ViewVC 1.1.20