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

Contents of /portage/pym/portage_db_cpickle.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.11 - (show annotations) (download) (as text)
Wed Mar 9 09:10:18 2005 UTC (9 years, 1 month ago) by ferringb
Branch: MAIN
CVS Tags: HEAD
Changes since 1.10: +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_cpickle.py,v 1.10 2005/02/26 06:35:20 jstubbs Exp $
4 cvs_id_string="$Id: portage_db_cpickle.py,v 1.10 2005/02/26 06:35:20 jstubbs Exp $"[5:-2]
5
6 import anydbm,cPickle,types
7 from os import chown,access,R_OK,unlink
8 import os
9
10 import portage_db_template
11
12 class database(portage_db_template.database):
13 def module_init(self):
14 self.modified = False
15
16 prevmask=os.umask(0)
17 if not os.path.exists(self.path):
18 os.makedirs(self.path, 02775)
19
20 self.filename = self.path + "/" + self.category + ".cpickle"
21
22 if access(self.filename, R_OK):
23 try:
24 mypickle=cPickle.Unpickler(open(self.filename,"r"))
25 mypickle.find_global=None
26 self.db = mypickle.load()
27 except SystemExit, e:
28 raise
29 except:
30 self.db = {}
31 else:
32 self.db = {}
33
34 os.umask(prevmask)
35
36 def has_key(self,key):
37 self.check_key(key)
38 if self.db.has_key(key):
39 return 1
40 return 0
41
42 def keys(self):
43 return self.db.keys()
44
45 def get_values(self,key):
46 self.check_key(key)
47 if self.db.has_key(key):
48 return self.db[key]
49 return None
50
51 def set_values(self,key,val):
52 self.modified = True
53 self.check_key(key)
54 self.db[key] = val
55
56 def del_key(self,key):
57 if self.has_key(key):
58 del self.db[key]
59 self.modified = True
60 return True
61 return False
62
63 def sync(self):
64 if self.modified:
65 try:
66 if os.path.exists(self.filename):
67 unlink(self.filename)
68 cPickle.dump(self.db, open(self.filename,"w"), cPickle.HIGHEST_PROTOCOL)
69 os.chown(self.filename,self.uid,self.gid)
70 os.chmod(self.filename, 0664)
71 except SystemExit, e:
72 raise
73 except:
74 pass
75
76 def close(self):
77 self.sync()
78 self.db = None;
79

  ViewVC Help
Powered by ViewVC 1.1.20