1 from portage.cache import fs_template
2 from portage.cache import cache_errors
5 # store the current key order *here*.
6 class database(fs_template.FsBased):
10 # do not screw with this ordering. _eclasses_ needs to be last
11 auxdbkey_order=('DEPEND', 'RDEPEND', 'SLOT', 'SRC_URI',
12 'RESTRICT', 'HOMEPAGE', 'LICENSE', 'DESCRIPTION',
13 'KEYWORDS', 'IUSE', 'CDEPEND',
14 'PDEPEND', 'PROVIDE', 'EAPI', 'PROPERTIES')
16 def __init__(self, label, auxdbkeys, **config):
17 super(database,self).__init__(label, auxdbkeys, **config)
18 self._base = os.path.join(self._base,
19 self.label.lstrip(os.path.sep).rstrip(os.path.sep))
21 if len(self._known_keys) > len(self.auxdbkey_order) + 2:
22 raise Exception("less ordered keys then auxdbkeys")
23 if not os.path.exists(self._base):
27 def _getitem(self, cpv):
30 myf = open(os.path.join(self._base, cpv),"r")
31 for k,v in zip(self.auxdbkey_order, myf):
33 except (OSError, IOError),e:
34 if errno.ENOENT == e.errno:
36 raise cache_errors.CacheCorruption(cpv, e)
39 d["_mtime_"] = long(os.fstat(myf.fileno()).st_mtime)
42 raise cache_errors.CacheCorruption(cpv, e)
47 def _setitem(self, cpv, values):
49 fp=os.path.join(self._base,cpv[:s],".update.%i.%s" % (os.getpid(), cpv[s+1:]))
50 try: myf=open(fp, "w")
51 except (OSError, IOError), e:
52 if errno.ENOENT == e.errno:
54 self._ensure_dirs(cpv)
56 except (OSError, IOError),e:
57 raise cache_errors.CacheCorruption(cpv, e)
59 raise cache_errors.CacheCorruption(cpv, e)
62 for x in self.auxdbkey_order:
63 myf.write(values.get(x,"")+"\n")
66 self._ensure_access(fp, mtime=values["_mtime_"])
67 #update written. now we move it.
68 new_fp = os.path.join(self._base,cpv)
69 try: os.rename(fp, new_fp)
70 except (OSError, IOError), e:
72 raise cache_errors.CacheCorruption(cpv, e)
75 def _delitem(self, cpv):
77 os.remove(os.path.join(self._base,cpv))
79 if errno.ENOENT == e.errno:
82 raise cache_errors.CacheCorruption(cpv, e)
85 def __contains__(self, cpv):
86 return os.path.exists(os.path.join(self._base, cpv))
90 """generator for walking the dir struct"""
92 len_base = len(self._base)
94 for l in os.listdir(dirs[0]):
95 if l.endswith(".cpickle"):
97 p = os.path.join(dirs[0],l)
99 if stat.S_ISDIR(st.st_mode):
106 def commit(self): pass