From 0b4e6c27e87e57fac09fa28d3ed1320cb6a83ad9 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Tue, 13 Nov 2012 23:08:05 -0800 Subject: [PATCH] update_dbentry: add parent arg for bug #367215 --- pym/_emerge/FakeVartree.py | 16 ++++++++++------ pym/portage/dbapi/__init__.py | 14 +++++++++----- pym/portage/dbapi/bintree.py | 2 +- pym/portage/dbapi/vartree.py | 2 +- pym/portage/emaint/modules/move/move.py | 16 ++++++++++------ pym/portage/update.py | 15 ++++++++++----- 6 files changed, 41 insertions(+), 24 deletions(-) diff --git a/pym/_emerge/FakeVartree.py b/pym/_emerge/FakeVartree.py index 5fde8e16b..9babb4c7b 100644 --- a/pym/_emerge/FakeVartree.py +++ b/pym/_emerge/FakeVartree.py @@ -1,4 +1,4 @@ -# Copyright 1999-2011 Gentoo Foundation +# Copyright 1999-2012 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 import sys @@ -15,6 +15,7 @@ from portage.eapi import _get_eapi_attrs from portage.exception import InvalidDependString from portage.repository.config import _gen_valid_repo from portage.update import grab_updates, parse_updates, update_dbentries +from portage.versions import _pkg_str if sys.hexversion >= 0x3000000: long = int @@ -286,12 +287,15 @@ def grab_global_updates(portdb): return retupdates def perform_global_updates(mycpv, mydb, myupdates): - aux_keys = Package._dep_keys + ("EAPI", 'repository') + aux_keys = Package._dep_keys + mydb._pkg_str_aux_keys aux_dict = dict(zip(aux_keys, mydb.aux_get(mycpv, aux_keys))) - eapi = aux_dict.pop('EAPI') - repository = aux_dict.pop('repository') try: - mycommands = myupdates[repository] + pkg = _pkg_str(mycpv, metadata=aux_dict) + except InvalidData: + return + aux_dict = dict((k, aux_dict[k]) for k in Package._dep_keys) + try: + mycommands = myupdates[pkg.repo] except KeyError: try: mycommands = myupdates['DEFAULT'] @@ -301,6 +305,6 @@ def perform_global_updates(mycpv, mydb, myupdates): if not mycommands: return - updates = update_dbentries(mycommands, aux_dict, eapi=eapi) + updates = update_dbentries(mycommands, aux_dict, parent=pkg) if updates: mydb.aux_update(mycpv, updates) diff --git a/pym/portage/dbapi/__init__.py b/pym/portage/dbapi/__init__.py index dbba22cd7..c6bdbc77a 100644 --- a/pym/portage/dbapi/__init__.py +++ b/pym/portage/dbapi/__init__.py @@ -291,7 +291,8 @@ class dbapi(object): maxval = len(cpv_all) aux_get = self.aux_get aux_update = self.aux_update - meta_keys = Package._dep_keys + ("EAPI", "PROVIDE", "repository") + update_keys = Package._dep_keys + ("PROVIDE",) + meta_keys = update_keys + self._pkg_str_aux_keys repo_dict = None if isinstance(updates, dict): repo_dict = updates @@ -301,13 +302,16 @@ class dbapi(object): onProgress(maxval, 0) for i, cpv in enumerate(cpv_all): metadata = dict(zip(meta_keys, aux_get(cpv, meta_keys))) - eapi = metadata.pop('EAPI') - repo = metadata.pop('repository') + try: + pkg = _pkg_str(cpv, metadata=metadata) + except InvalidData: + continue + metadata = dict((k, metadata[k]) for k in update_keys) if repo_dict is None: updates_list = updates else: try: - updates_list = repo_dict[repo] + updates_list = repo_dict[pkg.repo] except KeyError: try: updates_list = repo_dict['DEFAULT'] @@ -318,7 +322,7 @@ class dbapi(object): continue metadata_updates = \ - portage.update_dbentries(updates_list, metadata, eapi=eapi) + portage.update_dbentries(updates_list, metadata, parent=pkg) if metadata_updates: aux_update(cpv, metadata_updates) if onUpdate: diff --git a/pym/portage/dbapi/bintree.py b/pym/portage/dbapi/bintree.py index 0cc46268c..2203aafda 100644 --- a/pym/portage/dbapi/bintree.py +++ b/pym/portage/dbapi/bintree.py @@ -425,7 +425,7 @@ class binarytree(object): moves += 1 mytbz2 = portage.xpak.tbz2(tbz2path) mydata = mytbz2.get_data() - updated_items = update_dbentries([mylist], mydata, eapi=mycpv.eapi) + updated_items = update_dbentries([mylist], mydata, parent=mycpv) mydata.update(updated_items) mydata[b'PF'] = \ _unicode_encode(mynewpkg + "\n", diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py index 8d908fcf3..27e204e04 100644 --- a/pym/portage/dbapi/vartree.py +++ b/pym/portage/dbapi/vartree.py @@ -364,7 +364,7 @@ class vardbapi(dbapi): del e write_atomic(os.path.join(newpath, "PF"), new_pf+"\n") write_atomic(os.path.join(newpath, "CATEGORY"), mynewcat+"\n") - fixdbentries([mylist], newpath, eapi=mycpv.eapi) + fixdbentries([mylist], newpath, parent=mycpv) return moves def cp_list(self, mycp, use_cache=1): diff --git a/pym/portage/emaint/modules/move/move.py b/pym/portage/emaint/modules/move/move.py index 9f9ba90cd..607fbc42b 100644 --- a/pym/portage/emaint/modules/move/move.py +++ b/pym/portage/emaint/modules/move/move.py @@ -5,13 +5,14 @@ import portage from portage import os from portage.exception import InvalidData from _emerge.Package import Package +from portage.versions import _pkg_str class MoveHandler(object): def __init__(self, tree, porttree): self._tree = tree self._portdb = porttree.dbapi - self._update_keys = ["PROVIDE"] + list(Package._dep_keys) + self._update_keys = Package._dep_keys + ("PROVIDE",) self._master_repo = \ self._portdb.getRepositoryName(self._portdb.porttree_root) @@ -92,15 +93,18 @@ class MoveHandler(object): cpv_all = self._tree.dbapi.cpv_all() cpv_all.sort() maxval = len(cpv_all) - meta_keys = self._update_keys + ['repository', 'EAPI'] + meta_keys = self._update_keys + self._portdb._pkg_str_aux_keys if onProgress: onProgress(maxval, 0) for i, cpv in enumerate(cpv_all): metadata = dict(zip(meta_keys, aux_get(cpv, meta_keys))) - eapi = metadata.pop('EAPI') - repository = metadata.pop('repository') try: - updates = allupdates[repository] + pkg = _pkg_str(cpv, metadata=metadata) + except InvalidData: + continue + metadata = dict((k, metadata[k]) for k in self._update_keys) + try: + updates = allupdates[pkg.repo] except KeyError: try: updates = allupdates['DEFAULT'] @@ -109,7 +113,7 @@ class MoveHandler(object): if not updates: continue metadata_updates = \ - portage.update_dbentries(updates, metadata, eapi=eapi) + portage.update_dbentries(updates, metadata, parent=pkg) if metadata_updates: errors.append("'%s' has outdated metadata" % cpv) if onProgress: diff --git a/pym/portage/update.py b/pym/portage/update.py index d7ae34a46..9d2958573 100644 --- a/pym/portage/update.py +++ b/pym/portage/update.py @@ -32,7 +32,10 @@ else: ignored_dbentries = ("CONTENTS", "environment.bz2") -def update_dbentry(update_cmd, mycontent, eapi=None): +def update_dbentry(update_cmd, mycontent, eapi=None, parent=None): + + if parent is not None: + eapi = parent.eapi if update_cmd[0] == "move": old_value = _unicode(update_cmd[1]) @@ -101,7 +104,7 @@ def update_dbentry(update_cmd, mycontent, eapi=None): return mycontent -def update_dbentries(update_iter, mydata, eapi=None): +def update_dbentries(update_iter, mydata, eapi=None, parent=None): """Performs update commands and returns a dict containing only the updated items.""" updated_items = {} @@ -115,7 +118,8 @@ def update_dbentries(update_iter, mydata, eapi=None): is_encoded = mycontent is not orig_content orig_content = mycontent for update_cmd in update_iter: - mycontent = update_dbentry(update_cmd, mycontent, eapi=eapi) + mycontent = update_dbentry(update_cmd, mycontent, + eapi=eapi, parent=parent) if mycontent != orig_content: if is_encoded: mycontent = _unicode_encode(mycontent, @@ -124,7 +128,7 @@ def update_dbentries(update_iter, mydata, eapi=None): updated_items[k] = mycontent return updated_items -def fixdbentries(update_iter, dbdir, eapi=None): +def fixdbentries(update_iter, dbdir, eapi=None, parent=None): """Performs update commands which result in search and replace operations for each of the files in dbdir (excluding CONTENTS and environment.bz2). Returns True when actual modifications are necessary and False otherwise.""" @@ -136,7 +140,8 @@ def fixdbentries(update_iter, dbdir, eapi=None): mode='r', encoding=_encodings['repo.content'], errors='replace') as f: mydata[myfile] = f.read() - updated_items = update_dbentries(update_iter, mydata, eapi=eapi) + updated_items = update_dbentries(update_iter, mydata, + eapi=eapi, parent=parent) for myfile, mycontent in updated_items.items(): file_path = os.path.join(dbdir, myfile) write_atomic(file_path, mycontent, encoding=_encodings['repo.content']) -- 2.26.2