summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pym/portage/__init__.py92
-rw-r--r--pym/portage/_deprecated.py5
-rw-r--r--pym/portage/util/mtimedb.py77
3 files changed, 92 insertions, 82 deletions
diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py
index 595580fd0..5f1b05e76 100644
--- a/pym/portage/__init__.py
+++ b/pym/portage/__init__.py
@@ -131,12 +131,14 @@ try:
'portage.util.ExtractKernelVersion:ExtractKernelVersion',
'portage.util.listdir:cacheddir,listdir',
'portage.util.movefile:movefile',
+ 'portage.util.mtimedb:MtimeDB',
'portage.versions',
'portage.versions:best,catpkgsplit,catsplit,cpv_getkey,' + \
'cpv_getkey@getCPFromCPV,endversion_keys,' + \
'suffix_value@endversion,pkgcmp,pkgsplit,vercmp,ververify',
'portage.xpak',
- 'portage._deprecated:dep_virtual,digestParseFile,getvirtuals,pkgmerge',
+ 'portage._deprecated:commit_mtimedb,dep_virtual,' + \
+ 'digestParseFile,getvirtuals,pkgmerge',
)
import portage.const
@@ -535,92 +537,18 @@ def deprecated_profile_check(settings=None):
writemsg("\n\n", noiselevel=-1)
return True
-def commit_mtimedb(mydict=None, filename=None):
- if mydict is None:
- global mtimedb
- if "mtimedb" not in globals() or mtimedb is None:
- return
- mtimedb.commit()
- return
- if filename is None:
- global mtimedbfile
- filename = mtimedbfile
- mydict["version"] = VERSION
- d = {} # for full backward compat, pickle it as a plain dict object.
- d.update(mydict)
- try:
- f = atomic_ofstream(filename, mode='wb')
- pickle.dump(d, f, protocol=2)
- f.close()
- portage.util.apply_secpass_permissions(filename,
- uid=uid, gid=portage_gid, mode=0o644)
- except (IOError, OSError) as e:
- pass
-
def portageexit():
- global uid,portage_gid,portdb,db
- if secpass and os.environ.get("SANDBOX_ON") != "1":
+ if secpass > 1 and os.environ.get("SANDBOX_ON") != "1":
close_portdbapi_caches()
- commit_mtimedb()
+ try:
+ mtimedb
+ except NameError:
+ pass
+ else:
+ mtimedb.commit()
atexit_register(portageexit)
-class MtimeDB(dict):
- def __init__(self, filename):
- dict.__init__(self)
- self.filename = filename
- self._load(filename)
-
- def _load(self, filename):
- try:
- f = open(_unicode_encode(filename), 'rb')
- mypickle = pickle.Unpickler(f)
- try:
- mypickle.find_global = None
- except AttributeError:
- # TODO: If py3k, override Unpickler.find_class().
- pass
- d = mypickle.load()
- f.close()
- del f
- except (IOError, OSError, EOFError, ValueError, pickle.UnpicklingError) as e:
- if isinstance(e, pickle.UnpicklingError):
- writemsg(_("!!! Error loading '%s': %s\n") % \
- (filename, str(e)), noiselevel=-1)
- del e
- d = {}
-
- if "old" in d:
- d["updates"] = d["old"]
- del d["old"]
- if "cur" in d:
- del d["cur"]
-
- d.setdefault("starttime", 0)
- d.setdefault("version", "")
- for k in ("info", "ldpath", "updates"):
- d.setdefault(k, {})
-
- mtimedbkeys = set(("info", "ldpath", "resume", "resume_backup",
- "starttime", "updates", "version"))
-
- for k in list(d):
- if k not in mtimedbkeys:
- writemsg(_("Deleting invalid mtimedb key: %s\n") % str(k))
- del d[k]
- self.update(d)
- self._clean_data = copy.deepcopy(d)
-
- def commit(self):
- if not self.filename:
- return
- d = {}
- d.update(self)
- # Only commit if the internal state has changed.
- if d != self._clean_data:
- commit_mtimedb(mydict=d, filename=self.filename)
- self._clean_data = copy.deepcopy(d)
-
def create_trees(config_root=None, target_root=None, trees=None):
if trees is None:
trees = {}
diff --git a/pym/portage/_deprecated.py b/pym/portage/_deprecated.py
index a9ed0622b..f151cd6d0 100644
--- a/pym/portage/_deprecated.py
+++ b/pym/portage/_deprecated.py
@@ -16,6 +16,11 @@ from portage.localization import _
from portage.manifest import Manifest
from portage.util import writemsg, writemsg_stdout
+def commit_mtimedb(mydict=None, filename=None):
+ warnings.warn("portage.commit_mtimedb() is deprecated, " + \
+ "use portage.mtimedb.commit() instead",
+ DeprecationWarning, stacklevel=2)
+
def digestParseFile(myfilename, mysettings=None):
"""(filename) -- Parses a given file for entries matching:
<checksumkey> <checksum_hex_string> <filename> <filesize>
diff --git a/pym/portage/util/mtimedb.py b/pym/portage/util/mtimedb.py
new file mode 100644
index 000000000..cbeb1bb8c
--- /dev/null
+++ b/pym/portage/util/mtimedb.py
@@ -0,0 +1,77 @@
+# Copyright 2010 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id$
+
+__all__ = ['MtimeDB']
+
+import copy
+
+from portage import pickle, VERSION, _unicode_encode
+from portage.data import portage_gid, uid
+from portage.localization import _
+from portage.util import apply_secpass_permissions, atomic_ofstream, writemsg
+
+class MtimeDB(dict):
+ def __init__(self, filename):
+ dict.__init__(self)
+ self.filename = filename
+ self._load(filename)
+
+ def _load(self, filename):
+ try:
+ f = open(_unicode_encode(filename), 'rb')
+ mypickle = pickle.Unpickler(f)
+ try:
+ mypickle.find_global = None
+ except AttributeError:
+ # TODO: If py3k, override Unpickler.find_class().
+ pass
+ d = mypickle.load()
+ f.close()
+ del f
+ except (IOError, OSError, EOFError, ValueError, pickle.UnpicklingError) as e:
+ if isinstance(e, pickle.UnpicklingError):
+ writemsg(_("!!! Error loading '%s': %s\n") % \
+ (filename, str(e)), noiselevel=-1)
+ del e
+ d = {}
+
+ if "old" in d:
+ d["updates"] = d["old"]
+ del d["old"]
+ if "cur" in d:
+ del d["cur"]
+
+ d.setdefault("starttime", 0)
+ d.setdefault("version", "")
+ for k in ("info", "ldpath", "updates"):
+ d.setdefault(k, {})
+
+ mtimedbkeys = set(("info", "ldpath", "resume", "resume_backup",
+ "starttime", "updates", "version"))
+
+ for k in list(d):
+ if k not in mtimedbkeys:
+ writemsg(_("Deleting invalid mtimedb key: %s\n") % str(k))
+ del d[k]
+ self.update(d)
+ self._clean_data = copy.deepcopy(d)
+
+ def commit(self):
+ if not self.filename:
+ return
+ d = {}
+ d.update(self)
+ # Only commit if the internal state has changed.
+ if d != self._clean_data:
+ d["version"] = VERSION
+ try:
+ f = atomic_ofstream(self.filename, mode='wb')
+ except EnvironmentError:
+ pass
+ else:
+ pickle.dump(d, f, protocol=2)
+ f.close()
+ apply_secpass_permissions(self.filename,
+ uid=uid, gid=portage_gid, mode=0o644)
+ self._clean_data = copy.deepcopy(d)