From: Fabian Groffen Date: Sun, 31 Jan 2010 09:43:08 +0000 (-0000) Subject: Merged from trunk -r15285:15292 X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=d29ba6fb641f96715ee26c683924ea72c47a7edf;p=portage.git Merged from trunk -r15285:15292 | 15286 | fix: python dbm module doesn't accept unicode as key | | volkmar | | | 15287 | Define __slots__ in all classes. | | zmedico | | | 15288 | In config._expandLicenseToken(), make sure traversed_groups | | zmedico | is only initialized when appropriate. | | 15289 | Fix concatenation of list + tuple in | | zmedico | Manifest._createManifestEntries(). | | 15290 | Don't generate DeprecationWarning for portdbapi arguments. | | zmedico | Wait until new portdbapi constructor is in stable portage | | | first. | | 15291 | fix flat_list cache backend looks like it was outdated wrt. | | volkmar | template cache backend | | 15292 | Show a DeprecationWarning if the deprecated pordbapi | | zmedico | constructor parameter is used incorrectly. | svn path=/main/branches/prefix/; revision=15301 --- diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py index 911714909..c442a1168 100644 --- a/pym/portage/__init__.py +++ b/pym/portage/__init__.py @@ -2314,7 +2314,7 @@ class config(object): rValue.append(token) return rValue group_name = license_name[1:] - if not traversed_groups: + if traversed_groups is None: traversed_groups = set() license_group = self._license_groups.get(group_name) if group_name in traversed_groups: diff --git a/pym/portage/cache/anydbm.py b/pym/portage/cache/anydbm.py index 6add2da60..33cedebbb 100644 --- a/pym/portage/cache/anydbm.py +++ b/pym/portage/cache/anydbm.py @@ -63,10 +63,10 @@ class database(fs_template.FsBased): def _getitem(self, cpv): # we override getitem because it's just a cpickling of the data handed in. - return pickle.loads(self.__db[cpv]) + return pickle.loads(self.__db[_unicode_encode(cpv)]) def _setitem(self, cpv, values): - self.__db[cpv] = pickle.dumps(values,pickle.HIGHEST_PROTOCOL) + self.__db[_unicode_encode(cpv)] = pickle.dumps(values,pickle.HIGHEST_PROTOCOL) def _delitem(self, cpv): del self.__db[cpv] diff --git a/pym/portage/cache/flat_list.py b/pym/portage/cache/flat_list.py index 51231a52a..1c4ec68de 100644 --- a/pym/portage/cache/flat_list.py +++ b/pym/portage/cache/flat_list.py @@ -22,21 +22,21 @@ class database(fs_template.FsBased): 'KEYWORDS', 'IUSE', 'UNUSED_00', 'PDEPEND', 'PROVIDE', 'EAPI', 'PROPERTIES', 'DEFINED_PHASES') - def __init__(self, label, auxdbkeys, **config): - super(database,self).__init__(label, auxdbkeys, **config) - self._base = os.path.join(self._base, + def __init__(self, *args, **config): + super(database,self).__init__(*args, **config) + self.location = os.path.join(self.location, self.label.lstrip(os.path.sep).rstrip(os.path.sep)) if len(self._known_keys) > len(self.auxdbkey_order) + 2: raise Exception("less ordered keys then auxdbkeys") - if not os.path.exists(self._base): + if not os.path.exists(self.location): self._ensure_dirs() def _getitem(self, cpv): d = {} try: - myf = codecs.open(_unicode_encode(os.path.join(self._base, cpv), + myf = codecs.open(_unicode_encode(os.path.join(self.location, cpv), encoding=_encodings['fs'], errors='strict'), mode='r', encoding=_encodings['repo.content'], errors='replace') @@ -58,7 +58,7 @@ class database(fs_template.FsBased): def _setitem(self, cpv, values): s = cpv.rfind("/") - fp=os.path.join(self._base,cpv[:s],".update.%i.%s" % (os.getpid(), cpv[s+1:])) + fp=os.path.join(self.location,cpv[:s],".update.%i.%s" % (os.getpid(), cpv[s+1:])) try: myf = codecs.open(_unicode_encode(fp, encoding=_encodings['fs'], errors='strict'), @@ -84,7 +84,7 @@ class database(fs_template.FsBased): myf.close() self._ensure_access(fp, mtime=values["_mtime_"]) #update written. now we move it. - new_fp = os.path.join(self._base,cpv) + new_fp = os.path.join(self.location,cpv) try: os.rename(fp, new_fp) except (OSError, IOError) as e: @@ -94,7 +94,7 @@ class database(fs_template.FsBased): def _delitem(self, cpv): try: - os.remove(os.path.join(self._base,cpv)) + os.remove(os.path.join(self.location,cpv)) except OSError as e: if errno.ENOENT == e.errno: raise KeyError(cpv) @@ -103,13 +103,13 @@ class database(fs_template.FsBased): def __contains__(self, cpv): - return os.path.exists(os.path.join(self._base, cpv)) + return os.path.exists(os.path.join(self.location, cpv)) def __iter__(self): """generator for walking the dir struct""" - dirs = [self._base] - len_base = len(self._base) + dirs = [self.location] + len_base = len(self.location) while len(dirs): for l in os.listdir(dirs[0]): if l.endswith(".cpickle"): diff --git a/pym/portage/cache/mappings.py b/pym/portage/cache/mappings.py index 2e24a7a8a..f15f362b0 100644 --- a/pym/portage/cache/mappings.py +++ b/pym/portage/cache/mappings.py @@ -22,6 +22,8 @@ class Mapping(object): for UserDict.DictMixin so that code converted via 2to3 will run. """ + __slots__ = () + def __iter__(self): return iter(self.keys()) @@ -79,6 +81,8 @@ class MutableMapping(Mapping): A mutable vesion of the Mapping class. """ + __slots__ = () + def clear(self): for key in list(self): del self[key] @@ -146,6 +150,8 @@ class UserDict(MutableMapping): http://bugs.python.org/issue2876 """ + __slots__ = ('data',) + def __init__(self, *args, **kwargs): self.data = {} @@ -190,6 +196,8 @@ class UserDict(MutableMapping): class OrderedDict(UserDict): + __slots__ = ('_order',) + def __init__(self, *args, **kwargs): self._order = [] UserDict.__init__(self, *args, **kwargs) diff --git a/pym/portage/dbapi/porttree.py b/pym/portage/dbapi/porttree.py index 1b5567a8e..d5ecce987 100644 --- a/pym/portage/dbapi/porttree.py +++ b/pym/portage/dbapi/porttree.py @@ -143,7 +143,7 @@ class portdbapi(dbapi): def __init__(self, _unused_param=None, mysettings=None): """ - @param _unused_param: deprecated + @param _unused_param: deprecated, use mysettings['PORTDIR'] instead @type _unused_param: None @param mysettings: an immutable config instance @type mysettings: portage.config @@ -157,15 +157,17 @@ class portdbapi(dbapi): from portage import settings self.mysettings = config(clone=settings) - if _unused_param is not None: + porttree_root = self.mysettings['PORTDIR'] + + # always show this warning after this parameter + # is unused in stable portage + if _unused_param is not None and _unused_param != porttree_root: warnings.warn("The first parameter of the " + \ "portage.dbapi.porttree.portdbapi" + \ " constructor is now unused. Use " + \ "mysettings['PORTDIR'] instead.", DeprecationWarning) - porttree_root = self.mysettings['PORTDIR'] - # This is strictly for use in aux_get() doebuild calls when metadata # is generated by the depend phase. It's safest to use a clone for # this purpose because doebuild makes many changes to the config diff --git a/pym/portage/manifest.py b/pym/portage/manifest.py index fc8afb4cf..470f732d6 100644 --- a/pym/portage/manifest.py +++ b/pym/portage/manifest.py @@ -205,6 +205,8 @@ class Manifest(object): return myhashdict def _createManifestEntries(self): + valid_hashes = set(portage.const.MANIFEST2_HASH_FUNCTIONS) + valid_hashes.add('size') mytypes = list(self.fhashdict) mytypes.sort() for t in mytypes: @@ -213,10 +215,8 @@ class Manifest(object): for f in myfiles: myentry = Manifest2Entry( type=t, name=f, hashes=self.fhashdict[t][f].copy()) - myhashkeys = list(myentry.hashes) - myhashkeys.sort() - for h in myhashkeys: - if h not in ["size"] + portage.const.MANIFEST2_HASH_FUNCTIONS: + for h in list(myentry.hashes): + if h not in valid_hashes: del myentry.hashes[h] yield myentry