From 03c305743af0f625a23a8c2c5d69325c30e4e2d8 Mon Sep 17 00:00:00 2001 From: Fabian Groffen Date: Sat, 3 Nov 2007 19:28:56 +0000 Subject: [PATCH] Merged from trunk 8389:8397 | 8390 | Bug #197932 - Make dbapi._cpv_sort_ascending() preserve | | zmedico | explicit -r0 for consistency in findname and aux_get calls. | | 8392 | Remove redundant code from previous commit. | | zmedico | | | 8397 | Fix update_config_files() so that it uses update_dbentry() | | zmedico | to handle update commands since that already supports | | | slotmove commands for SLOT atoms. | svn path=/main/branches/prefix/; revision=8400 --- pym/portage/dbapi/__init__.py | 21 ++++++------ pym/portage/update.py | 61 +++++++++++++++++------------------ 2 files changed, 40 insertions(+), 42 deletions(-) diff --git a/pym/portage/dbapi/__init__.py b/pym/portage/dbapi/__init__.py index 0bec4cce5..c6318bacb 100644 --- a/pym/portage/dbapi/__init__.py +++ b/pym/portage/dbapi/__init__.py @@ -28,18 +28,17 @@ class dbapi(object): order. It sorts in place and returns None. """ if len(cpv_list) > 1: - first_split = catpkgsplit(cpv_list[0]) - cat = first_split[0] - cpv_list[0] = first_split[1:] - for i in xrange(1, len(cpv_list)): - cpv_list[i] = catpkgsplit(cpv_list[i])[1:] + # If the cpv includes explicit -r0, it has to be preserved + # for consistency in findname and aux_get calls, so use a + # dict to map strings back to their original values. + str_map = {} + for i, cpv in enumerate(cpv_list): + mysplit = tuple(catpkgsplit(cpv)[1:]) + str_map[mysplit] = cpv + cpv_list[i] = mysplit cpv_list.sort(pkgcmp) - for i, (pn, ver, rev) in enumerate(cpv_list): - if rev == "r0": - cpv = cat + "/" + pn + "-" + ver - else: - cpv = cat + "/" + pn + "-" + ver + "-" + rev - cpv_list[i] = cpv + for i, mysplit in enumerate(cpv_list): + cpv_list[i] = str_map[mysplit] def cpv_all(self): """Return all CPVs in the db diff --git a/pym/portage/update.py b/pym/portage/update.py index ec99ea03e..87f6057fd 100644 --- a/pym/portage/update.py +++ b/pym/portage/update.py @@ -181,40 +181,39 @@ def update_config_files(config_root, protect, protect_mask, update_iter): if file_contents.has_key(x): del file_contents[x] continue - worldlist = grabfile(os.path.join(config_root, WORLD_FILE)) - # TODO: handle slotmove commands for SLOT stoms + worldlist = grabfile(os.path.join(config_root, WORLD_FILE)) + modified = False for update_cmd in update_iter: - if update_cmd[0] == "move": - old_value, new_value = update_cmd[1], update_cmd[2] - #update world entries: - for x in range(0,len(worldlist)): - #update world entries, if any. - worldlist[x] = \ - dep_transform(worldlist[x], old_value, new_value) - - #update /etc/portage/packages.* - for x in file_contents: - for mypos in range(0,len(file_contents[x])): - line = file_contents[x][mypos] - if line[0] == "#" or not line.strip(): - continue - myatom = line.split()[0] - if myatom.startswith("-"): - # package.mask supports incrementals - myatom = myatom[1:] - if not isvalidatom(myatom): - continue - key = dep_getkey(myatom) - if key == old_value: - file_contents[x][mypos] = \ - line.replace(old_value, new_value) - update_files[x] = 1 - sys.stdout.write("p") - sys.stdout.flush() + for pos, atom in enumerate(worldlist): + new_atom = update_dbentry(update_cmd, atom) + if atom != new_atom: + worldlist[pos] = new_atom + modified = True + if modified: + worldlist.sort() + write_atomic(os.path.join(config_root, WORLD_FILE), + "\n".join(worldlist)+"\n") - worldlist.sort() - write_atomic(os.path.join(config_root, WORLD_FILE), "\n".join(worldlist)+"\n") + # update /etc/portage/packages.* + ignore_line_re = re.compile(r'^#|^\s*$') + for update_cmd in update_iter: + for x, contents in file_contents.iteritems(): + for pos, line in enumerate(contents): + if ignore_line_re.match(line): + continue + atom = line.split()[0] + if atom.startswith("-"): + # package.mask supports incrementals + atom = atom[1:] + if not isvalidatom(atom): + continue + new_atom = update_dbentry(update_cmd, atom) + if atom != new_atom: + contents[pos] = line.replace(atom, new_atom) + update_files[x] = 1 + sys.stdout.write("p") + sys.stdout.flush() protect_obj = ConfigProtect( config_root, protect, protect_mask) -- 2.26.2