-# Copyright 1999-2011 Gentoo Foundation
+# Copyright 1999-2012 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
import sys
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
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']
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)
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
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']
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:
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",
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):
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)
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']
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:
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])
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 = {}
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,
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."""
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'])