aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Harring <ferringb@gentoo.org>2005-08-03 00:17:55 +0000
committerBrian Harring <ferringb@gentoo.org>2005-08-03 00:17:55 +0000
commitdc80eb6b5cabcf1a5808b812278d515090246a61 (patch)
tree938e6527c447ce6c7b2699f1b182713b37205fa2
parentrewrite prepallman to use find rather than hardcoded paths (diff)
downloadportage-cvs-dc80eb6b5cabcf1a5808b812278d515090246a61.tar.gz
portage-cvs-dc80eb6b5cabcf1a5808b812278d515090246a61.tar.bz2
portage-cvs-dc80eb6b5cabcf1a5808b812278d515090246a61.zip
bit 'o' cleanup. added cleanse_keys class attribute, serves as an indication of whether or not the template layer needs to nuke empty
metadata keys (empty being defined as bool(val) == False)
-rw-r--r--portage/cache/anydbm.py16
-rw-r--r--portage/cache/cache_errors.py3
-rw-r--r--portage/cache/flat_list.py4
-rw-r--r--portage/cache/metadata.py22
-rw-r--r--portage/cache/sql_template.py5
-rw-r--r--portage/cache/template.py21
6 files changed, 47 insertions, 24 deletions
diff --git a/portage/cache/anydbm.py b/portage/cache/anydbm.py
index ab93c7b..5fe2149 100644
--- a/portage/cache/anydbm.py
+++ b/portage/cache/anydbm.py
@@ -1,10 +1,14 @@
# Copyright: 2005 Gentoo Foundation
# Author(s): Brian Harring (ferringb@gentoo.org)
# License: GPL2
-# $Header: /local/data/ulm/cvs/history/var/cvsroot/gentoo-src/portage/portage/cache/anydbm.py,v 1.3 2005/07/28 18:51:41 ferringb Exp $
+# $Header: /local/data/ulm/cvs/history/var/cvsroot/gentoo-src/portage/portage/cache/anydbm.py,v 1.4 2005/08/03 00:17:55 ferringb Exp $
anydbm_module = __import__("anydbm")
-import cPickle, os
+try:
+ import cPickle as pickle
+except ImportError:
+ import pickl
+import os
import fs_template
import cache_errors
@@ -12,6 +16,7 @@ import cache_errors
class database(fs_template.FsBased):
autocommits = True
+ cleanse_keys = True
def __init__(self, *args, **config):
super(database,self).__init__(*args, **config)
@@ -46,11 +51,11 @@ class database(fs_template.FsBased):
def __getitem__(self, cpv):
# we override getitem because it's just a cpickling of the data handed in.
- return cPickle.loads(self.__db[cpv])
+ return pickle.loads(self.__db[cpv])
def _setitem(self, cpv, values):
- self.__db[cpv] = cPickle.dumps(values,cPickle.HIGHEST_PROTOCOL)
+ self.__db[cpv] = pickle.dumps(values,pickle.HIGHEST_PROTOCOL)
def _delitem(self, cpv):
del self.__db[cpv]
@@ -64,9 +69,6 @@ class database(fs_template.FsBased):
return cpv in self.__db
- def commit(self): pass
-
-
def __del__(self):
if "__db" in self.__dict__ and self.__db != None:
self.__db.sync()
diff --git a/portage/cache/cache_errors.py b/portage/cache/cache_errors.py
index 4f8976a..87f1bb2 100644
--- a/portage/cache/cache_errors.py
+++ b/portage/cache/cache_errors.py
@@ -1,7 +1,7 @@
# Copyright: 2005 Gentoo Foundation
# Author(s): Brian Harring (ferringb@gentoo.org)
# License: GPL2
-# $Header: /local/data/ulm/cvs/history/var/cvsroot/gentoo-src/portage/portage/cache/cache_errors.py,v 1.2 2005/07/13 05:51:35 ferringb Exp $
+# $Header: /local/data/ulm/cvs/history/var/cvsroot/gentoo-src/portage/portage/cache/cache_errors.py,v 1.3 2005/08/03 00:17:55 ferringb Exp $
class CacheError(Exception): pass
@@ -15,6 +15,7 @@ class InitializationError(CacheError):
class CacheCorruption(CacheError):
def __init__(self, key, ex):
+ import traceback;traceback.print_stack()
self.key, self.ex = key, ex
def __str__(self):
return "%s is corrupt: %s" % (self.key, str(self.ex))
diff --git a/portage/cache/flat_list.py b/portage/cache/flat_list.py
index d9b23a8..6d9f483 100644
--- a/portage/cache/flat_list.py
+++ b/portage/cache/flat_list.py
@@ -1,7 +1,7 @@
# Copyright: 2005 Gentoo Foundation
# Author(s): Brian Harring (ferringb@gentoo.org)
# License: GPL2
-# $Header: /local/data/ulm/cvs/history/var/cvsroot/gentoo-src/portage/portage/cache/flat_list.py,v 1.2 2005/07/13 05:51:35 ferringb Exp $
+# $Header: /local/data/ulm/cvs/history/var/cvsroot/gentoo-src/portage/portage/cache/flat_list.py,v 1.3 2005/08/03 00:17:55 ferringb Exp $
import fs_template
import cache_errors
@@ -110,5 +110,3 @@ class database(fs_template.FsBased):
yield p[len_base+1:]
dirs.pop(0)
-
- def commit(self): pass
diff --git a/portage/cache/metadata.py b/portage/cache/metadata.py
index d4fac21..979e740 100644
--- a/portage/cache/metadata.py
+++ b/portage/cache/metadata.py
@@ -1,13 +1,13 @@
# Copyright: 2005 Gentoo Foundation
# Author(s): Brian Harring (ferringb@gentoo.org)
# License: GPL2
-# $Header: /local/data/ulm/cvs/history/var/cvsroot/gentoo-src/portage/portage/cache/metadata.py,v 1.3 2005/07/28 18:51:41 ferringb Exp $
+# $Header: /local/data/ulm/cvs/history/var/cvsroot/gentoo-src/portage/portage/cache/metadata.py,v 1.4 2005/08/03 00:17:55 ferringb Exp $
import os, stat
import fs_template
import cache_errors
from portage.ebuild import eclass_cache
-from template import reconstruct_eclasses
+from template import reconstruct_eclasses, serialize_eclasses
# store the current key order *here*.
class database(fs_template.FsBased):
@@ -17,7 +17,15 @@ class database(fs_template.FsBased):
'KEYWORDS', 'INHERITED', 'IUSE', 'CDEPEND',
'PDEPEND', 'PROVIDE')
+ autocommits = True
+
def __init__(self, *args, **config):
+ if "unused_padding" in config:
+ self.unused_padding = int(config["unused_padding"])
+ del config["unused_padding"]
+ else:
+ self.unused_padding = 0
+
super(database,self).__init__(*args, **config)
location = self.location
self.location = os.path.join(self.location, "metadata/cache")
@@ -27,7 +35,6 @@ class database(fs_template.FsBased):
raise Exception("less ordered keys then auxdbkeys")
if not os.path.exists(self.location):
self._ensure_dirs()
-
self.ec = eclass_cache.cache(location)
def __getitem__(self, cpv):
@@ -79,11 +86,12 @@ class database(fs_template.FsBased):
# hack. proper solution is to make this a __setitem__ override, since template.__setitem__
# serializes _eclasses_, then we reconstruct it.
- if "_eclasses_" in d:
- d["INHERITED"] = serialize_eclasses(d["_eclasses_"]).keys()
- del d["_eclasses_"]
+ if "_eclasses_" in values:
+ values["INHERITED"] = ' '.join(reconstruct_eclasses(cpv, values["_eclasses_"]).keys())
+ del values["_eclasses_"]
- myf.writelines( [ values.get(x,"")+"\n" for x in self.auxdbkey_order] )
+ myf.writelines(values.get(x,"")+"\n" for x in self.auxdbkey_order)
+ myf.write("\n"*self.unused_padding)
myf.close()
self._ensure_access(fp, mtime=values["_mtime_"])
#update written. now we move it.
diff --git a/portage/cache/sql_template.py b/portage/cache/sql_template.py
index 4c222a9..3c1417a 100644
--- a/portage/cache/sql_template.py
+++ b/portage/cache/sql_template.py
@@ -1,7 +1,7 @@
# Copyright: 2005 Gentoo Foundation
# Author(s): Brian Harring (ferringb@gentoo.org)
# License: GPL2
-# $Header: /local/data/ulm/cvs/history/var/cvsroot/gentoo-src/portage/portage/cache/sql_template.py,v 1.3 2005/07/28 18:51:41 ferringb Exp $
+# $Header: /local/data/ulm/cvs/history/var/cvsroot/gentoo-src/portage/portage/cache/sql_template.py,v 1.4 2005/08/03 00:17:55 ferringb Exp $
import template, cache_errors
from template import reconstruct_eclasses
@@ -36,6 +36,7 @@ class SQLDatabase(template.database):
_dbClass = None
autocommits = False
+# cleanse_keys = True
# boolean indicating if the derived RDBMS class supports replace syntax
_supports_replace = False
@@ -149,7 +150,7 @@ class SQLDatabase(template.database):
# so we store only what's handed to us and is a known key
db_values = []
for key in self._known_keys:
- if values.has_key(key):
+ if values.has_key(key) and values[key] != '':
db_values.append({"key":key, "value":values[key]})
if len(db_values) > 0:
diff --git a/portage/cache/template.py b/portage/cache/template.py
index f27ed03..f988446 100644
--- a/portage/cache/template.py
+++ b/portage/cache/template.py
@@ -1,7 +1,7 @@
# Copyright: 2005 Gentoo Foundation
# Author(s): Brian Harring (ferringb@gentoo.org)
# License: GPL2
-# $Header: /local/data/ulm/cvs/history/var/cvsroot/gentoo-src/portage/portage/cache/template.py,v 1.4 2005/07/28 18:51:41 ferringb Exp $
+# $Header: /local/data/ulm/cvs/history/var/cvsroot/gentoo-src/portage/portage/cache/template.py,v 1.5 2005/08/03 00:17:55 ferringb Exp $
import cache_errors, copy
@@ -12,6 +12,7 @@ class database(object):
complete_eclass_entries_ = True
autocommits = False
+ cleanse_keys = False
def __init__(self, location, label, auxdbkeys, readonly=False):
""" initialize the derived class; specifically, store label/keys"""
@@ -46,9 +47,19 @@ class database(object):
This shouldn't be overriden in derived classes since it handles the readonly checks"""
if self.readonly:
raise cache_errors.ReadOnlyRestriction()
- d=copy.copy(values)
- if "_eclasses_" in d:
+ if self.cleanse_keys:
+ d=copy.copy(values)
+ for k in d.keys():
+ if d[k] == '':
+ del d[k]
+ if "_eclasses_" in values:
+ d = values.copy()
+ d["_eclasses_"] = serialize_eclasses(d["_eclasses_"])
+ elif "_eclasses_" in values:
+ d = values.copy()
d["_eclasses_"] = serialize_eclasses(d["_eclasses_"])
+ else:
+ d = values
self._setitem(cpv, d)
if not self.autocommits:
self.updates += 1
@@ -93,7 +104,7 @@ class database(object):
def iteritems(self):
for x in self.iterkeys():
- yield x, self[x]
+ yield (x, self[x])
def items(self):
return list(self.iteritems())
@@ -104,6 +115,8 @@ class database(object):
self.commit()
def commit(self):
+ if self.autocommits:
+ pass
raise NotImplementedError
def get_matches(self, match_dict):