summaryrefslogtreecommitdiffstats
path: root/pym/portage_db_flat.py
diff options
context:
space:
mode:
authorBrian Harring <ferringb@gentoo.org>2005-09-24 17:54:05 +0000
committerBrian Harring <ferringb@gentoo.org>2005-09-24 17:54:05 +0000
commit430ce6fed697eea6c68b13ecdcad14bc6fdac01d (patch)
tree7e195bcb2c0715c5d663faecf3e84007f7e69ec1 /pym/portage_db_flat.py
parentf913d92453517074c89a4cd59004d72bee5ba7d8 (diff)
downloadportage-430ce6fed697eea6c68b13ecdcad14bc6fdac01d.tar.gz
portage-430ce6fed697eea6c68b13ecdcad14bc6fdac01d.tar.bz2
portage-430ce6fed697eea6c68b13ecdcad14bc6fdac01d.zip
EAPI awareness, and flat_hash/flat_list autodetection for rysnc cache.
svn path=/main/branches/2.0/; revision=2022
Diffstat (limited to 'pym/portage_db_flat.py')
-rw-r--r--pym/portage_db_flat.py59
1 files changed, 35 insertions, 24 deletions
diff --git a/pym/portage_db_flat.py b/pym/portage_db_flat.py
index ddec4f591..4fc220bb9 100644
--- a/pym/portage_db_flat.py
+++ b/pym/portage_db_flat.py
@@ -9,6 +9,10 @@ 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
@@ -42,39 +46,39 @@ class database(portage_db_template.database):
mykeys += [x]
return mykeys
- def get_values(self,key):
+ 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"
- try:
- # give buffering a hint of the pretty much maximal cache size we deal with
- myf = open(self.fullpath+key, "r", 8192)
- except OSError, oe:
- # either the file didn't exist, or it was removed under our feet.
- return None
-
+ 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)
- # nuke the newlines right off the batt.
- data = myf.read().splitlines()
- mdict = {}
-
# rely on exceptions to note differing line counts.
try:
- for x in range(0, len(self.dbkeys)):
- mdict[self.dbkeys[x]] = data[x]
-
- # do this now, rather then earlier- possible that earlier it might have been wasted
- # if key count mismatched
- mdict["_mtime_"] = os.fstat(myf.fileno()).st_mtime
+ for x in range(magic_line_count):
+ mydict[self.dbkeys[x]] = data[x]
except IndexError:
- myf.close()
raise ValueError, "Key count mistmatch"
- myf.close()
- return mdict
+ return mydict
- def set_values(self,key,val):
+ 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:
@@ -86,12 +90,19 @@ class database(portage_db_template.database):
update_fp = self.fullpath + ".update." + str(os.getpid()) + "." + key
myf = open(update_fp,"w")
- myf.writelines( [ val[x] +"\n" for x in self.dbkeys] )
+ 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(val["_mtime_"])))
+ os.utime(update_fp, (-1,long(mtime)))
os.rename(update_fp, self.fullpath+key)
def del_key(self,key):