class SlotDict(object):
- _keys = keys_set
- __slots__ = ("__weakref__",) + tuple("_val_" + k for k in _keys)
+ allowed_keys = keys_set
+ __slots__ = ("__weakref__",) + \
+ tuple("_val_" + k for k in allowed_keys)
def __iter__(self):
for k, v in self.iteritems():
return list(self)
def iteritems(self):
- for k in self._keys:
+ for k in self.allowed_keys:
try:
yield (k, getattr(self, "_val_" + k))
except AttributeError:
return c
def clear(self):
- for k in self._keys:
+ for k in self.allowed_keys:
try:
delattr(self, "_val_" + k)
except AttributeError:
pass
v = SlotDict
- _slot_dict_classes[keys_set] = v
+ _slot_dict_classes[v.allowed_keys] = v
return v
import os, errno, stat
import re
-from itertools import izip
+from itertools import chain, izip
class bindbapi(fakedbapi):
_known_keys = frozenset(list(fakedbapi._known_keys) + \
("repository" , "REPO"),
)
+ self._pkgindex_allowed_pkg_keys = set(chain(
+ self._pkgindex_keys,
+ self._pkgindex_aux_keys,
+ self._pkgindex_hashes,
+ self._pkgindex_default_pkg_data,
+ self._pkgindex_inherited_keys,
+ self._pkgindex_default_header_data,
+ chain(*self._pkgindex_translated_keys)
+ ))
+
def move_ent(self, mylist):
if not self.populated:
self.populate()
def _new_pkgindex(self):
return portage.getbinpkg.PackageIndex(
+ allowed_pkg_keys=self._pkgindex_allowed_pkg_keys,
default_header_data=self._pkgindex_default_header_data,
default_pkg_data=self._pkgindex_default_pkg_data,
inherited_keys=self._pkgindex_inherited_keys,
# $Id$
from portage.output import red, yellow, green
+from portage.cache.mappings import slot_dict_class
import portage.xpak
import HTMLParser
import sys
class PackageIndex(object):
- def __init__(self, default_header_data=None, default_pkg_data=None,
- inherited_keys=None, translated_keys=None):
+ def __init__(self,
+ allowed_pkg_keys=None,
+ default_header_data=None,
+ default_pkg_data=None,
+ inherited_keys=None,
+ translated_keys=None):
+
+ self._pkg_slot_dict = None
+ if allowed_pkg_keys is not None:
+ self._pkg_slot_dict = slot_dict_class(allowed_pkg_keys)
+
self._default_header_data = default_header_data
self._default_pkg_data = default_pkg_data
self._inherited_keys = inherited_keys
self.packages = []
self.modified = True
- def _readpkgindex(self, pkgfile):
- d = {}
+ def _readpkgindex(self, pkgfile, pkg_entry=True):
+
+ allowed_keys = None
+ if self._pkg_slot_dict is None or not pkg_entry:
+ d = {}
+ else:
+ d = self._pkg_slot_dict()
+ allowed_keys = d.allowed_keys
+
for line in pkgfile:
line = line.rstrip("\n")
if not line:
k, v = line
if v:
v = v[1:]
- d[self._read_translation_map.get(k, k)] = v
+ k = self._read_translation_map.get(k, k)
+ if allowed_keys is not None and \
+ k not in allowed_keys:
+ continue
+ d[k] = v
return d
def _writepkgindex(self, pkgfile, items):
self.readBody(pkgfile)
def readHeader(self, pkgfile):
- self.header.update(self._readpkgindex(pkgfile))
+ self.header.update(self._readpkgindex(pkgfile, pkg_entry=False))
def readBody(self, pkgfile):
while True: