When reading and writing the Packages index file, translate metadata keys
authorZac Medico <zmedico@gentoo.org>
Mon, 7 Apr 2008 23:10:30 +0000 (23:10 -0000)
committerZac Medico <zmedico@gentoo.org>
Mon, 7 Apr 2008 23:10:30 +0000 (23:10 -0000)
on the fly. Current translations:
DESC <-> DESCRIPTION
REPO <-> repository

svn path=/main/trunk/; revision=9742

pym/portage/dbapi/bintree.py
pym/portage/getbinpkg.py

index d2b499ba102e17fd83ddc1905bc397568dff938b..8b2ffbe0fd5ee15957c720225b04e8fe4560eab0 100644 (file)
@@ -174,6 +174,10 @@ class binarytree(object):
                        self._pkgindex_default_header_data = {
                                "repository":""
                        }
+                       self._pkgindex_translated_keys = (
+                               ("DESCRIPTION"   ,   "DESC"),
+                               ("repository"    ,   "REPO"),
+                       )
 
        def move_ent(self, mylist):
                if not self.populated:
@@ -811,7 +815,8 @@ class binarytree(object):
                return portage.getbinpkg.PackageIndex(
                        default_header_data=self._pkgindex_default_header_data,
                        default_pkg_data=self._pkgindex_default_pkg_data,
-                       inherited_keys=self._pkgindex_inherited_keys)
+                       inherited_keys=self._pkgindex_inherited_keys,
+                       translated_keys=self._pkgindex_translated_keys)
 
        def _update_pkgindex_header(self, header):
                portdir = normalize_path(os.path.realpath(self.settings["PORTDIR"]))
@@ -846,8 +851,6 @@ class binarytree(object):
                return False
 
        def _eval_use_flags(self, cpv, metadata):
-               metadata["DESC"] = metadata["DESCRIPTION"]
-               del metadata["DESCRIPTION"]
                use = metadata["USE"].split()
                raw_use = use
                iuse = set(f.lstrip("-+") for f in metadata["IUSE"].split())
index 3767679574eadbfa4727e9a9717d0c105bea4c52..9e03b1f0e5c5c4e120588e2971b760ea26167869 100644 (file)
@@ -668,10 +668,15 @@ def _cmp_cpv(d1, d2):
 class PackageIndex(object):
 
        def __init__(self, default_header_data=None, default_pkg_data=None,
-               inherited_keys=None):
+               inherited_keys=None, translated_keys=None):
                self._default_header_data = default_header_data
                self._default_pkg_data = default_pkg_data
                self._inherited_keys = inherited_keys
+               self._write_translation_map = {}
+               self._read_translation_map = {}
+               if translated_keys:
+                       self._write_translation_map.update(translated_keys)
+                       self._read_translation_map.update(((y, x) for (x, y) in translated_keys))
                self.header = {}
                if self._default_header_data:
                        self.header.update(self._default_header_data)
@@ -690,12 +695,13 @@ class PackageIndex(object):
                        k, v = line
                        if v:
                                v = v[1:]
-                       d[k] = v
+                       d[self._read_translation_map.get(k, k)] = v
                return d
-       
+
        def _writepkgindex(self, pkgfile, items):
                for k, v in items:
-                       pkgfile.write("%s: %s\n" % (k, v))
+                       pkgfile.write("%s: %s\n" % \
+                               (self._write_translation_map.get(k, k), v))
                pkgfile.write("\n")
 
        def read(self, pkgfile):