From e877ec9bb96a63b42a38bb722cbb6490fe04a08c Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Sat, 3 May 2008 19:25:07 +0000 Subject: [PATCH] Improve --resume handling of saved "favorites" argument atoms: * Save the favorites in oneshot mode too since they're still useful for restoring state upon --resume. * Add a depgraph._load_favorites() method to resume state from a previous select_files() call. This allows Package instances to be matched with DependencyArg instances during graph creation. (trunk r10134) svn path=/main/branches/2.1.2/; revision=10135 --- bin/emerge | 104 ++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 76 insertions(+), 28 deletions(-) diff --git a/bin/emerge b/bin/emerge index 631e354d9..038fdc1d1 100755 --- a/bin/emerge +++ b/bin/emerge @@ -2424,8 +2424,6 @@ class depgraph(object): root_config = self.roots[self.target_root] sets = root_config.sets getSetAtoms = root_config.setconfig.getSetAtoms - oneshot = "--oneshot" in self.myopts or \ - "--onlydeps" in self.myopts myfavorites=[] myroot = self.target_root dbs = self._filtered_trees[myroot]["dbs"] @@ -2557,8 +2555,7 @@ class depgraph(object): self._sets[s] = expanded_set args.append(SetArg(arg=SETPREFIX+s, set=expanded_set, root_config=root_config)) - #if not oneshot: - # myfavorites.append(x) + myfavorites.append(x) continue if not is_valid_package_atom(x): portage.writemsg("\n\n!!! '%s' is not a valid package atom.\n" % x, @@ -2645,8 +2642,7 @@ class depgraph(object): if myatom in args_set: continue args_set.add(myatom) - if not oneshot: - myfavorites.append(myatom) + myfavorites.append(myatom) self._set_atoms.update(chain(*self._sets.itervalues())) atom_arg_map = self._atom_arg_map for arg in args: @@ -4899,7 +4895,8 @@ class depgraph(object): s = SETPREFIX + k if s in world_set: continue - all_added.append(SETPREFIX + k) + # sets in world are supported in newer portage + #all_added.append(SETPREFIX + k) all_added.extend(added_favorites) all_added.sort() for a in all_added: @@ -4915,11 +4912,13 @@ class depgraph(object): Add a resume command to the graph and validate it in the process. This will raise a PackageNotFound exception if a package is not available. """ - self._sets["args"].update(resume_data.get("favorites", [])) - mergelist = resume_data.get("mergelist", []) + + if not isinstance(resume_data, dict): + return False favorites = resume_data.get("favorites") - if not isinstance(favorites, list): - favorites = [] + if isinstance(favorites, list): + self._load_favorites(resume_data) + mergelist = resume_data.get("mergelist", []) if mergelist and "--skipfirst" in self.myopts: for i, task in enumerate(mergelist): @@ -4976,15 +4975,9 @@ class depgraph(object): if not serialized_tasks or "--nodeps" in self.myopts: self._serialized_tasks_cache = serialized_tasks else: - favorites_set = InternalPackageSet(atom for atom in favorites \ - if isinstance(atom, basestring) and portage.isvalidatom(atom)) - for node in serialized_tasks: - if isinstance(node, Package) and \ - node.operation == "merge" and \ - favorites_set.findAtomForPackage(node.cpv, node.metadata): - self._set_nodes.add(node) - self._select_package = self._select_pkg_from_graph + self.myparams.add("selective") + for task in serialized_tasks: if isinstance(task, Package) and \ task.operation == "merge": @@ -5008,13 +5001,68 @@ class depgraph(object): except self._unknown_internal_error: return False - for node in self.digraph.root_nodes(): - if isinstance(node, Package) and \ - node.operation == "merge": - # Give hint to the --tree display. - self._set_nodes.add(node) return True + def _load_favorites(self, favorites): + """ + Use a list of favorites to resume state from a + previous select_files() call. This creates similar + DependencyArg instances to those that would have + been created by the original select_files() call. + This allows Package instances to be matched with + DependencyArg instances during graph creation. + """ + root_config = self.roots[self.target_root] + getSetAtoms = root_config.setconfig.getSetAtoms + sets = root_config.sets + args = [] + for x in favorites: + if not isinstance(x, basestring): + continue + if x in ("system", "world"): + x = SETPREFIX + x + if x.startswith(SETPREFIX): + s = x[len(SETPREFIX):] + if s not in sets: + continue + if s in self._sets: + continue + # Recursively expand sets so that containment tests in + # self._get_parent_sets() properly match atoms in nested + # sets (like if world contains system). + expanded_set = InternalPackageSet( + initial_atoms=getSetAtoms(s)) + self._sets[s] = expanded_set + args.append(SetArg(arg=x, set=expanded_set, + root_config=root_config)) + else: + if not portage.isvalidatom(x): + continue + args.append(AtomArg(arg=x, atom=x, + root_config=root_config)) + + # Create the "args" package set from atoms and + # packages given as arguments. + args_set = self._sets["args"] + for arg in args: + if not isinstance(arg, (AtomArg, PackageArg)): + continue + myatom = arg.atom + if myatom in args_set: + continue + args_set.add(myatom) + self._set_atoms.update(chain(*self._sets.itervalues())) + atom_arg_map = self._atom_arg_map + for arg in args: + for atom in arg.set: + atom_key = (atom, arg.root_config.root) + refs = atom_arg_map.get(atom_key) + if refs is None: + refs = [] + atom_arg_map[atom_key] = refs + if arg not in refs: + refs.append(arg) + class _internal_exception(portage_exception.PortageException): def __init__(self, value=""): portage_exception.PortageException.__init__(self, value) @@ -5355,6 +5403,8 @@ class MergeTask(object): buildpkgonly = "--buildpkgonly" in self.myopts fetchonly = "--fetchonly" in self.myopts or \ "--fetch-all-uri" in self.myopts + oneshot = "--oneshot" in self.myopts or \ + "--onlydeps" in self.myopts pretend = "--pretend" in self.myopts ldpath_mtimes = mtimedb["ldpath"] xterm_titles = "notitles" not in self.settings.features @@ -5704,10 +5754,8 @@ class MergeTask(object): if retval != os.EX_OK: return retval #need to check for errors - if "--buildpkgonly" not in self.myopts: - self.trees[x[1]]["vartree"].inject(x[2]) - myfavkey = portage.cpv_getkey(x[2]) - if not fetchonly and not pretend and \ + if not buildpkgonly: + if not (fetchonly or oneshot or pretend) and \ args_set.findAtomForPackage(pkg_key, metadata): world_set.lock() world_set.load() -- 2.26.2