2 # Copyright 1999-2006 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4 # $Id: emerge 5976 2007-02-17 09:14:53Z genone $
7 # This block ensures that ^C interrupts are handled quietly.
11 def exithandler(signum,frame):
12 signal.signal(signal.SIGINT, signal.SIG_IGN)
13 signal.signal(signal.SIGTERM, signal.SIG_IGN)
16 signal.signal(signal.SIGINT, exithandler)
17 signal.signal(signal.SIGTERM, exithandler)
18 signal.signal(signal.SIGPIPE, signal.SIG_DFL)
20 except KeyboardInterrupt:
25 os.environ["PORTAGE_LEGACY_GLOBALS"] = "false"
29 from os import path as osp
30 sys.path.insert(0, osp.join(osp.dirname(osp.dirname(osp.realpath(__file__))), "pym"))
32 del os.environ["PORTAGE_LEGACY_GLOBALS"]
33 from portage import digraph, portdbapi
34 from portage.const import NEWS_LIB_PATH, CACHE_PATH, PRIVATE_PATH
37 import portage.xpak, commands, errno, re, socket, time, types
38 from portage.output import blue, bold, colorize, darkblue, darkgreen, darkred, green, \
39 havecolor, nc_len, nocolor, red, teal, turquoise, white, xtermTitle, \
40 xtermTitleReset, yellow
41 from portage.output import create_color_func
42 good = create_color_func("GOOD")
43 bad = create_color_func("BAD")
46 portage.dep._dep_check_strict = True
49 import portage.exception
50 from portage.data import secpass
51 from portage.util import normalize_path as normpath
52 from portage.util import writemsg
54 if not hasattr(__builtins__, "set"):
55 from sets import Set as set
56 from itertools import chain, izip
57 from UserDict import DictMixin
62 import pickle as cPickle
64 class stdout_spinner(object):
66 "Gentoo Rocks ("+os.uname()[0]+")",
67 "Thank you for using Gentoo. :)",
68 "Are you actually trying to read this?",
69 "How many times have you stared at this?",
70 "We are generating the cache right now",
71 "You are paying too much attention.",
72 "A theory is better than its explanation.",
73 "Phasers locked on target, Captain.",
74 "Thrashing is just virtual crashing.",
75 "To be is to program.",
76 "Real Users hate Real Programmers.",
77 "When all else fails, read the instructions.",
78 "Functionality breeds Contempt.",
79 "The future lies ahead.",
80 "3.1415926535897932384626433832795028841971694",
81 "Sometimes insanity is the only alternative.",
82 "Inaccuracy saves a world of explanation.",
85 twirl_sequence = "/-\\|/-\\|/-\\|/-\\|\\-/|\\-/|\\-/|\\-/|"
89 self.update = self.update_twirl
90 self.scroll_sequence = self.scroll_msgs[
91 int(time.time() * 100) % len(self.scroll_msgs)]
93 def update_basic(self):
94 self.spinpos = (self.spinpos + 1) % 500
95 if (self.spinpos % 100) == 0:
97 sys.stdout.write(". ")
102 def update_scroll(self):
103 if(self.spinpos >= len(self.scroll_sequence)):
104 sys.stdout.write(darkgreen(" \b\b\b" + self.scroll_sequence[
105 len(self.scroll_sequence) - 1 - (self.spinpos % len(self.scroll_sequence))]))
107 sys.stdout.write(green("\b " + self.scroll_sequence[self.spinpos]))
109 self.spinpos = (self.spinpos + 1) % (2 * len(self.scroll_sequence))
111 def update_twirl(self):
112 self.spinpos = (self.spinpos + 1) % len(self.twirl_sequence)
113 sys.stdout.write("\b\b " + self.twirl_sequence[self.spinpos])
116 def update_quiet(self):
119 def userquery(prompt, responses=None, colours=None):
120 """Displays a prompt and a set of responses, then waits for a response
121 which is checked against the responses and the first to match is
122 returned. An empty response will match the first value in responses. The
123 input buffer is *not* cleared prior to the prompt!
126 responses: a List of Strings.
127 colours: a List of Functions taking and returning a String, used to
128 process the responses for display. Typically these will be functions
129 like red() but could be e.g. lambda x: "DisplayString".
130 If responses is omitted, defaults to ["Yes", "No"], [green, red].
131 If only colours is omitted, defaults to [bold, ...].
133 Returns a member of the List responses. (If called without optional
134 arguments, returns "Yes" or "No".)
135 KeyboardInterrupt is converted to SystemExit to avoid tracebacks being
137 if responses is None:
138 responses, colours = ["Yes", "No"], [green, red]
139 elif colours is None:
141 colours=(colours*len(responses))[:len(responses)]
145 response=raw_input("["+"/".join([colours[i](responses[i]) for i in range(len(responses))])+"] ")
146 for key in responses:
147 # An empty response will match the first value in responses.
148 if response.upper()==key[:len(response)].upper():
150 print "Sorry, response '%s' not understood." % response,
151 except (EOFError, KeyboardInterrupt):
156 "clean", "config", "depclean",
158 "prune", "regen", "search",
159 "sync", "system", "unmerge", "world",
162 "--ask", "--alphabetical",
163 "--buildpkg", "--buildpkgonly",
164 "--changelog", "--columns",
168 "--fetchonly", "--fetch-all-uri",
169 "--getbinpkg", "--getbinpkgonly",
170 "--help", "--ignore-default-opts",
172 "--newuse", "--nocolor",
173 "--nodeps", "--noreplace",
174 "--nospinner", "--oneshot",
175 "--onlydeps", "--pretend",
176 "--quiet", "--resume",
177 "--searchdesc", "--selective",
181 "--usepkg", "--usepkgonly",
182 "--verbose", "--version"
188 "b":"--buildpkg", "B":"--buildpkgonly",
189 "c":"--clean", "C":"--unmerge",
190 "d":"--debug", "D":"--deep",
192 "f":"--fetchonly", "F":"--fetch-all-uri",
193 "g":"--getbinpkg", "G":"--getbinpkgonly",
195 "k":"--usepkg", "K":"--usepkgonly",
197 "n":"--noreplace", "N":"--newuse",
198 "o":"--onlydeps", "O":"--nodeps",
199 "p":"--pretend", "P":"--prune",
201 "s":"--search", "S":"--searchdesc",
204 "v":"--verbose", "V":"--version"
207 def emergelog(xterm_titles, mystr, short_msg=None):
209 if short_msg == None:
211 if "HOSTNAME" in os.environ:
212 short_msg = os.environ["HOSTNAME"]+": "+short_msg
213 xtermTitle(short_msg)
215 file_path = "/var/log/emerge.log"
216 mylogfile = open(file_path, "a")
217 portage.util.apply_secpass_permissions(file_path,
218 uid=portage.portage_uid, gid=portage.portage_gid,
222 mylock = portage.locks.lockfile(mylogfile)
223 # seek because we may have gotten held up by the lock.
224 # if so, we may not be positioned at the end of the file.
226 mylogfile.write(str(time.time())[:10]+": "+mystr+"\n")
230 portage.locks.unlockfile(mylock)
232 except (IOError,OSError,portage.exception.PortageException), e:
234 print >> sys.stderr, "emergelog():",e
236 def countdown(secs=5, doing="Starting"):
238 print ">>> Waiting",secs,"seconds before starting..."
239 print ">>> (Control-C to abort)...\n"+doing+" in: ",
243 sys.stdout.write(colorize("UNMERGE_WARN", str(sec+1)+" "))
248 # formats a size given in bytes nicely
249 def format_size(mysize):
250 if type(mysize) not in [types.IntType,types.LongType]:
252 if 0 != mysize % 1024:
253 # Always round up to the next kB so that it doesn't show 0 kB when
254 # some small file still needs to be fetched.
255 mysize += 1024 - mysize % 1024
256 mystr=str(mysize/1024)
260 mystr=mystr[:mycount]+","+mystr[mycount:]
264 def getgccversion(chost):
267 return: the current in-use gcc version
270 gcc_ver_command = 'gcc -dumpversion'
271 gcc_ver_prefix = 'gcc-'
273 gcc_not_found_error = red(
274 "!!! No gcc found. You probably need to 'source /etc/profile'\n" +
275 "!!! to update the environment of this terminal and possibly\n" +
276 "!!! other terminals also.\n"
279 mystatus, myoutput = commands.getstatusoutput("eselect compiler show")
280 if mystatus == os.EX_OK and len(myoutput.split("/")) == 2:
281 part1, part2 = myoutput.split("/")
282 if part1.startswith(chost + "-"):
283 return myoutput.replace(chost + "-", gcc_ver_prefix, 1)
285 mystatus, myoutput = commands.getstatusoutput("gcc-config -c")
286 if mystatus == os.EX_OK and myoutput.startswith(chost + "-"):
287 return myoutput.replace(chost + "-", gcc_ver_prefix, 1)
289 mystatus, myoutput = commands.getstatusoutput(
290 chost + "-" + gcc_ver_command)
291 if mystatus == os.EX_OK:
292 return gcc_ver_prefix + myoutput
294 mystatus, myoutput = commands.getstatusoutput(gcc_ver_command)
295 if mystatus == os.EX_OK:
296 return gcc_ver_prefix + myoutput
298 portage.writemsg(gcc_not_found_error, noiselevel=-1)
299 return "[unavailable]"
301 def getportageversion(portdir, target_root, profile, chost, vardb):
302 profilever = "unavailable"
304 realpath = os.path.realpath(profile)
305 basepath = os.path.realpath(os.path.join(portdir, "profiles"))
306 if realpath.startswith(basepath):
307 profilever = realpath[1 + len(basepath):]
310 profilever = "!" + os.readlink(profile)
313 del realpath, basepath
316 libclist = vardb.match("virtual/libc")
317 libclist += vardb.match("virtual/glibc")
318 libclist = portage.util.unique_array(libclist)
320 xs=portage.catpkgsplit(x)
322 libcver+=","+"-".join(xs[1:])
324 libcver="-".join(xs[1:])
326 libcver="unavailable"
328 gccver = getgccversion(chost)
329 unameout=os.uname()[2]+" "+os.uname()[4]
331 return "Portage " + portage.VERSION +" ("+profilever+", "+gccver+", "+libcver+", "+unameout+")"
333 def create_depgraph_params(myopts, myaction):
334 #configure emerge engine parameters
336 # self: include _this_ package regardless of if it is merged.
337 # selective: exclude the package if it is merged
338 # recurse: go into the dependencies
339 # deep: go into the dependencies of already merged packages
340 # empty: pretend nothing is merged
341 myparams = ["recurse"]
344 if "--update" in myopts or \
345 "--newuse" in myopts or \
346 "--noreplace" in myopts or \
347 myaction in ("system", "world"):
348 add.extend(["selective"])
349 if "--emptytree" in myopts:
350 add.extend(["empty"])
351 sub.extend(["selective"])
352 if "--nodeps" in myopts:
353 sub.extend(["recurse"])
354 if "--deep" in myopts:
357 if (x not in myparams) and (x not in sub):
364 # search functionality
365 class search(object):
376 def __init__(self, settings, portdb, vartree, spinner, searchdesc,
378 """Searches the available and installed packages for the supplied search key.
379 The list of available and installed packages is created at object instantiation.
380 This makes successive searches faster."""
381 self.settings = settings
383 self.vartree = vartree
384 self.spinner = spinner
385 self.verbose = verbose
386 self.searchdesc = searchdesc
388 def execute(self,searchkey):
389 """Performs the search for the supplied search key"""
391 self.searchkey=searchkey
392 self.packagematches = []
395 self.matches = {"pkg":[], "desc":[]}
398 self.matches = {"pkg":[]}
399 print "Searching... ",
402 if self.searchkey.startswith('%'):
404 self.searchkey = self.searchkey[1:]
405 if self.searchkey.startswith('@'):
407 self.searchkey = self.searchkey[1:]
409 self.searchre=re.compile(self.searchkey,re.I)
411 self.searchre=re.compile(re.escape(self.searchkey), re.I)
412 for package in self.portdb.cp_all():
413 self.spinner.update()
416 match_string = package[:]
418 match_string = package.split("/")[-1]
421 if self.searchre.search(match_string):
422 if not self.portdb.xmatch("match-visible", package):
424 self.matches["pkg"].append([package,masked])
425 elif self.searchdesc: # DESCRIPTION searching
426 full_package = self.portdb.xmatch("bestmatch-visible", package)
428 #no match found; we don't want to query description
429 full_package = portage.best(
430 self.portdb.xmatch("match-all", package))
436 full_desc = self.portdb.aux_get(
437 full_package, ["DESCRIPTION"])[0]
439 print "emerge: search: aux_get() failed, skipping"
441 if self.searchre.search(full_desc):
442 self.matches["desc"].append([full_package,masked])
444 for mtype in self.matches:
445 self.matches[mtype].sort()
446 self.mlen += len(self.matches[mtype])
449 """Outputs the results of the search."""
450 print "\b\b \n[ Results for search key : "+white(self.searchkey)+" ]"
451 print "[ Applications found : "+white(str(self.mlen))+" ]"
453 for mtype in self.matches:
454 for match,masked in self.matches[mtype]:
457 full_package = self.portdb.xmatch(
458 "bestmatch-visible", match)
460 #no match found; we don't want to query description
462 full_package = portage.best(
463 self.portdb.xmatch("match-all",match))
466 match = portage.pkgsplit(match)[0]
470 desc, homepage, license = self.portdb.aux_get(
471 full_package, ["DESCRIPTION","HOMEPAGE","LICENSE"])
473 print "emerge: search: aux_get() failed, skipping"
476 print green("*")+" "+white(match)+" "+red("[ Masked ]")
478 print green("*")+" "+white(match)
479 myversion = self.getVersion(full_package, search.VERSION_RELEASE)
482 mycat = match.split("/")[0]
483 mypkg = match.split("/")[1]
484 mycpv = match + "-" + myversion
485 myebuild = self.portdb.findname(mycpv)
486 pkgdir = os.path.dirname(myebuild)
487 from portage import manifest
488 mf = manifest.Manifest(
489 pkgdir, self.settings["DISTDIR"])
490 fetchlist = self.portdb.getfetchlist(mycpv,
491 mysettings=self.settings, all=True)[1]
493 mysum[0] = mf.getDistfilesSize(fetchlist)
494 mystr = str(mysum[0]/1024)
498 mystr=mystr[:mycount]+","+mystr[mycount:]
501 mysum[0] = "Unknown (missing digest for %s)" % str(e)
504 print " ", darkgreen("Latest version available:"),myversion
505 print " ", self.getInstallationStatus(mycat+'/'+mypkg)
506 print " ", darkgreen("Size of files:"),mysum[0]
507 print " ", darkgreen("Homepage:")+" ",homepage
508 print " ", darkgreen("Description:")+" ",desc
509 print " ", darkgreen("License:")+" ",license
515 def getInstallationStatus(self,package):
516 installed_package = self.vartree.dep_bestmatch(package)
518 version = self.getVersion(installed_package,search.VERSION_RELEASE)
520 result = darkgreen("Latest version installed:")+" "+version
522 result = darkgreen("Latest version installed:")+" [ Not Installed ]"
525 def getVersion(self,full_package,detail):
526 if len(full_package) > 1:
527 package_parts = portage.catpkgsplit(full_package)
528 if detail == search.VERSION_RELEASE and package_parts[3] != 'r0':
529 result = package_parts[2]+ "-" + package_parts[3]
531 result = package_parts[2]
537 #build our package digraph
538 def getlist(settings, mode):
540 mylines = settings.packages
543 file_path = os.path.join(settings["ROOT"], portage.WORLD_FILE)
544 myfile = open(file_path, "r")
545 mylines = myfile.readlines()
547 except (OSError, IOError), e:
548 if e.errno == errno.ENOENT:
549 portage.writemsg("\n!!! World file does not exist: '%s'\n" % file_path)
555 myline=" ".join(x.split())
564 mynewlines.append(myline.strip())
568 def clean_world(vardb, cpv):
569 """Remove a package from the world file when unmerged."""
570 world_filename = os.path.join(vardb.root, portage.WORLD_FILE)
571 worldlist = portage.util.grabfile(world_filename)
572 mykey = portage.cpv_getkey(cpv)
575 if portage.dep_getkey(x) == mykey:
576 matches = vardb.match(x, use_cache=0)
580 elif len(matches) == 1 and matches[0] == cpv:
584 #others are around; keep it.
585 newworldlist.append(x)
587 #this doesn't match the package we're unmerging; keep it.
588 newworldlist.append(x)
590 portage.util.ensure_dirs(os.path.join(vardb.root, portage.PRIVATE_PATH),
591 gid=portage.portage_gid, mode=02770)
592 portage.util.write_atomic(world_filename, "\n".join(newworldlist))
594 def genericdict(mylist):
597 mynewdict[portage.dep_getkey(x)]=x
600 def filter_iuse_defaults(iuse):
602 if flag.startswith("+") or flag.startswith("-"):
607 class DepPriority(object):
609 This class generates an integer priority level based of various
610 attributes of the dependency relationship. Attributes can be assigned
611 at any time and the new integer value will be generated on calls to the
612 __int__() method. Rich comparison operators are supported.
614 The boolean attributes that affect the integer value are "satisfied",
615 "buildtime", "runtime", and "system". Various combinations of
616 attributes lead to the following priority levels:
618 Combination of properties Priority level
620 not satisfied and buildtime 0
621 not satisfied and runtime -1
622 satisfied and buildtime -2
623 satisfied and runtime -3
624 (none of the above) -4
626 Several integer constants are defined for categorization of priority
629 MEDIUM The upper boundary for medium dependencies.
630 SOFT The upper boundary for soft dependencies.
631 MIN The lower boundary for soft dependencies.
633 __slots__ = ("__weakref__", "satisfied", "buildtime", "runtime")
637 def __init__(self, **kwargs):
638 for myattr in self.__slots__:
639 if myattr == "__weakref__":
641 myvalue = kwargs.get(myattr, False)
642 setattr(self, myattr, myvalue)
644 if not self.satisfied:
654 def __lt__(self, other):
655 return self.__int__() < other
656 def __le__(self, other):
657 return self.__int__() <= other
658 def __eq__(self, other):
659 return self.__int__() == other
660 def __ne__(self, other):
661 return self.__int__() != other
662 def __gt__(self, other):
663 return self.__int__() > other
664 def __ge__(self, other):
665 return self.__int__() >= other
668 return copy.copy(self)
670 myvalue = self.__int__()
671 if myvalue > self.MEDIUM:
673 if myvalue > self.SOFT:
677 class FakeVartree(portage.vartree):
678 """This is implements an in-memory copy of a vartree instance that provides
679 all the interfaces required for use by the depgraph. The vardb is locked
680 during the constructor call just long enough to read a copy of the
681 installed package information. This allows the depgraph to do it's
682 dependency calculations without holding a lock on the vardb. It also
683 allows things like vardb global updates to be done in memory so that the
684 user doesn't necessarily need write access to the vardb in cases where
685 global updates are necessary (updates are performed when necessary if there
686 is not a matching ebuild in the tree)."""
687 def __init__(self, real_vartree, portdb):
688 self.root = real_vartree.root
689 self.settings = real_vartree.settings
690 self.dbapi = portage.fakedbapi(settings=real_vartree.settings)
691 vdb_path = os.path.join(self.root, portage.VDB_PATH)
693 # At least the parent needs to exist for the lock file.
694 portage.util.ensure_dirs(vdb_path)
695 except portage.exception.PortageException:
699 if os.access(vdb_path, os.W_OK):
700 vdb_lock = portage.locks.lockdir(vdb_path)
701 mykeys = ["SLOT", "COUNTER", "PROVIDE", "USE", "IUSE",
702 "DEPEND", "RDEPEND", "PDEPEND"]
703 real_dbapi = real_vartree.dbapi
705 for cpv in real_dbapi.cpv_all():
706 metadata = dict(izip(mykeys, real_dbapi.aux_get(cpv, mykeys)))
707 myslot = metadata["SLOT"]
708 mycp = portage.dep_getkey(cpv)
709 myslot_atom = "%s:%s" % (mycp, myslot)
711 mycounter = long(metadata["COUNTER"])
714 metadata["COUNTER"] = str(mycounter)
715 other_counter = slot_counters.get(myslot_atom, None)
716 if other_counter is not None:
717 if other_counter > mycounter:
719 slot_counters[myslot_atom] = mycounter
720 self.dbapi.cpv_inject(cpv, metadata=metadata)
721 real_dbapi.flush_cache()
724 portage.locks.unlockdir(vdb_lock)
725 # Populate the old-style virtuals using the cached values.
726 if not self.settings.treeVirtuals:
727 self.settings.treeVirtuals = portage.util.map_dictlist_vals(
728 portage.getCPFromCPV, self.get_all_provides())
730 # Intialize variables needed for lazy cache pulls of the live ebuild
731 # metadata. This ensures that the vardb lock is released ASAP, without
732 # being delayed in case cache generation is triggered.
733 self._aux_get = self.dbapi.aux_get
734 self.dbapi.aux_get = self._aux_get_wrapper
735 self._aux_get_history = set()
736 self._portdb_keys = ["DEPEND", "RDEPEND", "PDEPEND"]
737 self._portdb = portdb
738 self._global_updates = None
740 def _aux_get_wrapper(self, pkg, wants):
741 if pkg in self._aux_get_history:
742 return self._aux_get(pkg, wants)
743 self._aux_get_history.add(pkg)
745 # Use the live ebuild metadata if possible.
746 live_metadata = dict(izip(self._portdb_keys,
747 self._portdb.aux_get(pkg, self._portdb_keys)))
748 self.dbapi.aux_update(pkg, live_metadata)
749 except (KeyError, portage.exception.PortageException):
750 if self._global_updates is None:
751 self._global_updates = \
752 grab_global_updates(self._portdb.porttree_root)
753 perform_global_updates(
754 pkg, self.dbapi, self._global_updates)
755 return self._aux_get(pkg, wants)
757 def grab_global_updates(portdir):
758 from portage.update import grab_updates, parse_updates
759 updpath = os.path.join(portdir, "profiles", "updates")
761 rawupdates = grab_updates(updpath)
762 except portage.exception.DirectoryNotFound:
765 for mykey, mystat, mycontent in rawupdates:
766 commands, errors = parse_updates(mycontent)
767 upd_commands.extend(commands)
770 def perform_global_updates(mycpv, mydb, mycommands):
771 from portage.update import update_dbentries
772 aux_keys = ["DEPEND", "RDEPEND", "PDEPEND"]
773 aux_dict = dict(izip(aux_keys, mydb.aux_get(mycpv, aux_keys)))
774 updates = update_dbentries(mycommands, aux_dict)
776 mydb.aux_update(mycpv, updates)
778 class BlockerCache(DictMixin):
779 """This caches blockers of installed packages so that dep_check does not
780 have to be done for every single installed package on every invocation of
781 emerge. The cache is invalidated whenever it is detected that something
782 has changed that might alter the results of dep_check() calls:
783 1) the set of installed packages (including COUNTER) has changed
784 2) the old-style virtuals have changed
786 class BlockerData(object):
787 def __init__(self, counter, atoms):
788 self.counter = counter
791 def __init__(self, myroot, vardb):
793 self._installed_pkgs = set(vardb.cpv_all())
794 self._virtuals = vardb.settings.getvirtuals()
795 self._cache_filename = os.path.join(myroot,
796 portage.CACHE_PATH.lstrip(os.path.sep), "vdb_blockers.pickle")
797 self._cache_version = "1"
798 self._cache_data = None
799 self._modified = False
804 f = open(self._cache_filename)
805 mypickle = cPickle.Unpickler(f)
806 mypickle.find_global = None
807 self._cache_data = mypickle.load()
810 except (IOError, OSError, EOFError, cPickle.UnpicklingError):
812 cache_valid = self._cache_data and \
813 isinstance(self._cache_data, dict) and \
814 self._cache_data.get("version") == self._cache_version and \
815 self._cache_data.get("virtuals") == self._virtuals and \
816 set(self._cache_data.get("blockers", [])) == self._installed_pkgs
818 for pkg in self._installed_pkgs:
819 if long(self._vardb.aux_get(pkg, ["COUNTER"])[0]) != \
824 self._cache_data = {"version":self._cache_version}
825 self._cache_data["blockers"] = {}
826 self._cache_data["virtuals"] = self._virtuals
827 self._modified = False
830 """If the current user has permission and the internal blocker cache
831 been updated, save it to disk and mark it unmodified. This is called
832 by emerge after it has proccessed blockers for all installed packages.
833 Currently, the cache is only written if the user has superuser
834 privileges (since that's required to obtain a lock), but all users
835 have read access and benefit from faster blocker lookups (as long as
836 the entire cache is still valid). The cache is stored as a pickled
837 dict object with the following format:
841 "blockers" : {cpv1:(counter,(atom1, atom2...)), cpv2...},
842 "virtuals" : vardb.settings.getvirtuals()
845 if self._modified and \
848 f = portage.util.atomic_ofstream(self._cache_filename)
849 cPickle.dump(self._cache_data, f, -1)
851 portage.util.apply_secpass_permissions(
852 self._cache_filename, gid=portage.portage_gid, mode=0644)
853 except (IOError, OSError), e:
855 self._modified = False
857 def __setitem__(self, cpv, blocker_data):
859 Update the cache and mark it as modified for a future call to
862 @param cpv: Package for which to cache blockers.
864 @param blocker_data: An object with counter and atoms attributes.
865 @type blocker_data: BlockerData
867 self._cache_data["blockers"][cpv] = \
868 (blocker_data.counter, blocker_data.atoms)
869 self._modified = True
871 def __getitem__(self, cpv):
874 @returns: An object with counter and atoms attributes.
876 return self.BlockerData(*self._cache_data["blockers"][cpv])
878 def show_invalid_depstring_notice(parent_node, depstring, error_msg):
880 from formatter import AbstractFormatter, DumbWriter
881 f = AbstractFormatter(DumbWriter(maxcol=72))
883 print "\n\n!!! Invalid or corrupt dependency specification: "
891 p_type, p_root, p_key, p_status = parent_node
893 if p_status == "nomerge":
894 category, pf = portage.catsplit(p_key)
895 pkg_location = os.path.join(p_root, portage.VDB_PATH, category, pf)
896 msg.append("Portage is unable to process the dependencies of the ")
897 msg.append("'%s' package. " % p_key)
898 msg.append("In order to correct this problem, the package ")
899 msg.append("should be uninstalled, reinstalled, or upgraded. ")
900 msg.append("As a temporary workaround, the --nodeps option can ")
901 msg.append("be used to ignore all dependencies. For reference, ")
902 msg.append("the problematic dependencies can be found in the ")
903 msg.append("*DEPEND files located in '%s/'." % pkg_location)
905 msg.append("This package can not be installed. ")
906 msg.append("Please notify the '%s' package maintainer " % p_key)
907 msg.append("about this problem.")
910 f.add_flowing_data(x)
913 class depgraph(object):
918 "installed":"vartree"}
920 def __init__(self, settings, trees, myopts, myparams, spinner):
921 self.settings = settings
922 self.target_root = settings["ROOT"]
924 self.myparams = myparams
926 if settings.get("PORTAGE_DEBUG", "") == "1":
928 self.spinner = spinner
929 self.pkgsettings = {}
930 # Maps cpv to digraph node for all nodes added to the graph.
931 self.pkg_node_map = {}
932 # Maps slot atom to digraph node for all nodes added to the graph.
933 self._slot_node_map = {}
935 self._mydbapi_keys = ["SLOT", "DEPEND", "RDEPEND", "PDEPEND"]
939 self.trees[myroot] = {}
940 for tree in ("porttree", "bintree"):
941 self.trees[myroot][tree] = trees[myroot][tree]
942 self.trees[myroot]["vartree"] = \
943 FakeVartree(trees[myroot]["vartree"],
944 trees[myroot]["porttree"].dbapi)
945 self.pkgsettings[myroot] = portage.config(
946 clone=self.trees[myroot]["vartree"].settings)
947 self.pkg_node_map[myroot] = {}
948 self._slot_node_map[myroot] = {}
949 vardb = self.trees[myroot]["vartree"].dbapi
950 # This fakedbapi instance will model the state that the vdb will
951 # have after new packages have been installed.
952 fakedb = portage.fakedbapi(settings=self.pkgsettings[myroot])
953 self.mydbapi[myroot] = fakedb
954 if "--nodeps" not in self.myopts and \
955 "--buildpkgonly" not in self.myopts:
956 # --nodeps bypasses this, since it isn't needed in this case
957 # and the cache pulls might trigger (slow) cache generation.
958 for pkg in vardb.cpv_all():
959 self.spinner.update()
960 fakedb.cpv_inject(pkg,
961 metadata=dict(izip(self._mydbapi_keys,
962 vardb.aux_get(pkg, self._mydbapi_keys))))
964 self.useFlags[myroot] = {}
965 if "--usepkg" in self.myopts:
966 self.trees[myroot]["bintree"].populate(
967 "--getbinpkg" in self.myopts,
968 "--getbinpkgonly" in self.myopts)
972 self.digraph=portage.digraph()
973 # Tracks simple parent/child relationships (PDEPEND relationships are
975 self._parent_child_digraph = digraph()
977 self.outdatedpackages=[]
979 self.blocker_digraph = digraph()
980 self.blocker_parents = {}
981 self._unresolved_blocker_parents = {}
982 self._slot_collision_info = []
983 # Slot collision nodes are not allowed to block other packages since
984 # blocker validation is only able to account for one package per slot.
985 self._slot_collision_nodes = set()
986 self._altlist_cache = {}
987 self._pprovided_args = []
989 def _show_slot_collision_notice(self, packages):
990 """Show an informational message advising the user to mask one of the
991 the packages. In some cases it may be possible to resolve this
992 automatically, but support for backtracking (removal nodes that have
993 already been selected) will be required in order to handle all possible
997 msg.append("\n!!! Multiple versions within a single " + \
998 "package slot have been \n")
999 msg.append("!!! pulled into the dependency graph:\n\n")
1000 for node, parents in packages:
1001 msg.append(str(node))
1003 msg.append(" pulled in by\n")
1004 for parent in parents:
1006 msg.append(str(parent))
1009 msg.append(" (no parents)\n")
1011 sys.stderr.write("".join(msg))
1014 if "--quiet" in self.myopts:
1018 msg.append("It may be possible to solve this problem ")
1019 msg.append("by using package.mask to prevent one of ")
1020 msg.append("those packages from being selected. ")
1021 msg.append("However, it is also possible that conflicting ")
1022 msg.append("dependencies exist such that they are impossible to ")
1023 msg.append("satisfy simultaneously. If such a conflict exists in ")
1024 msg.append("the dependencies of two different packages, then those ")
1025 msg.append("packages can not be installed simultaneously.")
1027 from formatter import AbstractFormatter, DumbWriter
1028 f = AbstractFormatter(DumbWriter(sys.stderr, maxcol=72))
1030 f.add_flowing_data(x)
1034 msg.append("For more information, see MASKED PACKAGES ")
1035 msg.append("section in the emerge man page or refer ")
1036 msg.append("to the Gentoo Handbook.")
1038 f.add_flowing_data(x)
1042 def create(self, mybigkey, myparent=None, addme=1, myuse=None,
1043 priority=DepPriority(), rev_dep=False, arg=None):
1045 Fills the digraph with nodes comprised of packages to merge.
1046 mybigkey is the package spec of the package to merge.
1047 myparent is the package depending on mybigkey ( or None )
1048 addme = Should we add this package to the digraph or are we just looking at it's deps?
1049 Think --onlydeps, we need to ignore packages in that case.
1052 #IUSE-aware emerge -> USE DEP aware depgraph
1053 #"no downgrade" emerge
1055 mytype, myroot, mykey = mybigkey
1056 existing_node = None
1058 existing_node = self.pkg_node_map[myroot].get(mykey)
1060 self._parent_child_digraph.add(existing_node, myparent)
1061 if existing_node != myparent:
1062 # Refuse to make a node depend on itself so that the we don't
1063 # don't create a bogus circular dependency in self.altlist().
1064 if rev_dep and myparent:
1065 self.digraph.addnode(myparent, existing_node,
1068 self.digraph.addnode(existing_node, myparent,
1072 if "--nodeps" not in self.myopts:
1073 self.spinner.update()
1074 if mytype == "blocks":
1076 "--buildpkgonly" not in self.myopts and \
1077 "--nodeps" not in self.myopts and \
1078 myparent not in self._slot_collision_nodes:
1079 mybigkey[1] = myparent[1]
1080 self.blocker_parents.setdefault(
1081 tuple(mybigkey), set()).add(myparent)
1084 # select the correct /var database that we'll be checking against
1085 vardbapi = self.trees[myroot]["vartree"].dbapi
1086 portdb = self.trees[myroot]["porttree"].dbapi
1087 bindb = self.trees[myroot]["bintree"].dbapi
1088 pkgsettings = self.pkgsettings[myroot]
1090 # if the package is already on the system, we add a "nomerge"
1091 # directive, otherwise we add a "merge" directive.
1093 mydbapi = self.trees[myroot][self.pkg_tree_map[mytype]].dbapi
1095 if not arg and myroot == self.target_root:
1096 cpv_slot = "%s:%s" % (mykey, mydbapi.aux_get(mykey, ["SLOT"])[0])
1097 arg = portage.best_match_to_list(cpv_slot, self.args_keys)
1100 self.pkgsettings[myroot].setcpv(mykey, mydb=portdb)
1101 myuse = self.pkgsettings[myroot]["USE"].split()
1104 if mytype == "installed":
1106 if addme and mytype != "installed":
1107 # this is where we add the node to the list of packages to merge
1108 if "selective" in self.myparams or not arg:
1109 if "empty" not in self.myparams and vardbapi.cpv_exists(mykey):
1112 """ If we aren't merging, perform the --newuse check.
1113 If the package has new iuse flags or different use flags then if
1114 --newuse is specified, we need to merge the package. """
1115 if merging==0 and "--newuse" in self.myopts and \
1116 vardbapi.cpv_exists(mykey):
1117 pkgsettings.setcpv(mykey, mydb=mydbapi)
1118 forced_flags = set()
1119 forced_flags.update(pkgsettings.useforce)
1120 forced_flags.update(pkgsettings.usemask)
1121 old_use = vardbapi.aux_get(mykey, ["USE"])[0].split()
1122 iuses = set(filter_iuse_defaults(
1123 mydbapi.aux_get(mykey, ["IUSE"])[0].split()))
1124 old_iuse = set(filter_iuse_defaults(
1125 vardbapi.aux_get(mykey, ["IUSE"])[0].split()))
1126 if iuses.symmetric_difference(
1127 old_iuse).difference(forced_flags):
1129 elif old_iuse.intersection(old_use) != \
1130 iuses.intersection(myuse):
1133 if addme and merging == 1:
1134 mybigkey.append("merge")
1136 mybigkey.append("nomerge")
1137 jbigkey = tuple(mybigkey)
1140 metadata = dict(izip(self._mydbapi_keys,
1141 mydbapi.aux_get(mykey, self._mydbapi_keys)))
1142 if merging == 0 and vardbapi.cpv_exists(mykey) and \
1143 mytype != "installed":
1144 mybigkey[0] = "installed"
1146 jbigkey = tuple(mybigkey)
1147 metadata = dict(izip(self._mydbapi_keys,
1148 mydbapi.aux_get(mykey, self._mydbapi_keys)))
1149 myuse = mydbapi.aux_get(mykey, ["USE"])[0].split()
1150 slot_atom = "%s:%s" % (portage.dep_getkey(mykey), metadata["SLOT"])
1151 existing_node = self._slot_node_map[myroot].get(
1153 slot_collision = False
1155 e_type, myroot, e_cpv, e_status = existing_node
1157 # The existing node can be reused.
1158 self._parent_child_digraph.add(existing_node, myparent)
1159 if rev_dep and myparent:
1160 ptype, proot, pkey, pstatus = myparent
1161 self.digraph.addnode(myparent, existing_node,
1164 self.digraph.addnode(existing_node, myparent,
1168 # A slot collision has occurred. Sometimes this coincides
1169 # with unresolvable blockers, so the slot collision will be
1170 # shown later if there are no unresolvable blockers.
1171 e_parents = self._parent_child_digraph.parent_nodes(
1175 myparents.append(myparent)
1176 self._slot_collision_info.append(
1177 ((jbigkey, myparents), (existing_node, e_parents)))
1178 self._slot_collision_nodes.add(jbigkey)
1179 slot_collision = True
1182 # Now add this node to the graph so that self.display()
1183 # can show use flags and --tree portage.output. This node is
1184 # only being partially added to the graph. It must not be
1185 # allowed to interfere with the other nodes that have been
1186 # added. Do not overwrite data for existing nodes in
1187 # self.pkg_node_map and self.mydbapi since that data will
1188 # be used for blocker validation.
1189 self.pkg_node_map[myroot].setdefault(mykey, jbigkey)
1190 self.useFlags[myroot].setdefault(mykey, myuse)
1191 # Even though the graph is now invalid, continue to process
1192 # dependencies so that things like --fetchonly can still
1193 # function despite collisions.
1195 self.mydbapi[myroot].cpv_inject(mykey, metadata=metadata)
1196 self._slot_node_map[myroot][slot_atom] = jbigkey
1197 self.pkg_node_map[myroot][mykey] = jbigkey
1198 self.useFlags[myroot][mykey] = myuse
1200 if rev_dep and myparent:
1201 self.digraph.addnode(myparent, jbigkey,
1204 self.digraph.addnode(jbigkey, myparent,
1207 # Do this even when addme is False (--onlydeps) so that the
1208 # parent/child relationship is always known in case
1209 # self._show_slot_collision_notice() needs to be called later.
1210 self._parent_child_digraph.add(jbigkey, myparent)
1212 """ This section determines whether we go deeper into dependencies or not.
1213 We want to go deeper on a few occasions:
1214 Installing package A, we need to make sure package A's deps are met.
1215 emerge --deep <pkgspec>; we need to recursively check dependencies of pkgspec
1216 If we are in --nodeps (no recursion) mode, we obviously only check 1 level of dependencies.
1218 if "deep" not in self.myparams and not merging and \
1219 not ("--update" in self.myopts and arg and merging):
1221 elif "recurse" not in self.myparams:
1224 """ Check DEPEND/RDEPEND/PDEPEND/SLOT
1225 Pull from bintree if it's binary package, porttree if it's ebuild.
1226 Binpkg's can be either remote or local. """
1229 depkeys = ["DEPEND","RDEPEND","PDEPEND"]
1230 depvalues = mydbapi.aux_get(mykey, depkeys)
1231 for i in xrange(len(depkeys)):
1232 edepend[depkeys[i]] = depvalues[i]
1234 if mytype == "ebuild":
1235 if "--buildpkgonly" in self.myopts:
1236 edepend["RDEPEND"] = ""
1237 edepend["PDEPEND"] = ""
1238 if not (arg and "--onlydeps" in self.myopts and \
1239 mytype == "ebuild") and \
1240 self.myopts.get("--with-bdeps", "n") == "n" and \
1241 (mytype == "binary" or mybigkey[3] == "nomerge"):
1242 edepend["DEPEND"] = ""
1244 """ We have retrieve the dependency information, now we need to recursively
1245 process them. DEPEND gets processed for root = "/", {R,P}DEPEND in myroot. """
1247 mp = tuple(mybigkey)
1250 if not self.select_dep("/", edepend["DEPEND"], myparent=mp,
1251 myuse=myuse, priority=DepPriority(buildtime=True),
1254 """RDEPEND is soft by definition. However, in order to ensure
1255 correct merge order, we make it a hard dependency. Otherwise, a
1256 build time dependency might not be usable due to it's run time
1257 dependencies not being installed yet.
1259 if not self.select_dep(myroot,edepend["RDEPEND"], myparent=mp,
1260 myuse=myuse, priority=DepPriority(runtime=True),
1263 if edepend.has_key("PDEPEND") and edepend["PDEPEND"]:
1264 # Post Depend -- Add to the list without a parent, as it depends
1265 # on a package being present AND must be built after that package.
1266 if not self.select_dep(myroot, edepend["PDEPEND"], myparent=mp,
1267 myuse=myuse, priority=DepPriority(), rev_deps=True,
1270 except ValueError, e:
1272 portage.writemsg("\n\n!!! An atom in the dependencies " + \
1273 "is not fully-qualified. Multiple matches:\n\n", noiselevel=-1)
1275 portage.writemsg(" %s\n" % cpv, noiselevel=-1)
1276 portage.writemsg("\n", noiselevel=-1)
1277 if mytype == "binary":
1279 "!!! This binary package cannot be installed: '%s'\n" % \
1280 mykey, noiselevel=-1)
1281 elif mytype == "ebuild":
1282 myebuild, mylocation = portdb.findname2(mykey)
1283 portage.writemsg("!!! This ebuild cannot be installed: " + \
1284 "'%s'\n" % myebuild, noiselevel=-1)
1285 portage.writemsg("!!! Please notify the package maintainer " + \
1286 "that atoms must be fully-qualified.\n", noiselevel=-1)
1290 def select_files(self,myfiles):
1291 "given a list of .tbz2s, .ebuilds and deps, create the appropriate depgraph and return a favorite list"
1293 myroot = self.target_root
1294 portdb = self.trees[myroot]["porttree"].dbapi
1295 bindb = self.trees[myroot]["bintree"].dbapi
1296 pkgsettings = self.pkgsettings[myroot]
1298 def visible(mylist):
1299 matches = portdb.gvisible(portdb.visible(mylist))
1300 return [x for x in mylist \
1301 if x in matches or not portdb.cpv_exists(x)]
1303 ext = os.path.splitext(x)[1]
1305 if not os.path.exists(x):
1307 os.path.join(pkgsettings["PKGDIR"], "All", x)):
1308 x = os.path.join(pkgsettings["PKGDIR"], "All", x)
1309 elif os.path.exists(
1310 os.path.join(pkgsettings["PKGDIR"], x)):
1311 x = os.path.join(pkgsettings["PKGDIR"], x)
1313 print "\n\n!!! Binary package '"+str(x)+"' does not exist."
1314 print "!!! Please ensure the tbz2 exists as specified.\n"
1316 mytbz2=portage.xpak.tbz2(x)
1317 mykey=mytbz2.getelements("CATEGORY")[0]+"/"+os.path.splitext(os.path.basename(x))[0]
1318 if os.path.realpath(x) != \
1319 os.path.realpath(self.trees[myroot]["bintree"].getname(mykey)):
1320 print colorize("BAD", "\n*** You need to adjust PKGDIR to emerge this package.\n")
1322 if not self.create(["binary", myroot, mykey],
1323 None, "--onlydeps" not in self.myopts):
1324 return (0,myfavorites)
1325 elif not "--oneshot" in self.myopts:
1326 myfavorites.append(mykey)
1327 elif ext==".ebuild":
1328 x = os.path.realpath(x)
1329 mykey=os.path.basename(os.path.normpath(x+"/../.."))+"/"+os.path.splitext(os.path.basename(x))[0]
1330 ebuild_path = portdb.findname(mykey)
1332 if os.path.realpath(ebuild_path) != x:
1333 print colorize("BAD", "\n*** You need to adjust PORTDIR or PORTDIR_OVERLAY to emerge this package.\n")
1335 if mykey not in portdb.xmatch(
1336 "match-visible", portage.dep_getkey(mykey)):
1337 print colorize("BAD", "\n*** You are emerging a masked package. It is MUCH better to use")
1338 print colorize("BAD", "*** /etc/portage/package.* to accomplish this. See portage(5) man")
1339 print colorize("BAD", "*** page for details.")
1340 countdown(int(self.settings["EMERGE_WARNING_DELAY"]),
1343 raise portage.exception.PackageNotFound(
1344 "%s is not in a valid portage tree hierarchy or does not exist" % x)
1345 if not self.create(["ebuild", myroot, mykey],
1346 None, "--onlydeps" not in self.myopts):
1347 return (0,myfavorites)
1348 elif not "--oneshot" in self.myopts:
1349 myfavorites.append(mykey)
1351 if not is_valid_package_atom(x):
1352 portage.writemsg("\n\n!!! '%s' is not a valid package atom.\n" % x,
1354 portage.writemsg("!!! Please check ebuild(5) for full details.\n")
1355 portage.writemsg("!!! (Did you specify a version but forget to prefix with '='?)\n")
1359 if "--usepkg" in self.myopts:
1360 mykey = portage.dep_expand(x, mydb=bindb,
1361 settings=pkgsettings)
1362 if (mykey and not mykey.startswith("null/")) or \
1363 "--usepkgonly" in self.myopts:
1364 arg_atoms.append((x, mykey))
1367 mykey = portage.dep_expand(x,
1368 mydb=portdb, settings=pkgsettings)
1369 arg_atoms.append((x, mykey))
1370 except ValueError, errpkgs:
1371 print "\n\n!!! The short ebuild name \"" + x + "\" is ambiguous. Please specify"
1372 print "!!! one of the following fully-qualified ebuild names instead:\n"
1373 for i in errpkgs[0]:
1374 print " " + green(i)
1378 if "--update" in self.myopts:
1379 """Make sure all installed slots are updated when possible. Do this
1380 with --emptytree also, to ensure that all slots are remerged."""
1381 vardb = self.trees[self.target_root]["vartree"].dbapi
1383 for myarg, myatom in arg_atoms:
1384 greedy_atoms.append((myarg, myatom))
1386 for cpv in vardb.match(myatom):
1387 myslots.add(vardb.aux_get(cpv, ["SLOT"])[0])
1390 if "--usepkg" in self.myopts:
1391 mymatches = bindb.match(myatom)
1392 if "--usepkgonly" not in self.myopts:
1393 mymatches = visible(mymatches)
1394 best_pkg = portage.best(mymatches)
1396 best_slot = bindb.aux_get(best_pkg, ["SLOT"])[0]
1397 best_pkgs.append(("binary", best_pkg, best_slot))
1398 if "--usepkgonly" not in self.myopts:
1399 best_pkg = portage.best(portdb.match(myatom))
1401 best_slot = portdb.aux_get(best_pkg, ["SLOT"])[0]
1402 best_pkgs.append(("ebuild", best_pkg, best_slot))
1404 best_pkg = portage.best([x[1] for x in best_pkgs])
1405 best_pkgs = [x for x in best_pkgs if x[1] == best_pkg]
1406 best_slot = best_pkgs[0][2]
1407 myslots.add(best_slot)
1408 if len(myslots) > 1:
1409 for myslot in myslots:
1410 myslot_atom = "%s:%s" % \
1411 (portage.dep_getkey(myatom), myslot)
1413 if "--usepkgonly" not in self.myopts and \
1414 self.trees[self.target_root][
1415 "porttree"].dbapi.match(myslot_atom):
1417 elif "--usepkg" in self.myopts:
1418 mymatches = bindb.match(myslot_atom)
1419 if "--usepkgonly" not in self.myopts:
1420 mymatches = visible(mymatches)
1424 greedy_atoms.append((myarg, myslot_atom))
1425 arg_atoms = greedy_atoms
1427 """ These are used inside self.create() in order to ensure packages
1428 that happen to match arguments are not incorrectly marked as nomerge."""
1429 self.args_keys = [x[1] for x in arg_atoms]
1430 for myarg, myatom in arg_atoms:
1432 self.mysd = self.select_dep(myroot, myatom, arg=myarg)
1433 except portage.exception.MissingSignature, e:
1434 portage.writemsg("\n\n!!! A missing gpg signature is preventing portage from calculating the\n")
1435 portage.writemsg("!!! required dependencies. This is a security feature enabled by the admin\n")
1436 portage.writemsg("!!! to aid in the detection of malicious intent.\n\n")
1437 portage.writemsg("!!! THIS IS A POSSIBLE INDICATION OF TAMPERED FILES -- CHECK CAREFULLY.\n")
1438 portage.writemsg("!!! Affected file: %s\n" % (e), noiselevel=-1)
1440 except portage.exception.InvalidSignature, e:
1441 portage.writemsg("\n\n!!! An invalid gpg signature is preventing portage from calculating the\n")
1442 portage.writemsg("!!! required dependencies. This is a security feature enabled by the admin\n")
1443 portage.writemsg("!!! to aid in the detection of malicious intent.\n\n")
1444 portage.writemsg("!!! THIS IS A POSSIBLE INDICATION OF TAMPERED FILES -- CHECK CAREFULLY.\n")
1445 portage.writemsg("!!! Affected file: %s\n" % (e), noiselevel=-1)
1447 except SystemExit, e:
1448 raise # Needed else can't exit
1449 except Exception, e:
1450 print >> sys.stderr, "\n\n!!! Problem in '%s' dependencies." % mykey
1451 print >> sys.stderr, "!!!", str(e), getattr(e, "__module__", None)
1455 return (0,myfavorites)
1456 elif not "--oneshot" in self.myopts:
1457 mykey = portage.dep_getkey(myatom)
1458 if mykey not in myfavorites:
1459 myfavorites.append(mykey)
1462 if "--usepkgonly" in self.myopts:
1463 for xs in self.digraph.all_nodes():
1464 if len(xs) >= 4 and xs[0] != "binary" and xs[3] == "merge":
1468 print "Missing binary for:",xs[2]
1470 if not self.validate_blockers():
1471 return False, myfavorites
1473 # We're true here unless we are missing binaries.
1474 return (not missing,myfavorites)
1476 def select_dep(self, myroot, depstring, myparent=None, arg=None,
1477 myuse=None, raise_on_missing=False, priority=DepPriority(),
1478 rev_deps=False, parent_arg=None):
1479 """ Given a depstring, create the depgraph such that all dependencies are satisfied.
1480 myroot = $ROOT from environment, where {R,P}DEPENDs are merged to.
1481 myparent = the node whose depstring is being passed in
1482 arg = package was specified on the command line, merge even if it's already installed
1483 myuse = USE flags at present
1484 raise_on_missing = Given that the depgraph is not proper, raise an exception if true
1485 else continue trying.
1486 return 1 on success, 0 for failure
1489 portdb = self.trees[myroot]["porttree"].dbapi
1490 bindb = self.trees[myroot]["bintree"].dbapi
1491 vardb = self.trees[myroot]["vartree"].dbapi
1492 pkgsettings = self.pkgsettings[myroot]
1494 p_type, p_root, p_key, p_status = myparent
1496 if "--debug" in self.myopts:
1498 print "Parent: ",myparent
1499 print "Depstring:",depstring
1501 print "Reverse:", rev_deps
1502 print "Priority:", priority
1504 #processing dependencies
1505 """ Call portage.dep_check to evaluate the use? conditionals and make sure all
1506 dependencies are satisfiable. """
1508 mymerge = [depstring]
1509 pprovided = pkgsettings.pprovideddict.get(
1510 portage.dep_getkey(depstring))
1511 if pprovided and portage.match_from_list(depstring, pprovided):
1515 if myparent and p_status == "nomerge":
1516 portage.dep._dep_check_strict = False
1517 mycheck = portage.dep_check(depstring, None,
1518 pkgsettings, myuse=myuse,
1519 use_binaries=("--usepkgonly" in self.myopts),
1520 myroot=myroot, trees=self.trees)
1522 portage.dep._dep_check_strict = True
1526 show_invalid_depstring_notice(
1527 myparent, depstring, mycheck[1])
1529 sys.stderr.write("\n%s\n%s\n" % (depstring, mycheck[1]))
1531 mymerge = mycheck[1]
1533 if not mymerge and arg and \
1534 portage.best_match_to_list(depstring, self.args_keys):
1535 # A provided package has been specified on the command line. The
1536 # package will not be merged and a warning will be displayed.
1537 self._pprovided_args.append(arg)
1540 # The parent is added after it's own dep_check call so that it
1541 # isn't allowed to satisfy a direct bootstrap dependency on itself
1542 # via an old-style virtual. This isn't a problem with new-style
1543 # virtuals, which are preferenced in dep_zapdeps by looking only at
1544 # the depstring, vdb, and available packages.
1546 p_type, p_root, p_key, p_status = myparent
1547 if p_status == "merge":
1548 # Update old-style virtuals if this package provides any.
1549 # These are needed for dep_virtual calls inside dep_check.
1550 p_db = self.trees[p_root][self.pkg_tree_map[p_type]].dbapi
1552 self.pkgsettings[p_root].setinst(p_key, p_db)
1553 except portage.exception.InvalidDependString, e:
1554 provide = p_db.aux_get(p_key, ["PROVIDE"])[0]
1555 show_invalid_depstring_notice(myparent, provide, str(e))
1559 if "--debug" in self.myopts:
1560 print "Candidates:",mymerge
1564 selected_pkg = ["blocks", myroot, x[1:], None]
1566 #We are not processing a blocker but a normal dependency
1568 """In some cases, dep_check will return deps that shouldn't
1569 be proccessed any further, so they are identified and
1571 if "empty" not in self.myparams and \
1572 "deep" not in self.myparams and \
1573 not ("--update" in self.myopts and parent_arg) and \
1577 # List of acceptable packages, ordered by type preference.
1578 matched_packages = []
1579 myeb_matches = portdb.xmatch("match-visible", x)
1581 if "--usepkgonly" not in self.myopts:
1582 myeb = portage.best(myeb_matches)
1585 if "--usepkg" in self.myopts:
1586 # The next line assumes the binarytree has been populated.
1587 # XXX: Need to work out how we use the binary tree with roots.
1588 myeb_pkg_matches = bindb.match(x)
1589 if "--usepkgonly" not in self.myopts:
1590 # Remove any binary package entries that are masked in the portage tree (#55871)
1591 myeb_pkg_matches = [pkg for pkg in myeb_pkg_matches \
1592 if pkg in myeb_matches or \
1593 not portdb.cpv_exists(pkg)]
1594 if myeb_pkg_matches:
1595 myeb_pkg = portage.best(myeb_pkg_matches)
1597 if myeb_pkg and "--newuse" in self.myopts:
1598 iuses = set(filter_iuse_defaults(
1599 bindb.aux_get(myeb_pkg, ["IUSE"])[0].split()))
1600 old_use = bindb.aux_get(myeb_pkg, ["USE"])[0].split()
1602 if "--usepkgonly" not in self.myopts and myeb:
1605 pkgsettings.setcpv(myeb, mydb=mydb)
1607 pkgsettings.setcpv(myeb_pkg, mydb=mydb)
1608 now_use = pkgsettings["USE"].split()
1609 forced_flags = set()
1610 forced_flags.update(pkgsettings.useforce)
1611 forced_flags.update(pkgsettings.usemask)
1613 if "--usepkgonly" not in self.myopts and myeb:
1614 cur_iuse = set(filter_iuse_defaults(
1615 portdb.aux_get(myeb, ["IUSE"])[0].split()))
1616 if iuses.symmetric_difference(
1617 cur_iuse).difference(forced_flags):
1619 elif iuses.intersection(old_use) != \
1620 cur_iuse.intersection(now_use):
1624 self.trees[myroot]["bintree"].dbapi.aux_get(
1625 myeb_pkg, ["USE"])[0].split()
1626 matched_packages.append(
1627 ["binary", myroot, myeb_pkg, binpkguseflags])
1629 if "--usepkgonly" not in self.myopts and myeb_matches:
1630 matched_packages.append(
1631 ["ebuild", myroot, myeb, None])
1633 if not matched_packages and \
1634 not (arg and "selective" not in self.myparams):
1635 """Fall back to the installed package database. This is a
1636 last resort because the metadata tends to diverge from that
1637 of the ebuild in the tree."""
1638 myeb_inst_matches = vardb.match(x)
1639 if "--usepkgonly" not in self.myopts:
1640 """ TODO: Improve masking check for installed and
1641 binary packages. bug #149816"""
1642 myeb_inst_matches = [pkg for pkg in myeb_inst_matches \
1643 if not portdb.cpv_exists(pkg)]
1645 if myeb_inst_matches:
1646 myeb_inst = portage.best(myeb_inst_matches)
1648 binpkguseflags = vardb.aux_get(
1649 myeb_inst, ["USE"])[0].split()
1650 matched_packages.append(
1651 ["installed", myroot, myeb_inst, binpkguseflags])
1653 if not matched_packages:
1654 if raise_on_missing:
1661 xfrom = '(dependency required by '+ \
1662 green('"%s"' % myparent[2]) + \
1663 red(' [%s]' % myparent[0]) + ')'
1664 alleb = portdb.xmatch("match-all", x)
1666 if "--usepkgonly" not in self.myopts:
1667 print "\n!!! "+red("All ebuilds that could satisfy ")+green(xinfo)+red(" have been masked.")
1668 print "!!! One of the following masked packages is required to complete your request:"
1672 mreasons = portage.getmaskingstatus(p,
1673 settings=pkgsettings, portdb=portdb)
1674 print "- "+p+" (masked by: "+", ".join(mreasons)+")"
1675 if "package.mask" in mreasons:
1676 comment, filename = \
1677 portage.getmaskingreason(p,
1678 settings=pkgsettings, portdb=portdb,
1679 return_location=True)
1680 if comment and comment != oldcomment:
1683 oldcomment = comment
1685 licenses = portdb.aux_get(p, ["LICENSE"])[0]
1687 # Corruption will have been reported above.
1691 pkgsettings.setcpv(p, mydb=portdb)
1692 uselist = pkgsettings.get("USE", "").split()
1693 missing_licenses = []
1695 missing_licenses = \
1696 pkgsettings.getMissingLicenses(
1697 licenses, p, uselist)
1698 except portage.exception.InvalidDependString:
1699 # This will have already been reported
1700 # above via mreasons.
1702 for l in missing_licenses:
1703 l_path = portdb.findLicensePath(l)
1704 if l in shown_licenses:
1706 msg = ("A copy of the '%s' license" + \
1707 " is located at '%s'.") % (l, l_path)
1710 shown_licenses.append(l)
1712 print "For more information, see MASKED PACKAGES section in the emerge man page or "
1713 print "refer to the Gentoo Handbook."
1715 print "\n!!! "+red("There are no packages available to satisfy: ")+green(xinfo)
1716 print "!!! Either add a suitable binary package or compile from an ebuild."
1718 print "\nemerge: there are no ebuilds to satisfy "+green(xinfo)+"."
1724 if "--debug" in self.myopts:
1725 for pkg in matched_packages:
1726 print (pkg[0] + ":").rjust(10), pkg[2]
1728 if len(matched_packages) > 1:
1729 bestmatch = portage.best(
1730 [pkg[2] for pkg in matched_packages])
1731 matched_packages = [pkg for pkg in matched_packages \
1732 if pkg[2] == bestmatch]
1734 # ordered by type preference ("ebuild" type is the last resort)
1735 selected_pkg = matched_packages[0]
1736 pkgtype, myroot, mycpv, myuse = selected_pkg
1737 mydbapi = self.trees[myroot][self.pkg_tree_map[pkgtype]].dbapi
1738 slot_atom = "%s:%s" % (portage.dep_getkey(mycpv),
1739 mydbapi.aux_get(mycpv, ["SLOT"])[0])
1740 existing_node = self._slot_node_map[myroot].get(
1743 e_type, myroot, e_cpv, e_status = existing_node
1744 if portage.match_from_list(x, [e_cpv]):
1745 # The existing node can be reused.
1746 selected_pkg = [e_type, myroot, e_cpv,
1747 self.useFlags[myroot][e_cpv]]
1750 #we are a dependency, so we want to be unconditionally added
1751 mypriority = priority.copy()
1753 mypriority.satisfied = True
1754 if not self.create(selected_pkg[0:3], myparent,
1755 myuse=selected_pkg[-1], priority=mypriority,
1756 rev_dep=rev_deps, arg=arg):
1759 #if mysource is not set, then we are a command-line dependency and should not be added
1760 #if --onlydeps is specified.
1761 if not self.create(selected_pkg[0:3], myparent,
1762 addme=("--onlydeps" not in self.myopts),
1763 myuse=selected_pkg[-1], rev_dep=rev_deps, arg=arg):
1766 if "--debug" in self.myopts:
1767 print "Exiting...",myparent
1770 def validate_blockers(self):
1771 """Remove any blockers from the digraph that do not match any of the
1772 packages within the graph. If necessary, create hard deps to ensure
1773 correct merge order such that mutually blocking packages are never
1774 installed simultaneously."""
1776 if "--buildpkgonly" in self.myopts or \
1777 "--nodeps" in self.myopts:
1781 for myroot in self.trees:
1783 modified_slots[myroot] = myslots
1784 final_db = self.mydbapi[myroot]
1785 slot_node_map = self._slot_node_map[myroot]
1786 for slot_atom, mynode in slot_node_map.iteritems():
1787 mytype, myroot, mycpv, mystatus = mynode
1788 if mystatus == "merge":
1789 myslots[slot_atom] = mycpv
1791 #if "deep" in self.myparams:
1793 # Pull in blockers from all installed packages that haven't already
1794 # been pulled into the depgraph. This is not enabled by default
1795 # due to the performance penalty that is incurred by all the
1796 # additional dep_check calls that are required.
1798 # Optimization hack for dep_check calls that minimizes the
1799 # available matches by replacing the portdb with a fakedbapi
1801 class FakePortageTree(object):
1802 def __init__(self, mydb):
1804 dep_check_trees = {}
1805 for myroot in self.trees:
1806 dep_check_trees[myroot] = self.trees[myroot].copy()
1807 dep_check_trees[myroot]["porttree"] = \
1808 FakePortageTree(self.mydbapi[myroot])
1810 dep_keys = ["DEPEND","RDEPEND","PDEPEND"]
1811 for myroot in self.trees:
1812 pkg_node_map = self.pkg_node_map[myroot]
1813 vardb = self.trees[myroot]["vartree"].dbapi
1814 portdb = self.trees[myroot]["porttree"].dbapi
1815 pkgsettings = self.pkgsettings[myroot]
1816 final_db = self.mydbapi[myroot]
1817 cpv_all_installed = self.trees[myroot]["vartree"].dbapi.cpv_all()
1818 blocker_cache = BlockerCache(myroot, vardb)
1819 for pkg in cpv_all_installed:
1820 blocker_atoms = None
1821 matching_node = pkg_node_map.get(pkg, None)
1822 if matching_node and \
1823 matching_node[3] == "nomerge":
1825 # If this node has any blockers, create a "nomerge"
1826 # node for it so that they can be enforced.
1827 self.spinner.update()
1828 blocker_data = blocker_cache.get(pkg)
1830 blocker_atoms = blocker_data.atoms
1832 dep_vals = vardb.aux_get(pkg, dep_keys)
1833 myuse = vardb.aux_get(pkg, ["USE"])[0].split()
1834 depstr = " ".join(dep_vals)
1835 # It is crucial to pass in final_db here in order to
1836 # optimize dep_check calls by eliminating atoms via
1837 # dep_wordreduce and dep_eval calls.
1839 portage.dep._dep_check_strict = False
1841 success, atoms = portage.dep_check(depstr,
1842 final_db, pkgsettings, myuse=myuse,
1843 trees=dep_check_trees, myroot=myroot)
1844 except Exception, e:
1845 if isinstance(e, SystemExit):
1847 # This is helpful, for example, if a ValueError
1848 # is thrown from cpv_expand due to multiple
1849 # matches (this can happen if an atom lacks a
1851 show_invalid_depstring_notice(
1852 ("installed", myroot, pkg, "nomerge"),
1857 portage.dep._dep_check_strict = True
1859 slot_atom = "%s:%s" % (portage.dep_getkey(pkg),
1860 vardb.aux_get(pkg, ["SLOT"])[0])
1861 if slot_atom in modified_slots[myroot]:
1862 # This package is being replaced anyway, so
1863 # ignore invalid dependencies so as not to
1864 # annoy the user too much (otherwise they'd be
1865 # forced to manually unmerge it first).
1867 show_invalid_depstring_notice(
1868 ("installed", myroot, pkg, "nomerge"),
1871 blocker_atoms = [myatom for myatom in atoms \
1872 if myatom.startswith("!")]
1873 counter = long(vardb.aux_get(pkg, ["COUNTER"])[0])
1874 blocker_cache[pkg] = \
1875 blocker_cache.BlockerData(counter, blocker_atoms)
1877 # Don't store this parent in pkg_node_map, because it's
1878 # not needed there and it might overwrite a "merge"
1879 # node with the same cpv.
1880 myparent = ("installed", myroot, pkg, "nomerge")
1881 for myatom in blocker_atoms:
1882 blocker = ("blocks", myroot, myatom[1:])
1884 self.blocker_parents.get(blocker, None)
1887 self.blocker_parents[blocker] = myparents
1888 myparents.add(myparent)
1889 blocker_cache.flush()
1892 for blocker in self.blocker_parents.keys():
1893 mytype, myroot, mydep = blocker
1894 initial_db = self.trees[myroot]["vartree"].dbapi
1895 final_db = self.mydbapi[myroot]
1896 blocked_initial = initial_db.match(mydep)
1897 blocked_final = final_db.match(mydep)
1898 if not blocked_initial and not blocked_final:
1899 del self.blocker_parents[blocker]
1901 blocked_slots_initial = {}
1902 blocked_slots_final = {}
1903 for cpv in blocked_initial:
1904 blocked_slots_initial[cpv] = \
1905 "%s:%s" % (portage.dep_getkey(cpv),
1906 initial_db.aux_get(cpv, ["SLOT"])[0])
1907 for cpv in blocked_final:
1908 blocked_slots_final[cpv] = \
1909 "%s:%s" % (portage.dep_getkey(cpv),
1910 final_db.aux_get(cpv, ["SLOT"])[0])
1911 for parent in list(self.blocker_parents[blocker]):
1912 ptype, proot, pcpv, pstatus = parent
1913 pdbapi = self.trees[proot][self.pkg_tree_map[ptype]].dbapi
1914 pslot = pdbapi.aux_get(pcpv, ["SLOT"])[0]
1915 pslot_atom = "%s:%s" % (portage.dep_getkey(pcpv), pslot)
1916 parent_static = pslot_atom not in modified_slots[proot]
1917 unresolved_blocks = False
1918 depends_on_order = set()
1919 for cpv in blocked_initial:
1920 slot_atom = blocked_slots_initial[cpv]
1921 if slot_atom == pslot_atom:
1922 # TODO: Support blocks within slots in cases where it
1923 # might make sense. For example, a new version might
1924 # require that the old version be uninstalled at build
1927 if parent_static and \
1928 slot_atom not in modified_slots[myroot]:
1929 # This blocker will be handled the next time that a
1930 # merge of either package is triggered.
1932 if pstatus == "merge" and \
1933 slot_atom in modified_slots[myroot]:
1934 replacement = final_db.match(slot_atom)
1936 if not portage.match_from_list(mydep, replacement):
1937 # Apparently a replacement may be able to
1938 # invalidate this block.
1939 replacement_node = \
1940 self.pkg_node_map[proot][replacement[0]]
1941 depends_on_order.add((replacement_node, parent))
1943 # None of the above blocker resolutions techniques apply,
1944 # so apparently this one is unresolvable.
1945 unresolved_blocks = True
1946 for cpv in blocked_final:
1947 slot_atom = blocked_slots_final[cpv]
1948 if slot_atom == pslot_atom:
1949 # TODO: Support blocks within slots.
1951 if parent_static and \
1952 slot_atom not in modified_slots[myroot]:
1953 # This blocker will be handled the next time that a
1954 # merge of either package is triggered.
1956 if not parent_static and pstatus == "nomerge" and \
1957 slot_atom in modified_slots[myroot]:
1958 replacement = final_db.match(pslot_atom)
1960 replacement_node = \
1961 self.pkg_node_map[proot][replacement[0]]
1962 if replacement_node not in \
1963 self.blocker_parents[blocker]:
1964 # Apparently a replacement may be able to
1965 # invalidate this block.
1966 blocked_node = self.pkg_node_map[proot][cpv]
1967 depends_on_order.add(
1968 (replacement_node, blocked_node))
1970 # None of the above blocker resolutions techniques apply,
1971 # so apparently this one is unresolvable.
1972 unresolved_blocks = True
1973 if not unresolved_blocks and depends_on_order:
1974 for node, pnode in depends_on_order:
1975 # Enforce correct merge order with a hard dep.
1976 self.digraph.addnode(node, pnode,
1977 priority=DepPriority(buildtime=True))
1978 # Count references to this blocker so that it can be
1979 # invalidated after nodes referencing it have been
1981 self.blocker_digraph.addnode(node, blocker)
1982 if not unresolved_blocks and not depends_on_order:
1983 self.blocker_parents[blocker].remove(parent)
1984 if unresolved_blocks:
1985 self._unresolved_blocker_parents.setdefault(
1986 blocker, set()).add(parent)
1987 if not self.blocker_parents[blocker]:
1988 del self.blocker_parents[blocker]
1989 # Validate blockers that depend on merge order.
1990 if not self.blocker_digraph.empty():
1992 if self._slot_collision_info:
1993 # The user is only notified of a slot collision if there are no
1994 # unresolvable blocks.
1995 for x in self.altlist():
1996 if x[0] == "blocks":
1998 self._show_slot_collision_notice(self._slot_collision_info[0])
1999 if not self._accept_collisions():
2003 def _accept_collisions(self):
2005 for x in ("--nodeps", "--pretend", "--fetchonly", "--fetch-all-uri"):
2006 if x in self.myopts:
2011 def _merge_order_bias(self, mygraph):
2012 """Order nodes from highest to lowest overall reference count for
2013 optimal leaf node selection."""
2015 for node in mygraph.order:
2016 node_info[node] = len(mygraph.parent_nodes(node))
2017 def cmp_merge_preference(node1, node2):
2018 return node_info[node2] - node_info[node1]
2019 mygraph.order.sort(cmp_merge_preference)
2021 def altlist(self, reversed=False):
2022 if reversed in self._altlist_cache:
2023 return self._altlist_cache[reversed][:]
2025 retlist = self.altlist()
2027 self._altlist_cache[reversed] = retlist[:]
2029 mygraph=self.digraph.copy()
2030 self._merge_order_bias(mygraph)
2031 myblockers = self.blocker_digraph.copy()
2033 circular_blocks = False
2037 get_nodes = mygraph.root_nodes
2039 get_nodes = mygraph.leaf_nodes
2040 for cpv, node in self.pkg_node_map["/"].iteritems():
2041 if "portage" == portage.catsplit(portage.dep_getkey(cpv))[-1]:
2042 asap_nodes.append(node)
2044 ignore_priority_range = [None]
2045 ignore_priority_range.extend(
2046 xrange(DepPriority.MIN, DepPriority.MEDIUM + 1))
2047 tree_mode = "--tree" in self.myopts
2048 while not mygraph.empty():
2049 ignore_priority = None
2052 """ASAP nodes are merged before their soft deps."""
2053 for node in asap_nodes:
2054 if not mygraph.contains(node):
2055 asap_nodes.remove(node)
2057 if not mygraph.child_nodes(node,
2058 ignore_priority=DepPriority.SOFT):
2060 asap_nodes.remove(node)
2063 for ignore_priority in ignore_priority_range:
2064 nodes = get_nodes(ignore_priority=ignore_priority)
2067 selected_nodes = None
2069 if ignore_priority <= DepPriority.SOFT:
2070 if ignore_priority is None and not tree_mode:
2071 # Greedily pop all of these nodes since no relationship
2072 # has been ignored. This optimization destroys --tree
2073 # output, so it's disabled in reversed mode.
2074 selected_nodes = nodes
2076 # For optimal merge order:
2077 # * Only pop one node.
2078 # * Removing a root node (node without a parent)
2079 # will not produce a leaf node, so avoid it.
2081 if mygraph.parent_nodes(node):
2082 # found a non-root node
2083 selected_nodes = [node]
2085 if not selected_nodes:
2086 # settle for a root node
2087 selected_nodes = [nodes[0]]
2089 """Recursively gather a group of nodes that RDEPEND on
2090 eachother. This ensures that they are merged as a group
2091 and get their RDEPENDs satisfied as soon as possible."""
2092 def gather_deps(mergeable_nodes, selected_nodes, node):
2093 if node in selected_nodes:
2095 if node not in mergeable_nodes:
2097 selected_nodes.add(node)
2098 for child in mygraph.child_nodes(node,
2099 ignore_priority=DepPriority.SOFT):
2101 mergeable_nodes, selected_nodes, child):
2104 mergeable_nodes = set(nodes)
2106 selected_nodes = set()
2108 mergeable_nodes, selected_nodes, node):
2111 selected_nodes = None
2113 if not selected_nodes:
2114 if not myblockers.is_empty():
2115 """A blocker couldn't be circumnavigated while keeping all
2116 dependencies satisfied. The user will have to resolve this
2117 manually. This is a panic condition and thus the order
2118 doesn't really matter, so just pop a random node in order
2119 to avoid a circular dependency panic if possible."""
2120 if not circular_blocks:
2121 circular_blocks = True
2122 blocker_deps = myblockers.leaf_nodes()
2124 # Some of these nodes might have already been selected
2125 # by the normal node selection process after the
2126 # circular_blocks flag has been set. Therefore, we
2127 # have to verify that they're still in the graph so
2128 # that they're not selected more than once.
2129 node = blocker_deps.pop()
2130 if mygraph.contains(node):
2131 selected_nodes = [node]
2134 if not selected_nodes:
2135 # No leaf nodes are available, so we have a circular
2136 # dependency panic situation. Reduce the noise level to a
2137 # minimum via repeated elimination of root nodes since they
2138 # have no parents and thus can not be part of a cycle.
2140 root_nodes = mygraph.root_nodes(
2141 ignore_priority=DepPriority.SOFT)
2144 for node in root_nodes:
2145 mygraph.remove(node)
2146 # Display the USE flags that are enabled on nodes that are part
2147 # of dependency cycles in case that helps the user decide to
2148 # disable some of them.
2150 tempgraph = mygraph.copy()
2151 while not tempgraph.empty():
2152 nodes = tempgraph.leaf_nodes()
2154 node = tempgraph.order[0]
2157 display_order.append(list(node))
2158 tempgraph.remove(node)
2159 display_order.reverse()
2160 self.myopts.pop("--quiet", None)
2161 self.myopts.pop("--verbose", None)
2162 self.myopts["--tree"] = True
2163 self.display(display_order)
2164 print "!!! Error: circular dependencies:"
2166 mygraph.debug_print()
2168 print "!!! Note that circular dependencies can often be avoided by temporarily"
2169 print "!!! disabling USE flags that trigger optional dependencies."
2172 for node in selected_nodes:
2173 retlist.append(list(node))
2174 mygraph.remove(node)
2175 if not reversed and not circular_blocks and myblockers.contains(node):
2176 """This node may have invalidated one or more blockers."""
2177 myblockers.remove(node)
2178 for blocker in myblockers.root_nodes():
2179 if not myblockers.child_nodes(blocker):
2180 myblockers.remove(blocker)
2182 self._unresolved_blocker_parents.get(blocker)
2184 self.blocker_parents[blocker] = unresolved
2186 del self.blocker_parents[blocker]
2189 """Blocker validation does not work with reverse mode,
2190 so self.altlist() should first be called with reverse disabled
2191 so that blockers are properly validated."""
2192 self.blocker_digraph = myblockers
2194 """ Add any unresolved blocks so that they can be displayed."""
2195 for blocker in self.blocker_parents:
2196 retlist.append(list(blocker))
2197 self._altlist_cache[reversed] = retlist[:]
2200 def xcreate(self,mode="system"):
2201 vardb = self.trees[self.target_root]["vartree"].dbapi
2202 portdb = self.trees[self.target_root]["porttree"].dbapi
2203 bindb = self.trees[self.target_root]["bintree"].dbapi
2204 def visible(mylist):
2205 matches = portdb.gvisible(portdb.visible(mylist))
2206 return [x for x in mylist \
2207 if x in matches or not portdb.cpv_exists(x)]
2208 world_problems = False
2210 mylist = getlist(self.settings, "system")
2213 worldlist = getlist(self.settings, "world")
2214 mylist = getlist(self.settings, "system")
2215 worlddict=genericdict(worldlist)
2218 if not portage.isvalidatom(x):
2219 world_problems = True
2221 elif not vardb.match(x):
2222 world_problems = True
2224 if "--usepkgonly" not in self.myopts and \
2227 elif "--usepkg" in self.myopts:
2228 mymatches = bindb.match(x)
2229 if "--usepkgonly" not in self.myopts:
2230 mymatches = visible(mymatches)
2239 mykey = portage.dep_getkey(atom)
2241 newlist.append(atom)
2242 """Make sure all installed slots are updated when possible.
2243 Do this with --emptytree also, to ensure that all slots are
2246 for cpv in vardb.match(mykey):
2247 myslots.add(vardb.aux_get(cpv, ["SLOT"])[0])
2250 if "--usepkg" in self.myopts:
2251 mymatches = bindb.match(atom)
2252 if "--usepkgonly" not in self.myopts:
2253 mymatches = visible(mymatches)
2254 best_pkg = portage.best(mymatches)
2256 best_slot = bindb.aux_get(best_pkg, ["SLOT"])[0]
2257 best_pkgs.append(("binary", best_pkg, best_slot))
2258 if "--usepkgonly" not in self.myopts:
2259 best_pkg = portage.best(portdb.match(atom))
2261 best_slot = portdb.aux_get(best_pkg, ["SLOT"])[0]
2262 best_pkgs.append(("ebuild", best_pkg, best_slot))
2264 best_pkg = portage.best([x[1] for x in best_pkgs])
2265 best_pkgs = [x for x in best_pkgs if x[1] == best_pkg]
2266 best_slot = best_pkgs[0][2]
2267 myslots.add(best_slot)
2268 if len(myslots) > 1:
2269 for myslot in myslots:
2270 myslot_atom = "%s:%s" % (mykey, myslot)
2272 if "--usepkgonly" not in self.myopts and \
2273 self.trees[self.target_root][
2274 "porttree"].dbapi.match(myslot_atom):
2276 elif "--usepkg" in self.myopts:
2277 mymatches = bindb.match(myslot_atom)
2278 if "--usepkgonly" not in self.myopts:
2279 mymatches = visible(mymatches)
2283 newlist.append(myslot_atom)
2287 for mydep in mylist:
2289 if not self.select_dep(
2290 self.target_root, mydep, raise_on_missing=True, arg=mydep):
2291 print >> sys.stderr, "\n\n!!! Problem resolving dependencies for", mydep
2294 missing_atoms.append(mydep)
2296 if not self.validate_blockers():
2300 print >> sys.stderr, "\n!!! Problems have been detected with your world file"
2301 print >> sys.stderr, "!!! Please run "+green("emaint --check world")+"\n"
2304 print >> sys.stderr, "\n" + colorize("BAD", "!!!") + \
2305 " Ebuilds for the following packages are either all"
2306 print >> sys.stderr, colorize("BAD", "!!!") + " masked or don't exist:"
2307 print >> sys.stderr, " ".join(missing_atoms) + "\n"
2311 def display(self,mylist,verbosity=None):
2312 if verbosity is None:
2313 verbosity = ("--quiet" in self.myopts and 1 or \
2314 "--verbose" in self.myopts and 3 or 2)
2319 counters = PackageCounters()
2321 if verbosity == 1 and "--verbose" not in self.myopts:
2322 def create_use_string(*args):
2325 def create_use_string(name, cur_iuse, iuse_forced, cur_use,
2327 is_new, all_flags=(verbosity == 3 or "--quiet" in self.myopts),
2328 alphabetical=("--alphabetical" in self.myopts)):
2336 cur_iuse = set(cur_iuse)
2337 enabled_flags = cur_iuse.intersection(cur_use)
2338 removed_iuse = set(old_iuse).difference(cur_iuse)
2339 any_iuse = cur_iuse.union(old_iuse)
2340 any_iuse = list(any_iuse)
2342 for flag in any_iuse:
2345 if flag in enabled_flags:
2347 if is_new or flag in old_use and all_flags:
2348 flag_str = red(flag)
2349 elif flag not in old_iuse:
2350 flag_str = yellow(flag) + "%*"
2351 elif flag not in old_use:
2352 flag_str = green(flag) + "*"
2353 elif flag in removed_iuse:
2355 flag_str = yellow("-" + flag) + "%"
2358 flag_str = "(" + flag_str + ")"
2359 removed.append(flag_str)
2362 if is_new or flag in old_iuse and flag not in old_use and all_flags:
2363 flag_str = blue("-" + flag)
2364 elif flag not in old_iuse:
2365 flag_str = yellow("-" + flag)
2366 if flag not in iuse_forced:
2368 elif flag in old_use:
2369 flag_str = green("-" + flag) + "*"
2371 if flag in iuse_forced:
2372 flag_str = "(" + flag_str + ")"
2374 enabled.append(flag_str)
2376 disabled.append(flag_str)
2379 ret = " ".join(enabled)
2381 ret = " ".join(enabled + disabled + removed)
2383 ret = '%s="%s" ' % (name, ret)
2387 # FIXME: account for the possibility of different overlays in
2388 # /etc/make.conf vs. ${PORTAGE_CONFIGROOT}/etc/make.conf
2389 overlays = self.settings["PORTDIR_OVERLAY"].split()
2390 overlays_real = [os.path.realpath(t) \
2391 for t in self.settings["PORTDIR_OVERLAY"].split()]
2395 mygraph = self._parent_child_digraph
2400 if "blocks" == x[0]:
2401 display_list.append((x, 0, True))
2403 graph_key = tuple(x)
2404 if "--tree" in self.myopts:
2405 depth = len(tree_nodes)
2406 while depth and graph_key not in \
2407 mygraph.child_nodes(tree_nodes[depth-1]):
2410 tree_nodes = tree_nodes[:depth]
2411 tree_nodes.append(graph_key)
2412 display_list.append((x, depth, True))
2413 shown_edges.add((graph_key, tree_nodes[depth-1]))
2415 traversed_nodes = set() # prevent endless circles
2416 traversed_nodes.add(graph_key)
2417 def add_parents(current_node, ordered):
2418 parent_nodes = mygraph.parent_nodes(current_node)
2420 child_nodes = set(mygraph.child_nodes(current_node))
2421 selected_parent = None
2422 # First, try to avoid a direct cycle.
2423 for node in parent_nodes:
2424 if node not in traversed_nodes and \
2425 node not in child_nodes:
2426 edge = (current_node, node)
2427 if edge in shown_edges:
2429 selected_parent = node
2431 if not selected_parent:
2432 # A direct cycle is unavoidable.
2433 for node in parent_nodes:
2434 if node not in traversed_nodes:
2435 edge = (current_node, node)
2436 if edge in shown_edges:
2438 selected_parent = node
2441 shown_edges.add((current_node, selected_parent))
2442 traversed_nodes.add(selected_parent)
2443 add_parents(selected_parent, False)
2444 display_list.append((list(current_node),
2445 len(tree_nodes), ordered))
2446 tree_nodes.append(current_node)
2448 add_parents(graph_key, True)
2450 display_list.append((x, depth, True))
2451 mylist = display_list
2453 last_merge_depth = 0
2454 for i in xrange(len(mylist)-1,-1,-1):
2455 graph_key, depth, ordered = mylist[i]
2456 if not ordered and depth == 0 and i > 0 \
2457 and graph_key == mylist[i-1][0] and \
2458 mylist[i-1][1] == 0:
2459 # An ordered node got a consecutive duplicate when the tree was
2463 if "blocks" == graph_key[0]:
2465 if ordered and graph_key[-1] != "nomerge":
2466 last_merge_depth = depth
2468 if depth >= last_merge_depth or \
2469 i < len(mylist) - 1 and \
2470 depth >= mylist[i+1][1]:
2473 from portage import flatten
2474 from portage.dep import use_reduce, paren_reduce
2475 display_overlays=False
2476 # files to fetch list - avoids counting a same file twice
2477 # in size display (verbose mode)
2479 for mylist_index in xrange(len(mylist)):
2480 x, depth, ordered = mylist[mylist_index]
2484 portdb = self.trees[myroot]["porttree"].dbapi
2485 bindb = self.trees[myroot]["bintree"].dbapi
2486 vardb = self.trees[myroot]["vartree"].dbapi
2487 vartree = self.trees[myroot]["vartree"]
2488 pkgsettings = self.pkgsettings[myroot]
2493 addl=""+red("B")+" "+fetch+" "
2495 counters.blocks += 1
2496 resolved = portage.key_expand(
2497 pkg_key, mydb=vardb, settings=pkgsettings)
2498 if "--columns" in self.myopts and "--quiet" in self.myopts:
2499 addl = addl + " " + red(resolved)
2501 addl = "[blocks " + addl + "] " + red(resolved)
2502 block_parents = self.blocker_parents[tuple(x)]
2503 block_parents = set([pnode[2] for pnode in block_parents])
2504 block_parents = ", ".join(block_parents)
2506 addl += bad(" (\"%s\" is blocking %s)") % \
2507 (pkg_key, block_parents)
2509 addl += bad(" (is blocking %s)") % block_parents
2510 blockers.append(addl)
2512 mydbapi = self.trees[myroot][self.pkg_tree_map[pkg_type]].dbapi
2514 binary_package = True
2515 if "ebuild" == pkg_type:
2516 if "merge" == x[3] or \
2517 not vartree.dbapi.cpv_exists(pkg_key):
2518 """An ebuild "merge" node or a --onlydeps "nomerge"
2520 binary_package = False
2521 pkgsettings.setcpv(pkg_key, mydb=portdb)
2522 if pkg_key not in self.useFlags[myroot]:
2523 self.useFlags[myroot][pkg_key] = \
2524 pkgsettings["USE"].split()
2526 # An ebuild "nomerge" node, so USE come from the vardb.
2527 mydbapi = vartree.dbapi
2528 if pkg_key not in self.useFlags[myroot]:
2529 """If this is a --resume then the USE flags need to be
2530 fetched from the appropriate locations here."""
2531 self.useFlags[myroot][pkg_key] = mydbapi.aux_get(
2532 pkg_key, ["USE"])[0].split()
2535 restrict = flatten(use_reduce(paren_reduce(
2536 mydbapi.aux_get(pkg_key, ["RESTRICT"])[0]),
2537 uselist=self.useFlags[myroot][pkg_key]))
2538 except portage.exception.InvalidDependString, e:
2539 if pkg_status != "nomerge":
2540 restrict = mydbapi.aux_get(pkg_key, ["RESTRICT"])[0]
2541 show_invalid_depstring_notice(x, restrict, str(e))
2545 if "ebuild" == pkg_type and x[3] != "nomerge" and \
2546 "fetch" in restrict:
2549 counters.restrict_fetch += 1
2550 if portdb.fetch_check(
2551 pkg_key, self.useFlags[myroot][pkg_key]):
2554 counters.restrict_fetch_satisfied += 1
2556 #we need to use "--emptrytree" testing here rather than "empty" param testing because "empty"
2557 #param is used for -u, where you still *do* want to see when something is being upgraded.
2559 if vardb.cpv_exists(pkg_key):
2560 addl=" "+yellow("R")+fetch+" "
2561 if x[3] != "nomerge":
2563 counters.reinst += 1
2564 elif vardb.match(portage.dep_getkey(pkg_key)):
2565 mynewslot = mydbapi.aux_get(pkg_key, ["SLOT"])[0]
2566 myoldlist = self.trees[x[1]]["vartree"].dbapi.match(
2567 portage.pkgsplit(x[2])[0])
2568 myinslotlist = [inst_pkg for inst_pkg in myoldlist
2569 if mynewslot == vardb.aux_get(inst_pkg, ["SLOT"])[0]]
2571 myoldbest=portage.best(myinslotlist)
2573 if portage.pkgcmp(portage.pkgsplit(x[2]), portage.pkgsplit(myoldbest)) < 0:
2575 addl+=turquoise("U")+blue("D")
2577 counters.downgrades += 1
2580 addl+=turquoise("U")+" "
2582 counters.upgrades += 1
2584 # New slot, mark it new.
2585 addl=" "+green("NS")+fetch+" "
2587 counters.newslot += 1
2589 if "--changelog" in self.myopts:
2590 slot_atom = "%s:%s" % (portage.dep_getkey(pkg_key),
2591 mydbapi.aux_get(pkg_key, ["SLOT"])[0])
2592 inst_matches = vardb.match(slot_atom)
2594 changelogs.extend(self.calc_changelog(
2595 portdb.findname(pkg_key),
2596 inst_matches[0], pkg_key))
2598 addl=" "+green("N")+" "+fetch+" "
2604 if pkg_key in self.useFlags[myroot]:
2606 cur_iuse = list(filter_iuse_defaults(
2607 mydbapi.aux_get(pkg_key, ["IUSE"])[0].split()))
2609 forced_flags = set()
2610 if not binary_package:
2611 forced_flags.update(pkgsettings.useforce)
2612 forced_flags.update(pkgsettings.usemask)
2614 cur_iuse = portage.unique_array(cur_iuse)
2616 cur_use = self.useFlags[myroot][pkg_key]
2617 cur_use = [flag for flag in cur_use if flag in cur_iuse]
2623 if self.trees[x[1]]["vartree"].dbapi.cpv_exists(pkg):
2624 old_iuse, old_use = \
2625 self.trees[x[1]]["vartree"].dbapi.aux_get(
2626 pkg, ["IUSE", "USE"])
2627 old_iuse = list(set(
2628 filter_iuse_defaults(old_iuse.split())))
2630 old_use = old_use.split()
2637 old_use = [flag for flag in old_use if flag in old_iuse]
2639 use_expand = pkgsettings["USE_EXPAND"].lower().split()
2641 use_expand.reverse()
2642 use_expand_hidden = \
2643 pkgsettings["USE_EXPAND_HIDDEN"].lower().split()
2645 def map_to_use_expand(myvals, forcedFlags=False):
2648 for exp in use_expand:
2651 for val in myvals[:]:
2652 if val.startswith(exp.lower()+"_"):
2653 if val in forced_flags:
2654 forced[exp].add(val[len(exp)+1:])
2655 ret[exp].append(val[len(exp)+1:])
2658 forced["USE"] = [val for val in myvals \
2659 if val in forced_flags]
2660 for exp in use_expand_hidden:
2667 cur_iuse_map, iuse_forced = \
2668 map_to_use_expand(cur_iuse, forcedFlags=True)
2669 cur_use_map = map_to_use_expand(cur_use)
2670 old_iuse_map = map_to_use_expand(old_iuse)
2671 old_use_map = map_to_use_expand(old_use)
2674 use_expand.insert(0, "USE")
2676 for key in use_expand:
2677 if key in use_expand_hidden:
2679 verboseadd += create_use_string(key.upper(),
2680 cur_iuse_map[key], iuse_forced[key],
2681 cur_use_map[key], old_iuse_map[key],
2682 old_use_map[key], is_new)
2687 if x[0] == "ebuild" and ordered and x[-1] != "nomerge":
2689 myfilesdict = portdb.getfetchsizes(pkg_key,
2690 useflags=self.useFlags[myroot][pkg_key],
2692 except portage.exception.InvalidDependString, e:
2693 src_uri = portdb.aux_get(pkg_key, ["SRC_URI"])[0]
2694 show_invalid_depstring_notice(x, src_uri, str(e))
2697 if myfilesdict is None:
2698 myfilesdict="[empty/missing/bad digest]"
2700 for myfetchfile in myfilesdict:
2701 if myfetchfile not in myfetchlist:
2702 mysize+=myfilesdict[myfetchfile]
2703 myfetchlist.append(myfetchfile)
2704 counters.totalsize += mysize
2705 verboseadd+=format_size(mysize)+" "
2708 # XXX: Invalid binaries have caused tracebacks here. 'if file_name'
2709 # x = ['binary', '/', 'sys-apps/pcmcia-cs-3.2.7.2.6', 'merge']
2710 file_name = portdb.findname(pkg_key)
2711 if file_name: # It might not exist in the tree
2712 dir_name=os.path.abspath(os.path.dirname(file_name)+"/../..")
2713 if (overlays_real.count(dir_name)>0):
2714 verboseadd+=teal("["+str(overlays_real.index(
2715 os.path.normpath(dir_name))+1)+"]")+" "
2716 display_overlays=True
2718 verboseadd += "[No ebuild?]"
2720 xs = list(portage.pkgsplit(x[2]))
2727 if "COLUMNWIDTH" in self.settings:
2729 mywidth = int(self.settings["COLUMNWIDTH"])
2730 except ValueError, e:
2731 portage.writemsg("!!! %s\n" % str(e), noiselevel=-1)
2733 "!!! Unable to parse COLUMNWIDTH='%s'\n" % \
2734 self.settings["COLUMNWIDTH"], noiselevel=-1)
2739 indent = " " * depth
2742 myoldbest=portage.pkgsplit(myoldbest)[1]+"-"+portage.pkgsplit(myoldbest)[2]
2743 if myoldbest[-3:]=="-r0":
2744 myoldbest=myoldbest[:-3]
2745 myoldbest=blue("["+myoldbest+"]")
2750 if "--columns" in self.myopts:
2751 if "--quiet" in self.myopts:
2752 myprint=addl+" "+indent+darkgreen(xs[0])
2753 myprint=myprint+darkblue(" "+xs[1]+xs[2])+" "
2754 myprint=myprint+myoldbest
2755 myprint=myprint+darkgreen("to "+x[1])
2757 myprint="["+x[0]+" "+addl+"] "+indent+darkgreen(xs[0])
2758 if (newlp-nc_len(myprint)) > 0:
2759 myprint=myprint+(" "*(newlp-nc_len(myprint)))
2760 myprint=myprint+"["+darkblue(xs[1]+xs[2])+"] "
2761 if (oldlp-nc_len(myprint)) > 0:
2762 myprint=myprint+" "*(oldlp-nc_len(myprint))
2763 myprint=myprint+myoldbest
2764 myprint=myprint+darkgreen("to "+x[1])+" "+verboseadd
2766 if x[-1] == "nomerge" or not ordered:
2767 myprint = darkblue("[nomerge ] ")
2769 myprint = "[" + pkg_type + " " + addl + "] "
2770 myprint += indent + darkgreen(pkg_key) + " " + \
2771 myoldbest + darkgreen("to " + myroot) + " " + \
2774 if "--columns" in self.myopts:
2775 if "--quiet" in self.myopts:
2776 myprint=addl+" "+indent+darkgreen(xs[0])
2777 myprint=myprint+" "+green(xs[1]+xs[2])+" "
2778 myprint=myprint+myoldbest
2780 myprint="["+x[0]+" "+addl+"] "+indent+darkgreen(xs[0])
2781 if (newlp-nc_len(myprint)) > 0:
2782 myprint=myprint+(" "*(newlp-nc_len(myprint)))
2783 myprint=myprint+green(" ["+xs[1]+xs[2]+"] ")
2784 if (oldlp-nc_len(myprint)) > 0:
2785 myprint=myprint+(" "*(oldlp-nc_len(myprint)))
2786 myprint=myprint+myoldbest+" "+verboseadd
2788 if x[-1] == "nomerge" or not ordered:
2789 myprint=darkblue("[nomerge ] "+indent+x[2]+" "+myoldbest+" ")+verboseadd
2791 myprint="["+x[0]+" "+addl+"] "+indent+darkgreen(x[2])+" "+myoldbest+" "+verboseadd
2794 mysplit = portage.pkgsplit(x[2])
2795 if "--tree" not in self.myopts and mysplit and \
2796 len(mysplit) == 3 and mysplit[0] == "sys-apps/portage" and \
2799 if mysplit[2] == "r0":
2800 myversion = mysplit[1]
2802 myversion = "%s-%s" % (mysplit[1], mysplit[2])
2804 if myversion != portage.VERSION and "--quiet" not in self.myopts:
2805 if mylist_index < len(mylist) - 1 and \
2806 "livecvsportage" not in self.settings.features:
2807 p.append(colorize("WARN", "*** Portage will stop merging at this point and reload itself,"))
2808 p.append(colorize("WARN", " then resume the merge."))
2820 if overlays and display_overlays:
2821 print "Portage overlays:"
2825 print " "+teal("["+str(y)+"]"),x
2827 if "--changelog" in self.myopts:
2829 for revision,text in changelogs:
2830 print bold('*'+revision)
2831 sys.stdout.write(text)
2833 if self._pprovided_args:
2835 msg.append(bad("\nWARNING: "))
2836 if len(self._pprovided_args) > 1:
2837 msg.append("Requested packages will not be " + \
2838 "merged because they are listed in\n")
2840 msg.append("A requested package will not be " + \
2841 "merged because it is listed in\n")
2842 msg.append(" package.provided:\n\n")
2843 for arg in self._pprovided_args:
2844 msg.append(" " + arg + "\n")
2846 sys.stderr.write("".join(msg))
2848 def calc_changelog(self,ebuildpath,current,next):
2849 if ebuildpath == None or not os.path.exists(ebuildpath):
2851 current = '-'.join(portage.catpkgsplit(current)[1:])
2852 if current.endswith('-r0'):
2853 current = current[:-3]
2854 next = '-'.join(portage.catpkgsplit(next)[1:])
2855 if next.endswith('-r0'):
2857 changelogpath = os.path.join(os.path.split(ebuildpath)[0],'ChangeLog')
2859 changelog = open(changelogpath).read()
2860 except SystemExit, e:
2861 raise # Needed else can't exit
2864 divisions = self.find_changelog_tags(changelog)
2865 #print 'XX from',current,'to',next
2866 #for div,text in divisions: print 'XX',div
2867 # skip entries for all revisions above the one we are about to emerge
2868 for i in range(len(divisions)):
2869 if divisions[i][0]==next:
2870 divisions = divisions[i:]
2872 # find out how many entries we are going to display
2873 for i in range(len(divisions)):
2874 if divisions[i][0]==current:
2875 divisions = divisions[:i]
2878 # couldnt find the current revision in the list. display nothing
2882 def find_changelog_tags(self,changelog):
2886 match = re.search(r'^\*\ ?([-a-zA-Z0-9_.+]*)(?:\ .*)?\n',changelog,re.M)
2888 if release is not None:
2889 divs.append((release,changelog))
2891 if release is not None:
2892 divs.append((release,changelog[:match.start()]))
2893 changelog = changelog[match.end():]
2894 release = match.group(1)
2895 if release.endswith('.ebuild'):
2896 release = release[:-7]
2897 if release.endswith('-r0'):
2898 release = release[:-3]
2901 return self.outdatedpackages
2903 class PackageCounters(object):
2913 self.restrict_fetch = 0
2914 self.restrict_fetch_satisfied = 0
2917 total_installs = self.upgrades + self.downgrades + self.newslot + self.new + self.reinst
2920 myoutput.append("Total: %s package" % total_installs)
2921 if total_installs != 1:
2922 myoutput.append("s")
2923 if total_installs != 0:
2924 myoutput.append(" (")
2925 if self.upgrades > 0:
2926 details.append("%s upgrade" % self.upgrades)
2927 if self.upgrades > 1:
2929 if self.downgrades > 0:
2930 details.append("%s downgrade" % self.downgrades)
2931 if self.downgrades > 1:
2934 details.append("%s new" % self.new)
2935 if self.newslot > 0:
2936 details.append("%s in new slot" % self.newslot)
2937 if self.newslot > 1:
2940 details.append("%s reinstall" % self.reinst)
2944 details.append("%s block" % self.blocks)
2947 myoutput.append(", ".join(details))
2948 if total_installs != 0:
2949 myoutput.append(")")
2950 myoutput.append(", Size of downloads: %s" % format_size(self.totalsize))
2951 if self.restrict_fetch:
2952 myoutput.append("\nFetch Restriction: %s package" % \
2953 self.restrict_fetch)
2954 if self.restrict_fetch > 1:
2955 myoutput.append("s")
2956 if self.restrict_fetch_satisfied < self.restrict_fetch:
2957 myoutput.append(bad(" (%s unsatisfied)") % \
2958 (self.restrict_fetch - self.restrict_fetch_satisfied))
2959 return "".join(myoutput)
2961 class MergeTask(object):
2963 def __init__(self, settings, trees, myopts):
2964 self.settings = settings
2965 self.target_root = settings["ROOT"]
2967 self.myopts = myopts
2969 if settings.get("PORTAGE_DEBUG", "") == "1":
2971 self.pkgsettings = {}
2972 self.pkgsettings[self.target_root] = portage.config(clone=settings)
2973 if self.target_root != "/":
2974 self.pkgsettings["/"] = \
2975 portage.config(clone=trees["/"]["vartree"].settings)
2977 def merge(self, mylist, favorites, mtimedb):
2979 fetchonly = "--fetchonly" in self.myopts or \
2980 "--fetch-all-uri" in self.myopts
2982 ldpath_mtimes = mtimedb["ldpath"]
2983 xterm_titles = "notitles" not in self.settings.features
2985 #check for blocking dependencies
2986 if "--fetchonly" not in self.myopts and \
2987 "--fetch-all-uri" not in self.myopts and \
2988 "--buildpkgonly" not in self.myopts:
2991 print "\n!!! Error: the "+x[2]+" package conflicts with another package;"
2992 print "!!! the two packages cannot be installed on the same system together."
2993 print "!!! Please use 'emerge --pretend' to determine blockers."
2994 if "--quiet" not in self.myopts:
2995 show_blocker_docs_link()
2998 if "--resume" in self.myopts:
3000 print colorize("GOOD", "*** Resuming merge...")
3001 emergelog(xterm_titles, " *** Resuming merge...")
3002 mylist = mtimedb["resume"]["mergelist"][:]
3003 if "--skipfirst" in self.myopts and mylist:
3004 del mtimedb["resume"]["mergelist"][0]
3007 validate_merge_list(self.trees, mylist)
3008 mymergelist = mylist
3010 # Verify all the manifests now so that the user is notified of failure
3011 # as soon as possible.
3012 if "--fetchonly" not in self.myopts and \
3013 "--fetch-all-uri" not in self.myopts and \
3014 "strict" in self.settings.features:
3015 shown_verifying_msg = False
3017 for myroot, pkgsettings in self.pkgsettings.iteritems():
3018 quiet_config = portage.config(clone=pkgsettings)
3019 quiet_config["PORTAGE_QUIET"] = "1"
3020 quiet_config.backup_changes("PORTAGE_QUIET")
3021 quiet_settings[myroot] = quiet_config
3024 if x[0] != "ebuild" or x[-1] == "nomerge":
3026 if not shown_verifying_msg:
3027 shown_verifying_msg = True
3028 print ">>> Verifying ebuild Manifests..."
3029 mytype, myroot, mycpv, mystatus = x
3030 portdb = self.trees[myroot]["porttree"].dbapi
3031 quiet_config = quiet_settings[myroot]
3032 quiet_config["O"] = os.path.dirname(portdb.findname(mycpv))
3033 if not portage.digestcheck([], quiet_config, strict=True):
3035 del x, mytype, myroot, mycpv, mystatus, quiet_config
3036 del shown_verifying_msg, quiet_settings
3038 #buildsyspkg: I need mysysdict also on resume (moved from the else block)
3039 mysysdict = genericdict(getlist(self.settings, "system"))
3040 if "--resume" not in self.myopts:
3041 myfavs = portage.grabfile(
3042 os.path.join(self.target_root, portage.WORLD_FILE))
3043 myfavdict=genericdict(myfavs)
3044 for x in range(len(mylist)):
3045 if mylist[x][3]!="nomerge":
3046 # Add to the mergelist
3047 mymergelist.append(mylist[x])
3049 myfavkey=portage.cpv_getkey(mylist[x][2])
3050 if "--onlydeps" in self.myopts:
3052 # Add to the world file. Since we won't be able to later.
3053 if "--fetchonly" not in self.myopts and \
3054 myfavkey in favorites:
3055 #don't record if already in system profile or already recorded
3056 if (not mysysdict.has_key(myfavkey)) and (not myfavdict.has_key(myfavkey)):
3057 #we don't have a favorites entry for this package yet; add one
3058 myfavdict[myfavkey]=myfavkey
3059 print ">>> Recording",myfavkey,"in \"world\" favorites file..."
3060 if not ("--fetchonly" in self.myopts or \
3061 "--fetch-all-uri" in self.myopts or \
3062 "--pretend" in self.myopts):
3063 portage.write_atomic(
3064 os.path.join(self.target_root, portage.WORLD_FILE),
3065 "\n".join(myfavdict.values()))
3067 mtimedb["resume"]["mergelist"]=mymergelist[:]
3070 myfeat = self.settings.features[:]
3071 bad_resume_opts = set(["--ask", "--tree", "--changelog", "--skipfirst",
3073 if "parallel-fetch" in myfeat and \
3074 not ("--pretend" in self.myopts or \
3075 "--fetch-all-uri" in self.myopts or \
3076 "--fetchonly" in self.myopts):
3077 if "distlocks" not in myfeat:
3079 print red("!!!")+" parallel-fetching requires the distlocks feature enabled"
3080 print red("!!!")+" you have it disabled, thus parallel-fetching is being disabled"
3082 elif len(mymergelist) > 1:
3083 print ">>> starting parallel fetching"
3084 fetch_log = "/var/log/emerge-fetch.log"
3085 logfile = open(fetch_log, "w")
3086 fd_pipes = {1:logfile.fileno(), 2:logfile.fileno()}
3087 portage.util.apply_secpass_permissions(fetch_log,
3088 uid=portage.portage_uid, gid=portage.portage_gid,
3090 fetch_env = os.environ.copy()
3091 fetch_env["FEATURES"] = fetch_env.get("FEATURES", "") + " -cvs"
3092 fetch_env["PORTAGE_NICENESS"] = "0"
3093 fetch_args = [sys.argv[0], "--resume", "--fetchonly"]
3094 resume_opts = self.myopts.copy()
3095 # For automatic resume, we need to prevent
3096 # any of bad_resume_opts from leaking in
3097 # via EMERGE_DEFAULT_OPTS.
3098 resume_opts["--ignore-default-opts"] = True
3099 for myopt, myarg in resume_opts.iteritems():
3100 if myopt not in bad_resume_opts:
3102 fetch_args.append(myopt)
3104 fetch_args.append(myopt +"="+ myarg)
3105 portage.process.spawn(fetch_args, env=fetch_env,
3106 fd_pipes=fd_pipes, returnpid=True)
3107 logfile.close() # belongs to the spawned process
3108 del fetch_log, logfile, fd_pipes, fetch_env, fetch_args, \
3112 for x in mymergelist:
3117 portdb = self.trees[myroot]["porttree"].dbapi
3118 bindb = self.trees[myroot]["bintree"].dbapi
3119 vartree = self.trees[myroot]["vartree"]
3120 pkgsettings = self.pkgsettings[myroot]
3123 y = portdb.findname(pkg_key)
3124 if "--pretend" not in self.myopts:
3125 print "\n>>> Emerging (" + \
3126 colorize("MERGE_LIST_PROGRESS", str(mergecount)) + " of " + \
3127 colorize("MERGE_LIST_PROGRESS", str(len(mymergelist))) + ") " + \
3128 colorize("GOOD", x[pkgindex]) + " to " + x[1]
3129 emergelog(xterm_titles, " >>> emerge ("+\
3130 str(mergecount)+" of "+str(len(mymergelist))+\
3131 ") "+x[pkgindex]+" to "+x[1])
3133 pkgsettings["EMERGE_FROM"] = x[0]
3134 pkgsettings.backup_changes("EMERGE_FROM")
3137 #buildsyspkg: Check if we need to _force_ binary package creation
3138 issyspkg = ("buildsyspkg" in myfeat) \
3139 and x[0] != "blocks" \
3140 and mysysdict.has_key(portage.cpv_getkey(x[2])) \
3141 and "--buildpkg" not in self.myopts
3142 if x[0] in ["ebuild","blocks"]:
3143 if x[0] == "blocks" and "--fetchonly" not in self.myopts:
3144 raise Exception, "Merging a blocker"
3145 elif "--fetchonly" in self.myopts or \
3146 "--fetch-all-uri" in self.myopts:
3147 if "--fetch-all-uri" in self.myopts:
3148 retval = portage.doebuild(y, "fetch", myroot,
3149 pkgsettings, self.edebug,
3150 "--pretend" in self.myopts, fetchonly=1,
3151 fetchall=1, mydbapi=portdb, tree="porttree")
3153 retval = portage.doebuild(y, "fetch", myroot,
3154 pkgsettings, self.edebug,
3155 "--pretend" in self.myopts, fetchonly=1,
3156 mydbapi=portdb, tree="porttree")
3157 if (retval is None) or retval:
3159 print "!!! Fetch for",y,"failed, continuing..."
3161 failed_fetches.append(pkg_key)
3164 portage.doebuild_environment(y, "setup", myroot,
3165 pkgsettings, self.edebug, 1, portdb)
3166 catdir = os.path.dirname(pkgsettings["PORTAGE_BUILDDIR"])
3167 portage.util.ensure_dirs(os.path.dirname(catdir),
3168 uid=portage.portage_uid, gid=portage.portage_gid,
3170 builddir_lock = None
3173 catdir_lock = portage.locks.lockdir(catdir)
3174 portage.util.ensure_dirs(catdir,
3175 uid=portage.portage_uid, gid=portage.portage_gid,
3177 builddir_lock = portage.locks.lockdir(
3178 pkgsettings["PORTAGE_BUILDDIR"])
3180 portage.locks.unlockdir(catdir_lock)
3183 msg = " === (%s of %s) Cleaning (%s::%s)" % \
3184 (mergecount, len(mymergelist), pkg_key, y)
3185 short_msg = "emerge: (%s of %s) %s Clean" % \
3186 (mergecount, len(mymergelist), pkg_key)
3187 emergelog(xterm_titles, msg, short_msg=short_msg)
3188 retval = portage.doebuild(y, "clean", myroot,
3189 pkgsettings, self.edebug, cleanup=1,
3190 mydbapi=portdb, tree="porttree")
3191 if retval != os.EX_OK:
3193 if "--buildpkg" in self.myopts or issyspkg:
3195 print ">>> This is a system package, " + \
3196 "let's pack a rescue tarball."
3197 msg = " === (%s of %s) Compiling/Packaging (%s::%s)" % \
3198 (mergecount, len(mymergelist), pkg_key, y)
3199 short_msg = "emerge: (%s of %s) %s Compile" % \
3200 (mergecount, len(mymergelist), pkg_key)
3201 emergelog(xterm_titles, msg, short_msg=short_msg)
3202 self.trees[myroot]["bintree"].prevent_collision(pkg_key)
3203 binpkg_tmpfile = os.path.join(pkgsettings["PKGDIR"],
3204 pkg_key + ".tbz2." + str(os.getpid()))
3205 pkgsettings["PORTAGE_BINPKG_TMPFILE"] = binpkg_tmpfile
3206 pkgsettings.backup_changes("PORTAGE_BINPKG_TMPFILE")
3207 retval = portage.doebuild(y, "package", myroot,
3208 pkgsettings, self.edebug, mydbapi=portdb,
3210 del pkgsettings["PORTAGE_BINPKG_TMPFILE"]
3211 if retval != os.EX_OK:
3213 bintree = self.trees[myroot]["bintree"]
3214 bintree.inject(pkg_key, filename=binpkg_tmpfile)
3215 if "--buildpkgonly" not in self.myopts:
3216 msg = " === (%s of %s) Merging (%s::%s)" % \
3217 (mergecount, len(mymergelist), pkg_key, y)
3218 short_msg = "emerge: (%s of %s) %s Merge" % \
3219 (mergecount, len(mymergelist), pkg_key)
3220 emergelog(xterm_titles, msg, short_msg=short_msg)
3221 retval = portage.merge(pkgsettings["CATEGORY"],
3222 pkgsettings["PF"], pkgsettings["D"],
3223 os.path.join(pkgsettings["PORTAGE_BUILDDIR"],
3224 "build-info"), myroot, pkgsettings,
3225 myebuild=pkgsettings["EBUILD"],
3226 mytree="porttree", mydbapi=portdb,
3227 vartree=vartree, prev_mtimes=ldpath_mtimes)
3228 if retval != os.EX_OK:
3230 elif "noclean" not in pkgsettings.features:
3231 portage.doebuild(y, "clean", myroot,
3232 pkgsettings, self.edebug, mydbapi=portdb,
3235 msg = " === (%s of %s) Compiling/Merging (%s::%s)" % \
3236 (mergecount, len(mymergelist), pkg_key, y)
3237 short_msg = "emerge: (%s of %s) %s Compile" % \
3238 (mergecount, len(mymergelist), pkg_key)
3239 emergelog(xterm_titles, msg, short_msg=short_msg)
3240 retval = portage.doebuild(y, "merge", myroot,
3241 pkgsettings, self.edebug, vartree=vartree,
3242 mydbapi=portdb, tree="porttree",
3243 prev_mtimes=ldpath_mtimes)
3244 if retval != os.EX_OK:
3248 portage.locks.unlockdir(builddir_lock)
3251 # Lock catdir for removal if empty.
3252 catdir_lock = portage.locks.lockdir(catdir)
3258 if e.errno not in (errno.ENOENT,
3259 errno.ENOTEMPTY, errno.EEXIST):
3262 portage.locks.unlockdir(catdir_lock)
3264 elif x[0]=="binary":
3266 mytbz2 = self.trees[myroot]["bintree"].getname(pkg_key)
3267 if "--getbinpkg" in self.myopts:
3270 if "distlocks" in pkgsettings.features and \
3271 os.access(pkgsettings["PKGDIR"], os.W_OK):
3272 portage.util.ensure_dirs(os.path.dirname(mytbz2))
3273 tbz2_lock = portage.locks.lockfile(mytbz2,
3275 if self.trees[myroot]["bintree"].isremote(pkg_key):
3276 msg = " --- (%s of %s) Fetching Binary (%s::%s)" %\
3277 (mergecount, len(mymergelist), pkg_key, mytbz2)
3278 short_msg = "emerge: (%s of %s) %s Fetch" % \
3279 (mergecount, len(mymergelist), pkg_key)
3280 emergelog(xterm_titles, msg, short_msg=short_msg)
3282 self.trees[myroot]["bintree"].gettbz2(pkg_key)
3283 except portage.exception.FileNotFound:
3284 writemsg("!!! Fetching Binary failed " + \
3285 "for '%s'\n" % pkg_key, noiselevel=-1)
3288 failed_fetches.append(pkg_key)
3289 except portage.exception.DigestException, e:
3290 writemsg("\n!!! Digest verification failed:\n",
3292 writemsg("!!! %s\n" % e.value[0],
3294 writemsg("!!! Reason: %s\n" % e.value[1],
3296 writemsg("!!! Got: %s\n" % e.value[2],
3298 writemsg("!!! Expected: %s\n" % e.value[3],
3303 failed_fetches.append(pkg_key)
3306 portage.locks.unlockfile(tbz2_lock)
3308 if "--fetchonly" in self.myopts or \
3309 "--fetch-all-uri" in self.myopts:
3312 short_msg = "emerge: ("+str(mergecount)+" of "+str(len(mymergelist))+") "+x[pkgindex]+" Merge Binary"
3313 emergelog(xterm_titles, " === ("+str(mergecount)+\
3314 " of "+str(len(mymergelist))+") Merging Binary ("+\
3315 x[pkgindex]+"::"+mytbz2+")", short_msg=short_msg)
3316 retval = portage.pkgmerge(mytbz2, x[1], pkgsettings,
3318 vartree=self.trees[myroot]["vartree"],
3319 prev_mtimes=ldpath_mtimes)
3320 if retval != os.EX_OK:
3322 #need to check for errors
3323 if "--buildpkgonly" not in self.myopts:
3324 self.trees[x[1]]["vartree"].inject(x[2])
3325 myfavkey=portage.cpv_getkey(x[2])
3326 if "--fetchonly" not in self.myopts and \
3327 "--fetch-all-uri" not in self.myopts and \
3328 myfavkey in favorites:
3329 myfavs = portage.grabfile(os.path.join(myroot, portage.WORLD_FILE))
3330 myfavdict=genericdict(myfavs)
3331 #don't record if already in system profile or already recorded
3332 if (not mysysdict.has_key(myfavkey)) and (not myfavdict.has_key(myfavkey)):
3333 #we don't have a favorites entry for this package yet; add one
3334 myfavdict[myfavkey]=myfavkey
3335 print ">>> Recording",myfavkey,"in \"world\" favorites file..."
3336 emergelog(xterm_titles, " === ("+\
3337 str(mergecount)+" of "+\
3338 str(len(mymergelist))+\
3339 ") Updating world file ("+x[pkgindex]+")")
3340 portage.write_atomic(
3341 os.path.join(myroot, portage.WORLD_FILE),
3342 "\n".join(myfavdict.values()))
3344 if "--pretend" not in self.myopts and \
3345 "--fetchonly" not in self.myopts and \
3346 "--fetch-all-uri" not in self.myopts:
3347 # Clean the old package that we have merged over top of it.
3348 if pkgsettings.get("AUTOCLEAN", "yes") == "yes":
3349 xsplit=portage.pkgsplit(x[2])
3350 emergelog(xterm_titles, " >>> AUTOCLEAN: " + xsplit[0])
3351 retval = unmerge(pkgsettings, self.myopts, vartree,
3352 "clean", [xsplit[0]], ldpath_mtimes, autoclean=1)
3354 emergelog(xterm_titles,
3355 " --- AUTOCLEAN: Nothing unmerged.")
3357 portage.writemsg_stdout(colorize("WARN", "WARNING:")
3358 + " AUTOCLEAN is disabled. This can cause serious"
3359 + " problems due to overlapping packages.\n")
3361 # Figure out if we need a restart.
3362 mysplit=portage.pkgsplit(x[2])
3363 if mysplit[0] == "sys-apps/portage" and x[1] == "/":
3364 myver=mysplit[1]+"-"+mysplit[2]
3365 if myver[-3:]=='-r0':
3367 if (myver != portage.VERSION) and \
3368 "livecvsportage" not in self.settings.features:
3369 if len(mymergelist) > mergecount:
3370 emergelog(xterm_titles,
3371 " ::: completed emerge ("+ \
3372 str(mergecount)+" of "+ \
3373 str(len(mymergelist))+") "+ \
3375 emergelog(xterm_titles, " *** RESTARTING " + \
3376 "emerge via exec() after change of " + \
3378 del mtimedb["resume"]["mergelist"][0]
3380 portage.run_exitfuncs()
3381 mynewargv=[sys.argv[0],"--resume"]
3382 resume_opts = self.myopts.copy()
3383 # For automatic resume, we need to prevent
3384 # any of bad_resume_opts from leaking in
3385 # via EMERGE_DEFAULT_OPTS.
3386 resume_opts["--ignore-default-opts"] = True
3387 for myopt, myarg in resume_opts.iteritems():
3388 if myopt not in bad_resume_opts:
3390 mynewargv.append(myopt)
3392 mynewargv.append(myopt +"="+ myarg)
3393 # priority only needs to be adjusted on the first run
3394 os.environ["PORTAGE_NICENESS"] = "0"
3395 os.execv(mynewargv[0], mynewargv)
3397 if "--pretend" not in self.myopts and \
3398 "--fetchonly" not in self.myopts and \
3399 "--fetch-all-uri" not in self.myopts:
3400 if "noclean" not in self.settings.features:
3401 short_msg = "emerge: (%s of %s) %s Clean Post" % \
3402 (mergecount, len(mymergelist), x[pkgindex])
3403 emergelog(xterm_titles, (" === (%s of %s) " + \
3404 "Post-Build Cleaning (%s::%s)") % \
3405 (mergecount, len(mymergelist), x[pkgindex], y),
3406 short_msg=short_msg)
3407 emergelog(xterm_titles, " ::: completed emerge ("+\
3408 str(mergecount)+" of "+str(len(mymergelist))+") "+\
3411 # Unsafe for parallel merges
3412 del mtimedb["resume"]["mergelist"][0]
3413 # Commit after each merge so that --resume may still work in
3414 # in the event that portage is not allowed to exit normally
3415 # due to power failure, SIGKILL, etc...
3418 if "--pretend" not in self.myopts:
3419 emergelog(xterm_titles, " *** Finished. Cleaning up...")
3421 # We're out of the loop... We're done. Delete the resume data.
3422 if mtimedb.has_key("resume"):
3423 del mtimedb["resume"]
3426 #by doing an exit this way, --fetchonly can continue to try to
3427 #fetch everything even if a particular download fails.
3428 if "--fetchonly" in self.myopts or "--fetch-all-uri" in self.myopts:
3430 sys.stderr.write("\n\n!!! Some fetch errors were " + \
3431 "encountered. Please see above for details.\n\n")
3432 for cpv in failed_fetches:
3433 sys.stderr.write(" ")
3434 sys.stderr.write(cpv)
3435 sys.stderr.write("\n")
3436 sys.stderr.write("\n")
3442 def unmerge(settings, myopts, vartree, unmerge_action, unmerge_files,
3443 ldpath_mtimes, autoclean=0):
3444 candidate_catpkgs=[]
3446 xterm_titles = "notitles" not in settings.features
3448 vdb_path = os.path.join(settings["ROOT"], portage.VDB_PATH)
3450 # At least the parent needs to exist for the lock file.
3451 portage.util.ensure_dirs(vdb_path)
3452 except portage.exception.PortageException:
3456 if os.access(vdb_path, os.W_OK):
3457 vdb_lock = portage.locks.lockdir(vdb_path)
3458 realsyslist = getlist(settings, "system")
3460 for x in realsyslist:
3461 mycp = portage.dep_getkey(x)
3462 if mycp in settings.getvirtuals():
3464 for provider in settings.getvirtuals()[mycp]:
3465 if vartree.dbapi.match(provider):
3466 providers.append(provider)
3467 if len(providers) == 1:
3468 syslist.extend(providers)
3470 syslist.append(mycp)
3472 mysettings = portage.config(clone=settings)
3474 if not unmerge_files or "world" in unmerge_files or \
3475 "system" in unmerge_files:
3476 if "unmerge"==unmerge_action:
3478 print bold("emerge unmerge") + " can only be used with " + \
3479 "specific package names, not with "+bold("world")+" or"
3480 print bold("system")+" targets."
3487 # process all arguments and add all
3488 # valid db entries to candidate_catpkgs
3490 if not unmerge_files or "world" in unmerge_files:
3491 candidate_catpkgs.extend(vartree.dbapi.cp_all())
3492 elif "system" in unmerge_files:
3493 candidate_catpkgs.extend(getlist(settings, "system"))
3495 #we've got command-line arguments
3496 if not unmerge_files:
3497 print "\nNo packages to unmerge have been provided.\n"
3499 for x in unmerge_files:
3500 arg_parts = x.split('/')
3501 if x[0] not in [".","/"] and \
3502 arg_parts[-1][-7:] != ".ebuild":
3503 #possible cat/pkg or dep; treat as such
3504 candidate_catpkgs.append(x)
3505 elif unmerge_action in ["prune","clean"]:
3506 print "\n!!! Prune and clean do not accept individual" + \
3507 " ebuilds as arguments;\n skipping.\n"
3510 # it appears that the user is specifying an installed
3511 # ebuild and we're in "unmerge" mode, so it's ok.
3512 if not os.path.exists(x):
3513 print "\n!!! The path '"+x+"' doesn't exist.\n"
3516 absx = os.path.abspath(x)
3517 sp_absx = absx.split("/")
3518 if sp_absx[-1][-7:] == ".ebuild":
3520 absx = "/".join(sp_absx)
3522 sp_absx_len = len(sp_absx)
3524 vdb_path = os.path.join(settings["ROOT"], portage.VDB_PATH)
3525 vdb_len = len(vdb_path)
3527 sp_vdb = vdb_path.split("/")
3528 sp_vdb_len = len(sp_vdb)
3530 if not os.path.exists(absx+"/CONTENTS"):
3531 print "!!! Not a valid db dir: "+str(absx)
3534 if sp_absx_len <= sp_vdb_len:
3535 # The Path is shorter... so it can't be inside the vdb.
3538 print "\n!!!",x,"cannot be inside "+ \
3539 vdb_path+"; aborting.\n"
3542 for idx in range(0,sp_vdb_len):
3543 if idx >= sp_absx_len or sp_vdb[idx] != sp_absx[idx]:
3546 print "\n!!!", x, "is not inside "+\
3547 vdb_path+"; aborting.\n"
3550 print "="+"/".join(sp_absx[sp_vdb_len:])
3551 candidate_catpkgs.append(
3552 "="+"/".join(sp_absx[sp_vdb_len:]))
3555 if (not "--quiet" in myopts):
3557 if settings["ROOT"] != "/":
3558 print darkgreen(newline+ \
3559 ">>> Using system located in ROOT tree "+settings["ROOT"])
3560 if (("--pretend" in myopts) or ("--ask" in myopts)) and \
3561 not ("--quiet" in myopts):
3562 print darkgreen(newline+\
3563 ">>> These are the packages that would be unmerged:")
3567 for x in candidate_catpkgs:
3568 # cycle through all our candidate deps and determine
3569 # what will and will not get unmerged
3571 mymatch=localtree.dep_match(x)
3574 except ValueError, errpkgs:
3575 print "\n\n!!! The short ebuild name \"" + \
3576 x + "\" is ambiguous. Please specify"
3577 print "!!! one of the following fully-qualified " + \
3578 "ebuild names instead:\n"
3579 for i in errpkgs[0]:
3580 print " " + green(i)
3584 if not mymatch and x[0] not in "<>=~":
3585 #add a "=" if missing
3586 mymatch=localtree.dep_match("="+x)
3588 portage.writemsg("\n--- Couldn't find '%s' to %s.\n" % \
3589 (x, unmerge_action), noiselevel=-1)
3591 mykey = portage.key_expand(
3593 mymatch[0]), mydb=vartree.dbapi, settings=settings)
3594 if not pkgmap.has_key(mykey):
3595 pkgmap[mykey]={"protected":[], "selected":[], "omitted":[] }
3596 if unmerge_action=="unmerge":
3598 if y not in pkgmap[mykey]["selected"]:
3599 pkgmap[mykey]["selected"].append(y)
3600 numselected=numselected+len(mymatch)
3603 #unmerge_action in ["prune", clean"]
3605 for mypkg in mymatch:
3606 if unmerge_action=="clean":
3607 myslot=localtree.getslot(mypkg)
3609 # since we're pruning, we don't care about slots
3610 # and put all the pkgs in together
3612 if not slotmap.has_key(myslot):
3614 slotmap[myslot][localtree.dbapi.cpv_counter(mypkg)]=mypkg
3615 for myslot in slotmap:
3616 counterkeys=slotmap[myslot].keys()
3621 pkgmap[mykey]["protected"].append(
3622 slotmap[myslot][counterkeys[-1]])
3624 #be pretty and get them in order of merge:
3625 for ckey in counterkeys:
3626 pkgmap[mykey]["selected"].append(slotmap[myslot][ckey])
3627 numselected=numselected+1
3628 # ok, now the last-merged package
3629 # is protected, and the rest are selected
3630 if global_unmerge and not numselected:
3631 portage.writemsg_stdout("\n>>> No outdated packages were found on your system.\n")
3635 portage.writemsg_stdout(
3636 "\n>>> No packages selected for removal by " + \
3637 unmerge_action + "\n")
3641 portage.locks.unlockdir(vdb_lock)
3643 for y in localtree.dep_match(x):
3644 if y not in pkgmap[x]["omitted"] and \
3645 y not in pkgmap[x]["selected"] and \
3646 y not in pkgmap[x]["protected"]:
3647 pkgmap[x]["omitted"].append(y)
3648 if global_unmerge and not pkgmap[x]["selected"]:
3649 #avoid cluttering the preview printout with stuff that isn't getting unmerged
3651 if not (pkgmap[x]["protected"] or pkgmap[x]["omitted"]) and (x in syslist):
3652 print colorize("BAD","\a\n\n!!! '%s' is part of your system profile." % x)
3653 print colorize("WARN","\a!!! Unmerging it may be damaging to your system.\n")
3654 if "--pretend" not in myopts and "--ask" not in myopts:
3655 countdown(int(settings["EMERGE_WARNING_DELAY"]),
3656 colorize("UNMERGE_WARN", "Press Ctrl-C to Stop"))
3657 print "\n "+white(x)
3658 for mytype in ["selected","protected","omitted"]:
3659 portage.writemsg_stdout((mytype + ": ").rjust(14), noiselevel=-1)
3660 if pkgmap[x][mytype]:
3661 for mypkg in pkgmap[x][mytype]:
3662 mysplit=portage.catpkgsplit(mypkg)
3663 if mysplit[3]=="r0":
3664 myversion=mysplit[2]
3666 myversion=mysplit[2]+"-"+mysplit[3]
3667 if mytype=="selected":
3668 portage.writemsg_stdout(
3669 colorize("UNMERGE_WARN", myversion + " "), noiselevel=-1)
3671 portage.writemsg_stdout(
3672 colorize("GOOD", myversion + " "), noiselevel=-1)
3674 portage.writemsg_stdout("none", noiselevel=-1)
3675 portage.writemsg_stdout("\n", noiselevel=-1)
3677 portage.writemsg_stdout("\n>>> " + colorize("UNMERGE_WARN", "'Selected'") + \
3678 " packages are slated for removal.\n")
3679 portage.writemsg_stdout(">>> " + colorize("GOOD", "'Protected'") + \
3680 " and " + colorize("GOOD", "'omitted'") + \
3681 " packages will not be removed.\n\n")
3683 if "--pretend" in myopts:
3684 #we're done... return
3686 if "--ask" in myopts:
3687 if userquery("Would you like to unmerge these packages?")=="No":
3688 # enter pretend mode for correct formatting of results
3689 myopts["--pretend"] = True
3694 #the real unmerging begins, after a short delay....
3696 countdown(int(settings["CLEAN_DELAY"]), ">>> Unmerging")
3699 for y in pkgmap[x]["selected"]:
3700 print ">>> Unmerging "+y+"..."
3701 emergelog(xterm_titles, "=== Unmerging... ("+y+")")
3702 mysplit=y.split("/")
3704 retval = portage.unmerge(mysplit[0], mysplit[1], settings["ROOT"],
3705 mysettings, unmerge_action not in ["clean","prune"],
3706 vartree=vartree, ldpath_mtimes=ldpath_mtimes)
3707 if retval != os.EX_OK:
3708 emergelog(xterm_titles, " !!! unmerge FAILURE: "+y)
3709 ebuild = vartree.dbapi.findname(y)
3710 show_unmerge_failure_message(y, ebuild, retval)
3713 clean_world(vartree.dbapi, y)
3714 emergelog(xterm_titles, " >>> unmerge success: "+y)
3717 def show_unmerge_failure_message(pkg, ebuild, retval):
3719 from formatter import AbstractFormatter, DumbWriter
3720 f = AbstractFormatter(DumbWriter(sys.stderr, maxcol=72))
3723 msg.append("A removal phase of the '%s' package " % pkg)
3724 msg.append("has failed with exit value %s. " % retval)
3725 msg.append("The problem occurred while executing ")
3726 msg.append("the ebuild located at '%s'. " % ebuild)
3727 msg.append("If necessary, manually remove the ebuild " )
3728 msg.append("in order to skip the execution of removal phases.")
3732 f.add_flowing_data(x)
3736 def chk_updated_info_files(root, infodirs, prev_mtimes, retval):
3738 if os.path.exists("/usr/bin/install-info"):
3743 inforoot=normpath(root+z)
3744 if os.path.isdir(inforoot):
3745 infomtime = long(os.stat(inforoot).st_mtime)
3746 if inforoot not in prev_mtimes or \
3747 prev_mtimes[inforoot] != infomtime:
3748 regen_infodirs.append(inforoot)
3750 if not regen_infodirs:
3751 portage.writemsg_stdout(" "+green("*")+" GNU info directory index is up-to-date.\n")
3753 portage.writemsg_stdout(" "+green("*")+" Regenerating GNU info directory index...\n")
3757 for inforoot in regen_infodirs:
3760 for filename in ("dir", "dir.gz", "dir.bz2"):
3761 file_path = os.path.join(inforoot, filename)
3763 os.rename(file_path, file_path + ".old")
3765 if e.errno != errno.ENOENT:
3769 if not os.path.isdir(inforoot):
3772 file_list = os.listdir(inforoot)
3775 if (x[0] == ".") or (x in ["dir","dir.old"]) or (os.path.isdir(inforoot+"/"+x)):
3777 myso=commands.getstatusoutput("LANG=C LANGUAGE=C /usr/bin/install-info --dir-file="+inforoot+"/dir "+inforoot+"/"+x)[1]
3778 existsstr="already exists, for file `"
3780 if re.search(existsstr,myso):
3781 # Already exists... Don't increment the count for this.
3783 elif myso[:44]=="install-info: warning: no info dir entry in ":
3784 # This info file doesn't contain a DIR-header: install-info produces this
3785 # (harmless) warning (the --quiet switch doesn't seem to work).
3786 # Don't increment the count for this.
3790 errmsg += myso + "\n"
3793 #update mtime so we can potentially avoid regenerating.
3794 prev_mtimes[inforoot] = long(os.stat(inforoot).st_mtime)
3797 print " "+yellow("*")+" Processed",icount,"info files;",badcount,"errors."
3800 print " "+green("*")+" Processed",icount,"info files."
3803 def display_news_notification(trees):
3804 for target_root in trees:
3805 if len(trees) > 1 and target_root != "/":
3807 settings = trees[target_root]["vartree"].settings
3808 portdb = trees[target_root]["porttree"].dbapi
3809 vardb = trees[target_root]["vartree"].dbapi
3810 NEWS_PATH = os.path.join("metadata", "news")
3811 UNREAD_PATH = os.path.join(target_root, NEWS_LIB_PATH, "news")
3812 newsReaderDisplay = False
3814 for repo in portdb.getRepositories():
3815 unreadItems = checkUpdatedNewsItems(
3816 portdb, vardb, NEWS_PATH, UNREAD_PATH, repo)
3818 if not newsReaderDisplay:
3819 newsReaderDisplay = True
3821 print colorize("WARN", " * IMPORTANT:"),
3822 print "%s news items need reading for repository '%s'." % (unreadItems, repo)
3825 if newsReaderDisplay:
3826 print colorize("WARN", " *"),
3827 print "Use " + colorize("GOOD", "eselect news") + " to read news items."
3830 def post_emerge(trees, mtimedb, retval):
3832 Misc. things to run at the end of a merge session.
3838 Display preserved libs warnings
3841 @param trees: A dictionary mapping each ROOT to it's package databases
3843 @param mtimedb: The mtimeDB to store data needed across merge invocations
3844 @type mtimedb: MtimeDB class instance
3845 @param retval: Emerge's return value
3849 1. Calls sys.exit(retval)
3851 for target_root in trees:
3852 if len(trees) > 1 and target_root != "/":
3854 vardbapi = trees[target_root]["vartree"].dbapi
3855 settings = vardbapi.settings
3856 info_mtimes = mtimedb["info"]
3858 # Load the most current variables from ${ROOT}/etc/profile.env
3860 settings.regenerate()
3863 config_protect = settings.get("CONFIG_PROTECT","").split()
3864 infodirs = settings.get("INFOPATH","").split(":") + \
3865 settings.get("INFODIR","").split(":")
3869 emergelog("notitles" not in settings.features,
3870 " *** exiting successfully.")
3872 # Dump the mod_echo output now so that our other notifications are shown
3874 from portage.elog import mod_echo
3877 if "noinfo" not in settings.features:
3878 chk_updated_info_files(target_root, infodirs, info_mtimes, retval)
3880 chk_updated_cfg_files(target_root, config_protect)
3882 display_news_notification(trees)
3884 if vardbapi.plib_registry.hasEntries():
3885 print colorize("WARN", "!!!") + " existing preserved libs:"
3886 plibdata = vardbapi.plib_registry.getPreservedLibs()
3887 for cpv in plibdata:
3888 print colorize("WARN", ">>>") + " package: %s" % cpv
3889 for f in plibdata[cpv]:
3890 print colorize("WARN", " * ") + " - %s" % f
3891 print "Use " + colorize("GOOD", "revdep-rebuild") + " to rebuild packages using these libraries"
3892 print "and then remerge the packages listed above."
3898 def chk_updated_cfg_files(target_root, config_protect):
3900 #number of directories with some protect files in them
3902 for x in config_protect:
3903 x = os.path.join(target_root, x.lstrip(os.path.sep))
3905 mymode = os.lstat(x).st_mode
3908 if stat.S_ISDIR(mymode):
3909 mycommand = "cd '%s'; find . -iname '._cfg????_*'" % x
3911 mycommand = "cd '%s'; find . -maxdepth 1 -iname '._cfg????_%s'" % \
3912 os.path.split(x.rstrip(os.path.sep))
3913 a = commands.getstatusoutput(mycommand + \
3914 " ! -iname '.*~' ! -iname '.*.bak'")
3916 print >> sys.stderr, " " + bad("*")+ " error scanning '%s'" % x
3918 files = a[1].split()
3921 print colorize("WARN", " * IMPORTANT:"),
3922 if stat.S_ISDIR(mymode):
3923 print "%d config files in '%s' need updating." % \
3926 print "config file '%s' needs updating." % x
3929 #print " "+yellow("*")+" Type "+green("emerge --help config")+" to learn how to update config files."
3930 print " "+yellow("*")+" Type "+green("emerge --help config")+" to learn how to update config files."
3932 def checkUpdatedNewsItems(portdb, vardb, NEWS_PATH, UNREAD_PATH, repo_id):
3934 Examines news items in repodir + '/' + NEWS_PATH and attempts to find unread items
3935 Returns the number of unread (yet relevent) items.
3937 @param portdb: a portage tree database
3938 @type portdb: pordbapi
3939 @param vardb: an installed package database
3940 @type vardb: vardbapi
3949 1. The number of unread but relevant news items.
3952 from portage.news import NewsManager
3953 manager = NewsManager(portdb, vardb, NEWS_PATH, UNREAD_PATH)
3954 return manager.getUnreadItems( repo_id, update=True )
3956 def is_valid_package_atom(x):
3958 testkey = portage.dep_getkey(x)
3959 except portage.exception.InvalidData:
3961 if testkey.startswith("null/"):
3962 testatom = x.replace(testkey[5:], "cat/"+testkey[5:])
3967 return portage.isvalidatom(testatom)
3969 def validate_merge_list(trees, mergelist):
3970 """Validate the list to make sure all the packages are still available.
3971 This is needed for --resume."""
3972 for (pkg_type, myroot, pkg_key, action) in mergelist:
3973 if pkg_type == "binary" and \
3974 not trees[myroot]["bintree"].dbapi.match("="+pkg_key) or \
3975 pkg_type == "ebuild" and \
3976 not trees[myroot]["porttree"].dbapi.xmatch(
3977 "match-all", "="+pkg_key):
3978 print red("!!! Error: The resume list contains packages that are no longer")
3979 print red("!!! available to be emerged. Please restart/continue")
3980 print red("!!! the merge operation manually.")
3983 def show_blocker_docs_link():
3985 print "For more information about " + bad("Blocked Packages") + ", please refer to the following"
3986 print "section of the Gentoo Linux x86 Handbook (architecture is irrelevant):"
3988 print "http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?full=1#blocked"
3991 def action_sync(settings, trees, mtimedb, myopts, myaction):
3992 xterm_titles = "notitles" not in settings.features
3993 emergelog(xterm_titles, " === sync")
3994 myportdir = settings.get("PORTDIR", None)
3996 sys.stderr.write("!!! PORTDIR is undefined. Is /etc/make.globals missing?\n")
3998 if myportdir[-1]=="/":
3999 myportdir=myportdir[:-1]
4000 if not os.path.exists(myportdir):
4001 print ">>>",myportdir,"not found, creating it."
4002 os.makedirs(myportdir,0755)
4003 syncuri=settings["SYNC"].rstrip()
4005 updatecache_flg = False
4006 if myaction == "metadata":
4007 print "skipping sync"
4008 updatecache_flg = True
4009 tmpservertimestampfile = None
4010 elif syncuri[:8]=="rsync://":
4011 if not os.path.exists("/usr/bin/rsync"):
4012 print "!!! /usr/bin/rsync does not exist, so rsync support is disabled."
4013 print "!!! Type \"emerge net-misc/rsync\" to enable rsync support."
4018 import shlex, StringIO
4019 if settings["PORTAGE_RSYNC_OPTS"] == "":
4020 portage.writemsg("PORTAGE_RSYNC_OPTS empty or unset, using hardcoded defaults\n")
4022 "--recursive", # Recurse directories
4023 "--links", # Consider symlinks
4024 "--safe-links", # Ignore links outside of tree
4025 "--perms", # Preserve permissions
4026 "--times", # Preserive mod times
4027 "--compress", # Compress the data transmitted
4028 "--force", # Force deletion on non-empty dirs
4029 "--whole-file", # Don't do block transfers, only entire files
4030 "--delete", # Delete files that aren't in the master tree
4031 "--delete-after", # Delete only after everything else is done
4032 "--stats", # Show final statistics about what was transfered
4033 "--timeout="+str(mytimeout), # IO timeout if not done in X seconds
4034 "--exclude=/distfiles", # Exclude distfiles from consideration
4035 "--exclude=/local", # Exclude local from consideration
4036 "--exclude=/packages", # Exclude packages from consideration
4037 "--filter=H_**/files/digest-*", # Exclude manifest1 digests and delete on the receiving side
4041 # The below validation is not needed when using the above hardcoded
4044 portage.writemsg("Using PORTAGE_RSYNC_OPTS instead of hardcoded defaults\n", 1)
4045 lexer = shlex.shlex(StringIO.StringIO(
4046 settings.get("PORTAGE_RSYNC_OPTS","")), posix=True)
4047 lexer.whitespace_split = True
4048 rsync_opts.extend(lexer)
4051 for opt in ("--recursive", "--times"):
4052 if opt not in rsync_opts:
4053 portage.writemsg(yellow("WARNING:") + " adding required option " + \
4054 "%s not included in PORTAGE_RSYNC_OPTS\n" % opt)
4055 rsync_opts.append(opt)
4057 for exclude in ("distfiles", "local", "packages"):
4058 opt = "--exclude=/%s" % exclude
4059 if opt not in rsync_opts:
4060 portage.writemsg(yellow("WARNING:") + \
4061 " adding required option %s not included in " % opt + \
4062 "PORTAGE_RSYNC_OPTS (can be overridden with --exclude='!')\n")
4063 rsync_opts.append(opt)
4065 if settings["RSYNC_TIMEOUT"] != "":
4066 portage.writemsg("WARNING: usage of RSYNC_TIMEOUT is deprecated, " + \
4067 "use PORTAGE_RSYNC_EXTRA_OPTS instead\n")
4069 mytimeout = int(settings["RSYNC_TIMEOUT"])
4070 rsync_opts.append("--timeout=%d" % mytimeout)
4071 except ValueError, e:
4072 portage.writemsg("!!! %s\n" % str(e))
4074 # TODO: determine options required for official servers
4075 if syncuri.rstrip("/").endswith(".gentoo.org/gentoo-portage"):
4077 def rsync_opt_startswith(opt_prefix):
4078 for x in rsync_opts:
4079 if x.startswith(opt_prefix):
4083 if not rsync_opt_startswith("--timeout="):
4084 rsync_opts.append("--timeout=%d" % mytimeout)
4086 for opt in ("--compress", "--whole-file"):
4087 if opt not in rsync_opts:
4088 portage.writemsg(yellow("WARNING:") + " adding required option " + \
4089 "%s not included in PORTAGE_RSYNC_OPTS\n" % opt)
4090 rsync_opts.append(opt)
4092 if "--quiet" in myopts:
4093 rsync_opts.append("--quiet") # Shut up a lot
4095 rsync_opts.append("--verbose") # Print filelist
4097 if "--verbose" in myopts:
4098 rsync_opts.append("--progress") # Progress meter for each file
4100 if "--debug" in myopts:
4101 rsync_opts.append("--checksum") # Force checksum on all files
4103 if settings["RSYNC_EXCLUDEFROM"] != "":
4104 portage.writemsg(yellow("WARNING:") + \
4105 " usage of RSYNC_EXCLUDEFROM is deprecated, use " + \
4106 "PORTAGE_RSYNC_EXTRA_OPTS instead\n")
4107 if os.path.exists(settings["RSYNC_EXCLUDEFROM"]):
4108 rsync_opts.append("--exclude-from=%s" % \
4109 settings["RSYNC_EXCLUDEFROM"])
4111 portage.writemsg("!!! RSYNC_EXCLUDEFROM specified," + \
4112 " but file does not exist.\n")
4114 if settings["RSYNC_RATELIMIT"] != "":
4115 portage.writemsg(yellow("WARNING:") + \
4116 " usage of RSYNC_RATELIMIT is deprecated, use " + \
4117 "PORTAGE_RSYNC_EXTRA_OPTS instead")
4118 rsync_opts.append("--bwlimit=%s" % \
4119 settings["RSYNC_RATELIMIT"])
4121 # Real local timestamp file.
4122 servertimestampfile = os.path.join(
4123 myportdir, "metadata", "timestamp.chk")
4124 # Temporary file for remote server timestamp comparison.
4125 tmpservertimestampfile = os.path.join(
4126 settings["PORTAGE_TMPDIR"], "timestamp.chk")
4128 content = portage.util.grabfile(servertimestampfile)
4132 mytimestamp = time.mktime(time.strptime(content[0],
4133 "%a, %d %b %Y %H:%M:%S +0000"))
4134 except (OverflowError, ValueError):
4139 rsync_initial_timeout = \
4140 int(settings.get("PORTAGE_RSYNC_INITIAL_TIMEOUT", "15"))
4142 rsync_initial_timeout = 15
4145 if settings.has_key("RSYNC_RETRIES"):
4146 print yellow("WARNING:")+" usage of RSYNC_RETRIES is deprecated, use PORTAGE_RSYNC_RETRIES instead"
4147 maxretries=int(settings["RSYNC_RETRIES"])
4149 maxretries=int(settings["PORTAGE_RSYNC_RETRIES"])
4150 except SystemExit, e:
4151 raise # Needed else can't exit
4153 maxretries=3 #default number of retries
4156 user_name, hostname, port = re.split(
4157 "rsync://([^:/]+@)?([^:/]*)(:[0-9]+)?", syncuri, maxsplit=3)[1:4]
4160 if user_name is None:
4162 updatecache_flg=True
4163 all_rsync_opts = set(rsync_opts)
4164 lexer = shlex.shlex(StringIO.StringIO(
4165 settings.get("PORTAGE_RSYNC_EXTRA_OPTS","")), posix=True)
4166 lexer.whitespace_split = True
4167 extra_rsync_opts = list(lexer)
4169 all_rsync_opts.update(extra_rsync_opts)
4170 family = socket.AF_INET
4171 if "-4" in all_rsync_opts or "--ipv4" in all_rsync_opts:
4172 family = socket.AF_INET
4173 elif socket.has_ipv6 and \
4174 ("-6" in all_rsync_opts or "--ipv6" in all_rsync_opts):
4175 family = socket.AF_INET6
4182 for addrinfo in socket.getaddrinfo(
4183 hostname, None, family, socket.SOCK_STREAM):
4184 if addrinfo[0] == socket.AF_INET6:
4185 # IPv6 addresses need to be enclosed in square brackets
4186 ips.append("[%s]" % addrinfo[4][0])
4188 ips.append(addrinfo[4][0])
4189 from random import shuffle
4191 except SystemExit, e:
4192 raise # Needed else can't exit
4193 except Exception, e:
4194 print "Notice:",str(e)
4199 dosyncuri = syncuri.replace(
4200 "//" + user_name + hostname + port + "/",
4201 "//" + user_name + ips[0] + port + "/", 1)
4202 except SystemExit, e:
4203 raise # Needed else can't exit
4204 except Exception, e:
4205 print "Notice:",str(e)
4209 if "--ask" in myopts:
4210 if userquery("Do you want to sync your Portage tree with the mirror at\n" + blue(dosyncuri) + bold("?"))=="No":
4215 emergelog(xterm_titles, ">>> Starting rsync with " + dosyncuri)
4216 if "--quiet" not in myopts:
4217 print ">>> Starting rsync with "+dosyncuri+"..."
4219 emergelog(xterm_titles,
4220 ">>> Starting retry %d of %d with %s" % \
4221 (retries,maxretries,dosyncuri))
4222 print "\n\n>>> Starting retry %d of %d with %s" % (retries,maxretries,dosyncuri)
4224 if mytimestamp != 0 and "--quiet" not in myopts:
4225 print ">>> Checking server timestamp ..."
4227 rsynccommand = ["/usr/bin/rsync"] + rsync_opts + extra_rsync_opts
4229 if "--debug" in myopts:
4234 # Even if there's no timestamp available locally, fetch the
4235 # timestamp anyway as an initial probe to verify that the server is
4236 # responsive. This protects us from hanging indefinitely on a
4237 # connection attempt to an unresponsive server which rsync's
4238 # --timeout option does not prevent.
4240 mycommand = rsynccommand[:]
4241 mycommand.append(dosyncuri.rstrip("/") + \
4242 "/metadata/timestamp.chk")
4243 mycommand.append(tmpservertimestampfile)
4247 def timeout_handler(signum, frame):
4248 raise portage.exception.PortageException("timed out")
4249 signal.signal(signal.SIGALRM, timeout_handler)
4250 # Timeout here in case the server is unresponsive. The
4251 # --timeout rsync option doesn't apply to the initial
4252 # connection attempt.
4253 if rsync_initial_timeout:
4254 signal.alarm(rsync_initial_timeout)
4256 mypids.extend(portage.process.spawn(
4257 mycommand, env=settings.environ(), returnpid=True))
4258 exitcode = os.waitpid(mypids[0], 0)[1]
4259 content = portage.grabfile(tmpservertimestampfile)
4261 if rsync_initial_timeout:
4264 os.unlink(tmpservertimestampfile)
4267 except portage.exception.PortageException, e:
4271 if mypids and os.waitpid(mypids[0], os.WNOHANG) == (0,0):
4272 os.kill(mypids[0], signal.SIGTERM)
4273 os.waitpid(mypids[0], 0)
4274 # This is the same code rsync uses for timeout.
4277 if exitcode != os.EX_OK:
4279 exitcode = (exitcode & 0xff) << 8
4281 exitcode = exitcode >> 8
4283 portage.process.spawned_pids.remove(mypids[0])
4286 servertimestamp = time.mktime(time.strptime(
4287 content[0], "%a, %d %b %Y %H:%M:%S +0000"))
4288 except (OverflowError, ValueError):
4290 del mycommand, mypids, content
4291 if exitcode == os.EX_OK:
4292 if (servertimestamp != 0) and (servertimestamp == mytimestamp):
4293 emergelog(xterm_titles,
4294 ">>> Cancelling sync -- Already current.")
4297 print ">>> Timestamps on the server and in the local repository are the same."
4298 print ">>> Cancelling all further sync action. You are already up to date."
4300 print ">>> In order to force sync, remove '%s'." % servertimestampfile
4304 elif (servertimestamp != 0) and (servertimestamp < mytimestamp):
4305 emergelog(xterm_titles,
4306 ">>> Server out of date: %s" % dosyncuri)
4309 print ">>> SERVER OUT OF DATE: %s" % dosyncuri
4311 print ">>> In order to force sync, remove '%s'." % servertimestampfile
4314 elif (servertimestamp == 0) or (servertimestamp > mytimestamp):
4316 mycommand = rsynccommand + [dosyncuri+"/", myportdir]
4317 exitcode = portage.process.spawn(mycommand,
4318 env=settings.environ())
4319 if exitcode in [0,1,3,4,11,14,20,21]:
4321 elif exitcode in [1,3,4,11,14,20,21]:
4324 # Code 2 indicates protocol incompatibility, which is expected
4325 # for servers with protocol < 29 that don't support
4326 # --prune-empty-directories. Retry for a server that supports
4327 # at least rsync protocol version 29 (>=rsync-2.6.4).
4332 if retries<=maxretries:
4333 print ">>> Retrying..."
4338 updatecache_flg=False
4342 emergelog(xterm_titles, "=== Sync completed with %s" % dosyncuri)
4346 print darkred("!!!")+green(" Rsync has reported that there is a syntax error. Please ensure")
4347 print darkred("!!!")+green(" that your SYNC statement is proper.")
4348 print darkred("!!!")+green(" SYNC="+settings["SYNC"])
4350 print darkred("!!!")+green(" Rsync has reported that there is a File IO error. Normally")
4351 print darkred("!!!")+green(" this means your disk is full, but can be caused by corruption")
4352 print darkred("!!!")+green(" on the filesystem that contains PORTDIR. Please investigate")
4353 print darkred("!!!")+green(" and try again after the problem has been fixed.")
4354 print darkred("!!!")+green(" PORTDIR="+settings["PORTDIR"])
4356 print darkred("!!!")+green(" Rsync was killed before it finished.")
4358 print darkred("!!!")+green(" Rsync has not successfully finished. It is recommended that you keep")
4359 print darkred("!!!")+green(" trying or that you use the 'emerge-webrsync' option if you are unable")
4360 print darkred("!!!")+green(" to use rsync due to firewall or other restrictions. This should be a")
4361 print darkred("!!!")+green(" temporary problem unless complications exist with your network")
4362 print darkred("!!!")+green(" (and possibly your system's filesystem) configuration.")
4365 elif syncuri[:6]=="cvs://":
4366 if not os.path.exists("/usr/bin/cvs"):
4367 print "!!! /usr/bin/cvs does not exist, so CVS support is disabled."
4368 print "!!! Type \"emerge dev-util/cvs\" to enable CVS support."
4371 cvsdir=os.path.dirname(myportdir)
4372 if not os.path.exists(myportdir+"/CVS"):
4374 print ">>> Starting initial cvs checkout with "+syncuri+"..."
4375 if os.path.exists(cvsdir+"/gentoo-x86"):
4376 print "!!! existing",cvsdir+"/gentoo-x86 directory; exiting."
4381 if e.errno != errno.ENOENT:
4383 "!!! existing '%s' directory; exiting.\n" % myportdir)
4386 if portage.spawn("cd "+cvsdir+"; cvs -z0 -d "+cvsroot+" co -P gentoo-x86",settings,free=1):
4387 print "!!! cvs checkout error; exiting."
4389 os.rename(os.path.join(cvsdir, "gentoo-x86"), myportdir)
4392 print ">>> Starting cvs update with "+syncuri+"..."
4393 retval = portage.spawn("cd '%s'; cvs -z0 -q update -dP" % \
4394 myportdir, settings, free=1)
4395 if retval != os.EX_OK:
4399 print "!!! rsync setting: ",syncuri,"not recognized; exiting."
4402 if updatecache_flg and \
4403 myaction != "metadata" and \
4404 "metadata-transfer" not in settings.features:
4405 updatecache_flg = False
4407 # Reload the whole config from scratch.
4408 settings, trees, mtimedb = load_emerge_config(trees=trees)
4409 portdb = trees[settings["ROOT"]]["porttree"].dbapi
4411 if os.path.exists(myportdir+"/metadata/cache") and updatecache_flg:
4412 action_metadata(settings, portdb, myopts)
4414 if portage._global_updates(trees, mtimedb["updates"]):
4416 # Reload the whole config from scratch.
4417 settings, trees, mtimedb = load_emerge_config(trees=trees)
4418 portdb = trees[settings["ROOT"]]["porttree"].dbapi
4420 mybestpv = portdb.xmatch("bestmatch-visible", "sys-apps/portage")
4421 mypvs = portage.best(
4422 trees[settings["ROOT"]]["vartree"].dbapi.match("sys-apps/portage"))
4424 chk_updated_cfg_files("/", settings.get("CONFIG_PROTECT","").split())
4426 if myaction != "metadata":
4427 if os.access(portage.USER_CONFIG_PATH + "/bin/post_sync", os.X_OK):
4428 retval = portage.process.spawn(
4429 [os.path.join(portage.USER_CONFIG_PATH, "bin", "post_sync"),
4430 dosyncuri], env=settings.environ())
4431 if retval != os.EX_OK:
4432 print red(" * ")+bold("spawn failed of "+ portage.USER_CONFIG_PATH + "/bin/post_sync")
4434 if(mybestpv != mypvs) and not "--quiet" in myopts:
4436 print red(" * ")+bold("An update to portage is available.")+" It is _highly_ recommended"
4437 print red(" * ")+"that you update portage now, before any other packages are updated."
4438 print red(" * ")+"Please run 'emerge portage' and then update "+bold("ALL")+" of your"
4439 print red(" * ")+"configuration files."
4440 print red(" * ")+"To update portage, run 'emerge portage'."
4443 display_news_notification(trees)
4445 def action_metadata(settings, portdb, myopts):
4446 portage.writemsg_stdout("\n>>> Updating Portage cache: ")
4447 old_umask = os.umask(0002)
4448 cachedir = os.path.normpath(settings.depcachedir)
4449 if cachedir in ["/", "/bin", "/dev", "/etc", "/home",
4450 "/lib", "/opt", "/proc", "/root", "/sbin",
4451 "/sys", "/tmp", "/usr", "/var"]:
4452 print >> sys.stderr, "!!! PORTAGE_DEPCACHEDIR IS SET TO A PRIMARY " + \
4453 "ROOT DIRECTORY ON YOUR SYSTEM."
4454 print >> sys.stderr, \
4455 "!!! This is ALMOST CERTAINLY NOT what you want: '%s'" % cachedir
4457 if not os.path.exists(cachedir):
4460 ec = portage.eclass_cache.cache(portdb.porttree_root)
4461 myportdir = os.path.realpath(settings["PORTDIR"])
4462 cm = settings.load_best_module("portdbapi.metadbmodule")(
4463 myportdir, "metadata/cache", portage.auxdbkeys[:])
4465 from portage.cache import util
4467 class percentage_noise_maker(util.quiet_mirroring):
4468 def __init__(self, dbapi):
4470 self.cp_all = dbapi.cp_all()
4471 l = len(self.cp_all)
4472 self.call_update_min = 100000000
4473 self.min_cp_all = l/100.0
4478 for x in self.cp_all:
4480 if self.count > self.min_cp_all:
4481 self.call_update_min = 0
4483 for y in self.dbapi.cp_list(x):
4485 self.call_update_mine = 0
4487 def update(self, *arg):
4488 try: self.pstr = int(self.pstr) + 1
4489 except ValueError: self.pstr = 1
4490 sys.stdout.write("%s%i%%" % \
4491 ("\b" * (len(str(self.pstr))+1), self.pstr))
4493 self.call_update_min = 10000000
4495 def finish(self, *arg):
4496 sys.stdout.write("\b\b\b\b100%\n")
4499 if "--quiet" in myopts:
4500 def quicky_cpv_generator(cp_all_list):
4501 for x in cp_all_list:
4502 for y in portdb.cp_list(x):
4504 source = quicky_cpv_generator(portdb.cp_all())
4505 noise_maker = portage.cache.util.quiet_mirroring()
4507 noise_maker = source = percentage_noise_maker(portdb)
4508 portage.cache.util.mirror_cache(source, cm, portdb.auxdb[myportdir],
4509 eclass_cache=ec, verbose_instance=noise_maker)
4514 def action_regen(settings, portdb):
4515 xterm_titles = "notitles" not in settings.features
4516 emergelog(xterm_titles, " === regen")
4517 #regenerate cache entries
4518 print "Regenerating cache entries... "
4520 os.close(sys.stdin.fileno())
4521 except SystemExit, e:
4522 raise # Needed else can't exit
4526 mynodes = portdb.cp_all()
4527 from portage.cache.cache_errors import CacheError
4529 for mytree in portdb.porttrees:
4531 dead_nodes[mytree] = set(portdb.auxdb[mytree].iterkeys())
4532 except CacheError, e:
4533 print "\n error listing cache entries for " + \
4534 "'%s': %s, continuing..." % (mytree, e)
4539 mymatches = portdb.cp_list(x)
4540 portage.writemsg_stdout("processing %s\n" % x)
4543 foo = portdb.aux_get(y,["DEPEND"])
4544 except SystemExit, e:
4545 # sys.exit is an exception... And consequently, we can't catch it.
4547 except Exception, e:
4548 print "\n error processing %(cpv)s, continuing... (%(e)s)" % {"cpv":y,"e":str(e)}
4550 for mytree in portdb.porttrees:
4551 if portdb.findname2(y, mytree=mytree)[0]:
4552 dead_nodes[mytree].discard(y)
4554 for mytree, nodes in dead_nodes.iteritems():
4555 auxdb = portdb.auxdb[mytree]
4559 except (KeyError, CacheError):
4563 def action_config(settings, trees, myopts, myfiles):
4564 if len(myfiles) != 1 or "system" in myfiles or "world" in myfiles:
4565 print red("!!! config can only take a single package atom at this time\n")
4567 if not is_valid_package_atom(myfiles[0]):
4568 portage.writemsg("!!! '%s' is not a valid package atom.\n" % myfiles[0],
4570 portage.writemsg("!!! Please check ebuild(5) for full details.\n")
4571 portage.writemsg("!!! (Did you specify a version but forget to prefix with '='?)\n")
4575 pkgs = trees[settings["ROOT"]]["vartree"].dbapi.match(myfiles[0])
4576 except ValueError, e:
4577 # Multiple matches thrown from cpv_expand
4580 print "No packages found.\n"
4583 if "--ask" in myopts:
4585 print "Please select a package to configure:"
4589 options.append(str(idx))
4590 print options[-1]+") "+pkg
4593 idx = userquery("Selection?", options)
4596 pkg = pkgs[int(idx)-1]
4598 print "The following packages available:"
4601 print "\nPlease use a specific atom or the --ask option."
4607 if "--ask" in myopts:
4608 if userquery("Ready to configure "+pkg+"?") == "No":
4611 print "Configuring pkg..."
4613 ebuildpath = trees[settings["ROOT"]]["vartree"].dbapi.findname(pkg)
4614 mysettings = portage.config(clone=settings)
4615 portage.doebuild(ebuildpath, "config", settings["ROOT"], mysettings,
4616 debug=(settings.get("PORTAGE_DEBUG", "") == 1), cleanup=True,
4617 mydbapi=trees[settings["ROOT"]]["vartree"].dbapi, tree="vartree")
4620 def action_info(settings, trees, myopts, myfiles):
4621 unameout=commands.getstatusoutput("uname -mrp")[1]
4622 print getportageversion(settings["PORTDIR"], settings["ROOT"],
4623 settings.profile_path, settings["CHOST"],
4624 trees[settings["ROOT"]]["vartree"].dbapi)
4626 header_title = "System Settings"
4628 print header_width * "="
4629 print header_title.rjust(int(header_width/2 + len(header_title)/2))
4630 print header_width * "="
4631 print "System uname: "+unameout
4632 gentoo_release = portage.grabfile(os.path.join(
4633 settings["PORTAGE_CONFIGROOT"], "etc", "gentoo-release"))
4635 print gentoo_release[0]
4637 print "Unknown Host Operating System"
4638 lastSync = portage.grabfile(os.path.join(
4639 settings["PORTDIR"], "metadata", "timestamp.chk"))
4640 print "Timestamp of tree:",
4646 output=commands.getstatusoutput("distcc --version")
4648 print str(output[1].split("\n",1)[0]),
4649 if "distcc" in settings.features:
4654 output=commands.getstatusoutput("ccache -V")
4656 print str(output[1].split("\n",1)[0]),
4657 if "ccache" in settings.features:
4662 myvars = ["sys-devel/autoconf", "sys-devel/automake", "virtual/os-headers",
4663 "sys-devel/binutils", "sys-devel/libtool", "dev-lang/python"]
4664 myvars += portage.util.grabfile(settings["PORTDIR"]+"/profiles/info_pkgs")
4665 myvars = portage.util.unique_array(myvars)
4669 if portage.isvalidatom(x):
4670 pkg_matches = trees["/"]["vartree"].dbapi.match(x)
4671 pkg_matches = [portage.catpkgsplit(cpv)[1:] for cpv in pkg_matches]
4672 pkg_matches.sort(portage.pkgcmp)
4674 for pn, ver, rev in pkg_matches:
4676 pkgs.append(ver + "-" + rev)
4680 pkgs = ", ".join(pkgs)
4681 print "%-20s %s" % (x+":", pkgs)
4683 print "%-20s %s" % (x+":", "[NOT VALID]")
4685 libtool_vers = ",".join(trees["/"]["vartree"].dbapi.match("sys-devel/libtool"))
4687 if "--verbose" in myopts:
4688 myvars=settings.keys()
4690 myvars = ['GENTOO_MIRRORS', 'CONFIG_PROTECT', 'CONFIG_PROTECT_MASK',
4691 'PORTDIR', 'DISTDIR', 'PKGDIR', 'PORTAGE_TMPDIR',
4692 'PORTDIR_OVERLAY', 'USE', 'CHOST', 'CFLAGS', 'CXXFLAGS',
4693 'ACCEPT_KEYWORDS', 'SYNC', 'FEATURES', 'EMERGE_DEFAULT_OPTS']
4695 myvars.extend(portage.util.grabfile(settings["PORTDIR"]+"/profiles/info_vars"))
4697 myvars = portage.util.unique_array(myvars)
4703 print '%s="%s"' % (x, settings[x])
4705 use = set(settings["USE"].split())
4706 use_expand = settings["USE_EXPAND"].split()
4708 for varname in use_expand:
4709 flag_prefix = varname.lower() + "_"
4711 if f.startswith(flag_prefix):
4715 print 'USE="%s"' % " ".join(use),
4716 for varname in use_expand:
4717 myval = settings.get(varname)
4719 print '%s="%s"' % (varname, myval),
4722 unset_vars.append(x)
4724 print "Unset: "+", ".join(unset_vars)
4727 if "--debug" in myopts:
4728 for x in dir(portage):
4729 module = getattr(portage, x)
4730 if "cvs_id_string" in dir(module):
4731 print "%s: %s" % (str(x), str(module.cvs_id_string))
4733 # See if we can find any packages installed matching the strings
4734 # passed on the command line
4736 vardb = trees[settings["ROOT"]]["vartree"].dbapi
4737 portdb = trees[settings["ROOT"]]["porttree"].dbapi
4739 mypkgs.extend(vardb.match(x))
4741 # If some packages were found...
4743 # Get our global settings (we only print stuff if it varies from
4744 # the current config)
4745 mydesiredvars = [ 'CHOST', 'CFLAGS', 'CXXFLAGS' ]
4746 auxkeys = mydesiredvars + [ "USE", "IUSE"]
4748 pkgsettings = portage.config(clone=settings)
4750 for myvar in mydesiredvars:
4751 global_vals[myvar] = set(settings.get(myvar, "").split())
4753 # Loop through each package
4754 # Only print settings if they differ from global settings
4755 header_printed = False
4757 # Get all package specific variables
4758 auxvalues = vardb.aux_get(pkg, auxkeys)
4760 for i in xrange(len(auxkeys)):
4761 valuesmap[auxkeys[i]] = set(auxvalues[i].split())
4763 for myvar in mydesiredvars:
4764 # If the package variable doesn't match the
4765 # current global variable, something has changed
4766 # so set diff_found so we know to print
4767 if valuesmap[myvar] != global_vals[myvar]:
4768 diff_values[myvar] = valuesmap[myvar]
4769 valuesmap["IUSE"] = set(filter_iuse_defaults(valuesmap["IUSE"]))
4770 valuesmap["USE"] = valuesmap["USE"].intersection(valuesmap["IUSE"])
4772 # If a matching ebuild is no longer available in the tree, maybe it
4773 # would make sense to compare against the flags for the best
4774 # available version with the same slot?
4776 if portdb.cpv_exists(pkg):
4778 pkgsettings.setcpv(pkg, mydb=mydb)
4779 if valuesmap["IUSE"].intersection(pkgsettings["USE"].split()) != \
4781 diff_values["USE"] = valuesmap["USE"]
4782 # If a difference was found, print the info for
4786 # If we have not yet printed the header,
4788 if not header_printed:
4789 header_title = "Package Settings"
4790 print header_width * "="
4791 print header_title.rjust(int(header_width/2 + len(header_title)/2))
4792 print header_width * "="
4793 header_printed = True
4795 # Print package info
4796 print "%s was built with the following:" % pkg
4797 for myvar in mydesiredvars + ["USE"]:
4798 if myvar in diff_values:
4799 mylist = list(diff_values[myvar])
4801 print "%s=\"%s\"" % (myvar, " ".join(mylist))
4804 def action_search(settings, portdb, vartree, myopts, myfiles, spinner):
4806 print "emerge: no search terms provided."
4808 searchinstance = search(settings, portdb,
4809 vartree, spinner, "--searchdesc" in myopts,
4810 "--quiet" not in myopts)
4811 for mysearch in myfiles:
4813 searchinstance.execute(mysearch)
4814 except re.error, comment:
4815 print "\n!!! Regular expression error in \"%s\": %s" % ( mysearch, comment )
4817 searchinstance.output()
4819 def action_depclean(settings, trees, ldpath_mtimes,
4821 # Kill packages that aren't explicitly merged or are required as a
4822 # dependency of another package. World file is explicit.
4824 warn_prefix = colorize("BAD", "*** WARNING *** ")
4826 print warn_prefix + "Depclean may break link level dependencies. Thus, it is"
4827 print warn_prefix + "recommended to use a tool such as " + good("`revdep-rebuild`") + " (from"
4828 print warn_prefix + "app-portage/gentoolkit) in order to detect such breakage."
4830 print warn_prefix + "Also study the list of packages to be cleaned for any obvious"
4831 print warn_prefix + "mistakes. Packages that are part of the world set will always"
4832 print warn_prefix + "be kept. They can be manually added to this set with"
4833 print warn_prefix + good("`emerge --noreplace <atom>`") + ". Packages that are listed in"
4834 print warn_prefix + "package.provided (see portage(5)) will be removed by"
4835 print warn_prefix + "depclean, even if they are part of the world set."
4837 print warn_prefix + "As a safety measure, depclean will not remove any packages"
4838 print warn_prefix + "unless *all* required dependencies have been resolved. As a"
4839 print warn_prefix + "consequence, it is often necessary to run "
4840 print warn_prefix + good("`emerge --update --newuse --deep world`") + " prior to depclean."
4842 xterm_titles = "notitles" not in settings.features
4843 myroot = settings["ROOT"]
4844 dep_check_trees = {}
4845 dep_check_trees[myroot] = {}
4846 dep_check_trees[myroot]["vartree"] = \
4847 FakeVartree(trees[myroot]["vartree"], trees[myroot]["porttree"].dbapi)
4848 vardb = dep_check_trees[myroot]["vartree"].dbapi
4849 # Constrain dependency selection to the installed packages.
4850 dep_check_trees[myroot]["porttree"] = dep_check_trees[myroot]["vartree"]
4851 syslist = getlist(settings, "system")
4852 worldlist = getlist(settings, "world")
4853 system_world_dict = genericdict(worldlist)
4854 system_world_dict.update(genericdict(syslist))
4855 fakedb = portage.fakedbapi(settings=settings)
4856 myvarlist = vardb.cpv_all()
4859 print "\n!!! You have no system list.",
4861 print "\n!!! You have no world file.",
4863 print "\n!!! You have no installed package database (%s)." % portage.VDB_PATH,
4865 if not (syslist and worldlist and myvarlist):
4866 print "\n!!! Proceeding "+(syslist and myvarlist and "may" or "will")
4867 print " break your installation.\n"
4868 if "--pretend" not in myopts:
4869 countdown(int(settings["EMERGE_WARNING_DELAY"]), ">>> Depclean")
4871 if not "--pretend" in myopts: #just check pretend, since --ask implies pretend
4872 emergelog(xterm_titles, " >>> depclean")
4874 if "--quiet" not in myopts:
4875 print "\nCalculating dependencies ",
4879 remaining_atoms = [(atom, 'world', hard) for atom in worldlist if vardb.match(atom)]
4880 remaining_atoms += [(atom, 'system', hard) for atom in syslist if vardb.match(atom)]
4882 aux_keys = ["DEPEND", "RDEPEND", "PDEPEND"]
4884 while remaining_atoms:
4885 atom, parent, priority = remaining_atoms.pop()
4886 pkgs = vardb.match(atom)
4888 if not atom.startswith("!") and priority == hard:
4889 unresolveable.setdefault(atom, []).append(parent)
4891 if portage.dep_getkey(atom) not in system_world_dict:
4892 # Prune all but the best matching slot, since that's all that a
4893 # deep world update would pull in. Don't prune if the cpv is in
4894 # system or world though, since those sets trigger greedy update
4896 pkgs = [portage.best(pkgs)]
4898 if fakedb.cpv_exists(pkg):
4901 fakedb.cpv_inject(pkg)
4902 myaux = dict(izip(aux_keys, vardb.aux_get(pkg, aux_keys)))
4904 if myopts.get("--with-bdeps", "y") == "y":
4905 mydeps.append((myaux["DEPEND"], soft))
4907 mydeps.append((" ".join(myaux.values()), hard))
4908 usedef = vardb.aux_get(pkg, ["USE"])[0].split()
4909 for depstr, priority in mydeps:
4914 if "--debug" in myopts:
4916 print "Parent: ", pkg
4917 print "Depstring:", depstr
4919 if priority == soft:
4925 portage.dep._dep_check_strict = False
4926 success, atoms = portage.dep_check(depstr, None, settings,
4927 myuse=usedef, trees=dep_check_trees, myroot=myroot)
4929 portage.dep._dep_check_strict = True
4931 show_invalid_depstring_notice(
4932 ("installed", myroot, pkg, "nomerge"),
4936 if "--debug" in myopts:
4937 print "Candidates:", atoms
4940 remaining_atoms.append((atom, pkg, priority))
4942 if "--quiet" not in myopts:
4943 print "\b\b... done!\n"
4946 print "Dependencies could not be completely resolved due to"
4947 print "the following required packages not being installed:"
4949 for atom in unresolveable:
4950 print atom, "required by", " ".join(unresolveable[atom])
4952 print "Have you forgotten to run " + good("`emerge --update --newuse --deep world`") + " prior to"
4953 print "depclean? It may be necessary to manually uninstall packages that no longer"
4954 print "exist in the portage tree since it may not be possible to satisfy their"
4955 print "dependencies. Also, be aware of the --with-bdeps option that is documented"
4956 print "in " + good("`man emerge`") + "."
4960 cleanlist = [pkg for pkg in vardb.cpv_all() if not fakedb.cpv_exists(pkg)]
4963 unmerge(settings, myopts, trees[settings["ROOT"]]["vartree"],
4964 "unmerge", cleanlist, ldpath_mtimes)
4966 print "Packages installed: "+str(len(myvarlist))
4967 print "Packages in world: "+str(len(worldlist))
4968 print "Packages in system: "+str(len(syslist))
4969 print "Unique package names: "+str(len(myvarlist))
4970 print "Required packages: "+str(len(fakedb.cpv_all()))
4971 if "--pretend" in myopts:
4972 print "Number to remove: "+str(len(cleanlist))
4974 print "Number removed: "+str(len(cleanlist))
4976 def action_build(settings, trees, mtimedb,
4977 myopts, myaction, myfiles, spinner):
4978 ldpath_mtimes = mtimedb["ldpath"]
4980 if "--quiet" not in myopts and \
4981 ("--pretend" in myopts or "--ask" in myopts or \
4982 "--tree" in myopts or "--verbose" in myopts):
4984 if "--fetchonly" in myopts or "--fetch-all-uri" in myopts:
4988 if "--tree" in myopts and action != "fetched": # Tree doesn't work with fetching
4990 print darkgreen("These are the packages that would be %s, in reverse order:") % action
4994 print darkgreen("These are the packages that would be %s, in order:") % action
4997 # validate the state of the resume data
4998 # so that we can make assumptions later.
4999 for k in ("resume", "resume_backup"):
5001 if "mergelist" in mtimedb[k]:
5002 if not mtimedb[k]["mergelist"]:
5007 if "--resume" in myopts and \
5008 ("resume" in mtimedb or
5009 "resume_backup" in mtimedb):
5010 if "resume" not in mtimedb:
5011 mtimedb["resume"] = mtimedb["resume_backup"]
5012 del mtimedb["resume_backup"]
5014 # XXX: "myopts" is a list for backward compatibility.
5015 myresumeopts = dict([(k,True) for k in mtimedb["resume"]["myopts"]])
5017 for opt in ("--skipfirst", "--ask", "--tree"):
5018 myresumeopts.pop(opt, None)
5020 for myopt, myarg in myopts.iteritems():
5021 if myopt not in myresumeopts:
5022 myresumeopts[myopt] = myarg
5025 # Adjust config according to options of the command being resumed.
5026 for myroot in trees:
5027 mysettings = trees[myroot]["vartree"].settings
5029 adjust_config(myopts, mysettings)
5031 del myroot, mysettings
5033 myparams = create_depgraph_params(myopts, myaction)
5034 if "--quiet" not in myopts and "--nodeps" not in myopts:
5035 print "Calculating dependencies ",
5036 mydepgraph = depgraph(settings, trees,
5037 myopts, myparams, spinner)
5038 if "--quiet" not in myopts and "--nodeps" not in myopts:
5039 print "\b\b... done!"
5041 if ("--resume" in myopts):
5042 print darkgreen("emerge: It seems we have nothing to resume...")
5045 myparams = create_depgraph_params(myopts, myaction)
5046 if myaction in ["system","world"]:
5047 if "--quiet" not in myopts and "--nodeps" not in myopts:
5048 print "Calculating",myaction,"dependencies ",
5050 mydepgraph = depgraph(settings, trees, myopts, myparams, spinner)
5051 if not mydepgraph.xcreate(myaction):
5052 print "!!! Depgraph creation failed."
5054 if "--quiet" not in myopts and "--nodeps" not in myopts:
5055 print "\b\b... done!"
5057 if "--quiet" not in myopts and "--nodeps" not in myopts:
5058 print "Calculating dependencies ",
5060 mydepgraph = depgraph(settings, trees, myopts, myparams, spinner)
5062 retval, favorites = mydepgraph.select_files(myfiles)
5063 except portage.exception.PackageNotFound, e:
5064 portage.writemsg("\n!!! %s\n" % str(e), noiselevel=-1)
5068 if "--quiet" not in myopts and "--nodeps" not in myopts:
5069 print "\b\b... done!"
5071 if ("--usepkgonly" in myopts) and mydepgraph.missingbins:
5072 sys.stderr.write(red("The following binaries are not available for merging...\n"))
5074 if mydepgraph.missingbins:
5075 for x in mydepgraph.missingbins:
5076 sys.stderr.write(" "+str(x)+"\n")
5077 sys.stderr.write("\nThese are required by '--usepkgonly' -- Terminating.\n\n")
5080 if "--pretend" not in myopts and \
5081 ("--ask" in myopts or "--tree" in myopts or \
5082 "--verbose" in myopts) and \
5083 not ("--quiet" in myopts and "--ask" not in myopts):
5084 if "--resume" in myopts:
5085 validate_merge_list(trees, mtimedb["resume"]["mergelist"])
5086 mymergelist = mtimedb["resume"]["mergelist"]
5087 if "--skipfirst" in myopts:
5088 mymergelist = mymergelist[1:]
5089 if len(mymergelist) == 0:
5090 print colorize("INFORM", "emerge: It seems we have nothing to resume...")
5092 mydepgraph.display(mymergelist)
5093 prompt="Would you like to resume merging these packages?"
5096 mydepgraph.altlist(reversed=("--tree" in myopts)))
5098 for x in mydepgraph.altlist():
5099 if x[0] != "blocks" and x[3] != "nomerge":
5101 #check for blocking dependencies
5102 if x[0]=="blocks" and "--fetchonly" not in myopts and "--fetch-all-uri" not in myopts:
5103 print "\n!!! Error: The above package list contains packages which cannot be installed"
5104 print "!!! at the same time on the same system."
5105 if "--quiet" not in myopts:
5106 show_blocker_docs_link()
5109 if "--noreplace" in myopts and favorites:
5112 print " %s %s" % (good("*"), x)
5113 prompt="Would you like to add these packages to your world favorites?"
5114 elif settings["AUTOCLEAN"] and "yes"==settings["AUTOCLEAN"]:
5115 prompt="Nothing to merge; would you like to auto-clean packages?"
5118 print "Nothing to merge; quitting."
5121 elif "--fetchonly" in myopts or "--fetch-all-uri" in myopts:
5122 prompt="Would you like to fetch the source files for these packages?"
5124 prompt="Would you like to merge these packages?"
5126 if "--ask" in myopts and userquery(prompt) == "No":
5131 # Don't ask again (e.g. when auto-cleaning packages after merge)
5132 myopts.pop("--ask", None)
5134 if ("--pretend" in myopts) and not ("--fetchonly" in myopts or "--fetch-all-uri" in myopts):
5135 if ("--resume" in myopts):
5136 validate_merge_list(trees, mtimedb["resume"]["mergelist"])
5137 mymergelist = mtimedb["resume"]["mergelist"]
5138 if "--skipfirst" in myopts:
5139 mymergelist = mymergelist[1:]
5140 if len(mymergelist) == 0:
5141 print colorize("INFORM", "emerge: It seems we have nothing to resume...")
5143 mydepgraph.display(mymergelist)
5146 mydepgraph.altlist(reversed=("--tree" in myopts)))
5147 if "--buildpkgonly" in myopts and \
5148 not mydepgraph.digraph.hasallzeros(ignore_priority=DepPriority.MEDIUM):
5149 print "\n!!! --buildpkgonly requires all dependencies to be merged."
5150 print "!!! You have to merge the dependencies before you can build this package.\n"
5153 if ("--buildpkgonly" in myopts):
5154 if not mydepgraph.digraph.hasallzeros(ignore_priority=DepPriority.MEDIUM):
5155 print "\n!!! --buildpkgonly requires all dependencies to be merged."
5156 print "!!! Cannot merge requested packages. Merge deps and try again.\n"
5159 if ("--resume" in myopts):
5160 favorites=mtimedb["resume"]["favorites"]
5161 mergetask = MergeTask(settings, trees, myopts)
5162 if "--fetchonly" in myopts:
5163 """ parallel-fetch uses --resume --fetchonly and we don't want
5164 it to write the mtimedb"""
5165 mtimedb.filename = None
5166 time.sleep(3) # allow the parent to have first fetch
5168 retval = mergetask.merge(
5169 mtimedb["resume"]["mergelist"], favorites, mtimedb)
5170 if retval != os.EX_OK:
5173 if "resume" in mtimedb and \
5174 "mergelist" in mtimedb["resume"] and \
5175 len(mtimedb["resume"]["mergelist"]) > 1:
5176 mtimedb["resume_backup"] = mtimedb["resume"]
5177 del mtimedb["resume"]
5179 mtimedb["resume"]={}
5180 # XXX: Stored as a list for backward compatibility.
5181 mtimedb["resume"]["myopts"] = \
5182 [k for k in myopts if myopts[k] is True]
5183 mtimedb["resume"]["favorites"]=favorites
5184 if ("--digest" in myopts) and not ("--fetchonly" in myopts or "--fetch-all-uri" in myopts):
5185 for pkgline in mydepgraph.altlist():
5186 if pkgline[0]=="ebuild" and pkgline[3]=="merge":
5187 y = trees[pkgline[1]]["porttree"].dbapi.findname(pkgline[2])
5188 tmpsettings = portage.config(clone=settings)
5190 if settings.get("PORTAGE_DEBUG", "") == "1":
5192 retval = portage.doebuild(
5193 y, "digest", settings["ROOT"], tmpsettings, edebug,
5194 ("--pretend" in myopts),
5195 mydbapi=trees[pkgline[1]]["porttree"].dbapi,
5197 if "--fetchonly" in myopts or "--fetch-all-uri" in myopts:
5199 for pkg in mydepgraph.altlist():
5200 if pkg[0] != "blocks":
5203 pkglist = mydepgraph.altlist()
5205 mergetask = MergeTask(settings, trees, myopts)
5206 retval = mergetask.merge(pkglist, favorites, mtimedb)
5207 if retval != os.EX_OK:
5210 if mtimedb.has_key("resume"):
5211 del mtimedb["resume"]
5212 if settings["AUTOCLEAN"] and "yes"==settings["AUTOCLEAN"]:
5213 portage.writemsg_stdout(">>> Auto-cleaning packages...\n")
5214 vartree = trees[settings["ROOT"]]["vartree"]
5215 unmerge(settings, myopts, vartree, "clean", ["world"],
5216 ldpath_mtimes, autoclean=1)
5218 portage.writemsg_stdout(colorize("WARN", "WARNING:")
5219 + " AUTOCLEAN is disabled. This can cause serious"
5220 + " problems due to overlapping packages.\n")
5222 def multiple_actions(action1, action2):
5223 sys.stderr.write("\n!!! Multiple actions requested... Please choose one only.\n")
5224 sys.stderr.write("!!! '%s' or '%s'\n\n" % (action1, action2))
5227 def parse_opts(tmpcmdline, silent=False):
5232 global actions, options, shortmapping
5234 longopt_aliases = {"--cols":"--columns", "--skip-first":"--skipfirst"}
5235 argument_options = {
5237 "help":"specify the location for portage configuration files",
5241 "help":"enable or disable color output",
5243 "choices":("y", "n")
5246 "help":"include unnecessary build time dependencies",
5248 "choices":("y", "n")
5252 from optparse import OptionParser
5253 parser = OptionParser()
5254 if parser.has_option("--help"):
5255 parser.remove_option("--help")
5257 for action_opt in actions:
5258 parser.add_option("--" + action_opt, action="store_true",
5259 dest=action_opt.replace("-", "_"), default=False)
5260 for myopt in options:
5261 parser.add_option(myopt, action="store_true",
5262 dest=myopt.lstrip("--").replace("-", "_"), default=False)
5263 for shortopt, longopt in shortmapping.iteritems():
5264 parser.add_option("-" + shortopt, action="store_true",
5265 dest=longopt.lstrip("--").replace("-", "_"), default=False)
5266 for myalias, myopt in longopt_aliases.iteritems():
5267 parser.add_option(myalias, action="store_true",
5268 dest=myopt.lstrip("--").replace("-", "_"), default=False)
5270 for myopt, kwargs in argument_options.iteritems():
5271 parser.add_option(myopt,
5272 dest=myopt.lstrip("--").replace("-", "_"), **kwargs)
5274 myoptions, myargs = parser.parse_args(args=tmpcmdline)
5276 for myopt in options:
5277 v = getattr(myoptions, myopt.lstrip("--").replace("-", "_"))
5279 myopts[myopt] = True
5281 for myopt in argument_options:
5282 v = getattr(myoptions, myopt.lstrip("--").replace("-", "_"), None)
5286 for action_opt in actions:
5287 v = getattr(myoptions, action_opt.replace("-", "_"))
5290 multiple_actions(myaction, action_opt)
5292 myaction = action_opt
5295 if x in actions and myaction != "search":
5296 if not silent and x not in ["system", "world"]:
5297 print red("*** Deprecated use of action '%s', use '--%s' instead" % (x,x))
5298 # special case "search" so people can search for action terms, e.g. emerge -s sync
5300 multiple_actions(myaction, x)
5306 if "--nocolor" in myopts:
5308 sys.stderr.write("*** Deprecated use of '--nocolor', " + \
5309 "use '--color=n' instead.\n")
5310 del myopts["--nocolor"]
5311 myopts["--color"] = "n"
5313 return myaction, myopts, myfiles
5315 def validate_ebuild_environment(trees):
5316 for myroot in trees:
5317 mysettings = trees[myroot]["vartree"].settings
5318 for var in "ARCH", "USERLAND":
5319 if mysettings.get(var):
5321 print >> sys.stderr, bad(("\a!!! %s is not set... " % var) + \
5322 "Are you missing the '%setc/make.profile' symlink?" % \
5323 mysettings["PORTAGE_CONFIGROOT"])
5324 print >> sys.stderr, bad("\a!!! Is the symlink correct? " + \
5325 "Is your portage tree complete?\n")
5327 del myroot, mysettings
5329 def load_emerge_config(trees=None):
5331 for k, envvar in (("config_root", "PORTAGE_CONFIGROOT"), ("target_root", "ROOT")):
5332 kwargs[k] = os.environ.get(envvar, None)
5333 trees = portage.create_trees(trees=trees, **kwargs)
5335 settings = trees["/"]["vartree"].settings
5337 for myroot in trees:
5339 settings = trees[myroot]["vartree"].settings
5342 mtimedbfile = os.path.join("/", portage.CACHE_PATH.lstrip(os.path.sep), "mtimedb")
5343 mtimedb = portage.MtimeDB(mtimedbfile)
5344 return settings, trees, mtimedb
5346 def adjust_config(myopts, settings):
5347 """Make emerge specific adjustments to the config."""
5349 # To enhance usability, make some vars case insensitive by forcing them to
5351 for myvar in ("AUTOCLEAN", "NOCOLOR"):
5352 if myvar in settings:
5353 settings[myvar] = settings[myvar].lower()
5354 settings.backup_changes(myvar)
5357 # Kill noauto as it will break merges otherwise.
5358 if "noauto" in settings.features:
5359 while "noauto" in settings.features:
5360 settings.features.remove("noauto")
5361 settings["FEATURES"] = " ".join(settings.features)
5362 settings.backup_changes("FEATURES")
5366 CLEAN_DELAY = int(settings.get("CLEAN_DELAY", str(CLEAN_DELAY)))
5367 except ValueError, e:
5368 portage.writemsg("!!! %s\n" % str(e), noiselevel=-1)
5369 portage.writemsg("!!! Unable to parse integer: CLEAN_DELAY='%s'\n" % \
5370 settings["CLEAN_DELAY"], noiselevel=-1)
5371 settings["CLEAN_DELAY"] = str(CLEAN_DELAY)
5372 settings.backup_changes("CLEAN_DELAY")
5374 EMERGE_WARNING_DELAY = 10
5376 EMERGE_WARNING_DELAY = int(settings.get(
5377 "EMERGE_WARNING_DELAY", str(EMERGE_WARNING_DELAY)))
5378 except ValueError, e:
5379 portage.writemsg("!!! %s\n" % str(e), noiselevel=-1)
5380 portage.writemsg("!!! Unable to parse integer: EMERGE_WARNING_DELAY='%s'\n" % \
5381 settings["EMERGE_WARNING_DELAY"], noiselevel=-1)
5382 settings["EMERGE_WARNING_DELAY"] = str(EMERGE_WARNING_DELAY)
5383 settings.backup_changes("EMERGE_WARNING_DELAY")
5385 if "--quiet" in myopts:
5386 settings["PORTAGE_QUIET"]="1"
5387 settings.backup_changes("PORTAGE_QUIET")
5389 # Set so that configs will be merged regardless of remembered status
5390 if ("--noconfmem" in myopts):
5391 settings["NOCONFMEM"]="1"
5392 settings.backup_changes("NOCONFMEM")
5394 # Set various debug markers... They should be merged somehow.
5397 PORTAGE_DEBUG = int(settings.get("PORTAGE_DEBUG", str(PORTAGE_DEBUG)))
5398 if PORTAGE_DEBUG not in (0, 1):
5399 portage.writemsg("!!! Invalid value: PORTAGE_DEBUG='%i'\n" % \
5400 PORTAGE_DEBUG, noiselevel=-1)
5401 portage.writemsg("!!! PORTAGE_DEBUG must be either 0 or 1\n",
5404 except ValueError, e:
5405 portage.writemsg("!!! %s\n" % str(e), noiselevel=-1)
5406 portage.writemsg("!!! Unable to parse integer: PORTAGE_DEBUG='%s'\n" %\
5407 settings["PORTAGE_DEBUG"], noiselevel=-1)
5409 if "--debug" in myopts:
5411 settings["PORTAGE_DEBUG"] = str(PORTAGE_DEBUG)
5412 settings.backup_changes("PORTAGE_DEBUG")
5414 if settings.get("NOCOLOR") not in ("yes","true"):
5415 portage.output.havecolor = 1
5417 """The explicit --color < y | n > option overrides the NOCOLOR environment
5418 variable and stdout auto-detection."""
5419 if "--color" in myopts:
5420 if "y" == myopts["--color"]:
5421 portage.output.havecolor = 1
5422 settings["NOCOLOR"] = "false"
5424 portage.output.havecolor = 0
5425 settings["NOCOLOR"] = "true"
5426 settings.backup_changes("NOCOLOR")
5427 elif not sys.stdout.isatty() and settings.get("NOCOLOR") != "no":
5428 portage.output.havecolor = 0
5429 settings["NOCOLOR"] = "true"
5430 settings.backup_changes("NOCOLOR")
5433 global portage # NFC why this is necessary now - genone
5434 # Disable color until we're sure that it should be enabled (after
5435 # EMERGE_DEFAULT_OPTS has been parsed).
5436 portage.output.havecolor = 0
5437 # This first pass is just for options that need to be known as early as
5438 # possible, such as --config-root. They will be parsed again later,
5439 # together with EMERGE_DEFAULT_OPTS (which may vary depending on the
5440 # the value of --config-root).
5441 myaction, myopts, myfiles = parse_opts(sys.argv[1:], silent=True)
5442 if "--debug" in myopts:
5443 os.environ["PORTAGE_DEBUG"] = "1"
5444 if "--config-root" in myopts:
5445 os.environ["PORTAGE_CONFIGROOT"] = myopts["--config-root"]
5447 # Portage needs to ensure a sane umask for the files it creates.
5449 settings, trees, mtimedb = load_emerge_config()
5450 portdb = trees[settings["ROOT"]]["porttree"].dbapi
5453 os.nice(int(settings.get("PORTAGE_NICENESS", "0")))
5454 except (OSError, ValueError), e:
5455 portage.writemsg("!!! Failed to change nice value to '%s'\n" % \
5456 settings["PORTAGE_NICENESS"])
5457 portage.writemsg("!!! %s\n" % str(e))
5460 if portage._global_updates(trees, mtimedb["updates"]):
5462 # Reload the whole config from scratch.
5463 settings, trees, mtimedb = load_emerge_config(trees=trees)
5464 portdb = trees[settings["ROOT"]]["porttree"].dbapi
5466 xterm_titles = "notitles" not in settings.features
5469 if "--ignore-default-opts" not in myopts:
5470 tmpcmdline.extend(settings["EMERGE_DEFAULT_OPTS"].split())
5471 tmpcmdline.extend(sys.argv[1:])
5472 myaction, myopts, myfiles = parse_opts(tmpcmdline)
5474 if "--digest" in myopts:
5475 os.environ["FEATURES"] = os.environ.get("FEATURES","") + " digest"
5476 # Reload the whole config from scratch so that the portdbapi internal
5477 # config is updated with new FEATURES.
5478 settings, trees, mtimedb = load_emerge_config(trees=trees)
5479 portdb = trees[settings["ROOT"]]["porttree"].dbapi
5481 for myroot in trees:
5482 mysettings = trees[myroot]["vartree"].settings
5484 adjust_config(myopts, mysettings)
5486 del myroot, mysettings
5488 spinner = stdout_spinner()
5489 if "candy" in settings.features:
5490 spinner.update = spinner.update_scroll
5492 if "--quiet" not in myopts:
5493 portage.deprecated_profile_check()
5495 #Freeze the portdbapi for enhanced performance:
5496 for myroot in trees:
5497 trees[myroot]["porttree"].dbapi.freeze()
5500 if "moo" in myfiles:
5503 Larry loves Gentoo (""" + os.uname()[0] + """)
5505 _______________________
5506 < Have you mooed today? >
5507 -----------------------
5516 if (myaction in ["world", "system"]) and myfiles:
5517 print "emerge: please specify a package class (\"world\" or \"system\") or individual packages, but not both."
5521 ext = os.path.splitext(x)[1]
5522 if (ext == ".ebuild" or ext == ".tbz2") and os.path.exists(os.path.abspath(x)):
5523 print "emerging by path implies --oneshot... adding --oneshot to options."
5524 print colorize("BAD", "\n*** emerging by path is broken and may not always work!!!\n")
5527 if ("--tree" in myopts) and ("--columns" in myopts):
5528 print "emerge: can't specify both of \"--tree\" and \"--columns\"."
5531 if ("--quiet" in myopts):
5532 spinner.update = spinner.update_quiet
5533 portage.util.noiselimit = -1
5535 # Always create packages if FEATURES=buildpkg
5536 # Imply --buildpkg if --buildpkgonly
5537 if ("buildpkg" in settings.features) or ("--buildpkgonly" in myopts):
5538 if "--buildpkg" not in myopts:
5539 myopts["--buildpkg"] = True
5541 # Also allow -S to invoke search action (-sS)
5542 if ("--searchdesc" in myopts):
5543 if myaction and myaction != "search":
5544 myfiles.append(myaction)
5545 if "--search" not in myopts:
5546 myopts["--search"] = True
5549 # Always try and fetch binary packages if FEATURES=getbinpkg
5550 if ("getbinpkg" in settings.features):
5551 myopts["--getbinpkg"] = True
5553 if "--skipfirst" in myopts and "--resume" not in myopts:
5554 myopts["--resume"] = True
5556 if ("--getbinpkgonly" in myopts) and not ("--usepkgonly" in myopts):
5557 myopts["--usepkgonly"] = True
5559 if ("--getbinpkgonly" in myopts) and not ("--getbinpkg" in myopts):
5560 myopts["--getbinpkg"] = True
5562 if ("--getbinpkg" in myopts) and not ("--usepkg" in myopts):
5563 myopts["--usepkg"] = True
5565 # Also allow -K to apply --usepkg/-k
5566 if ("--usepkgonly" in myopts) and not ("--usepkg" in myopts):
5567 myopts["--usepkg"] = True
5569 # Allow -p to remove --ask
5570 if ("--pretend" in myopts) and ("--ask" in myopts):
5571 print ">>> --pretend disables --ask... removing --ask from options."
5574 # forbid --ask when not in a terminal
5575 # note: this breaks `emerge --ask | tee logfile`, but that doesn't work anyway.
5576 if ("--ask" in myopts) and (not sys.stdin.isatty()):
5577 portage.writemsg("!!! \"--ask\" should only be used in a terminal. Exiting.\n",
5581 if settings.get("PORTAGE_DEBUG", "") == "1":
5582 spinner.update = spinner.update_quiet
5584 if "python-trace" in settings.features:
5585 import portage.debug
5586 portage.debug.set_trace(True)
5588 if ("--resume" in myopts):
5589 if "--tree" in myopts:
5590 print "* --tree is currently broken with --resume. Disabling..."
5591 del myopts["--tree"]
5593 if not ("--quiet" in myopts):
5594 if not sys.stdout.isatty() or ("--nospinner" in myopts):
5595 spinner.update = spinner.update_basic
5597 if "--version" in myopts:
5598 print getportageversion(settings["PORTDIR"], settings["ROOT"],
5599 settings.profile_path, settings["CHOST"],
5600 trees[settings["ROOT"]]["vartree"].dbapi)
5602 elif "--help" in myopts:
5603 emerge.help.help(myaction, myopts, portage.output.havecolor)
5606 if portage.wheelgid == portage.portage_gid:
5607 print "emerge: wheel group use is being deprecated. Please update group and passwd to"
5608 print " include the portage user as noted above, and then use group portage."
5610 if "--debug" in myopts:
5611 print "myaction", myaction
5612 print "myopts", myopts
5614 if not myaction and not myfiles and "--resume" not in myopts:
5615 emerge.help.help(myaction, myopts, portage.output.havecolor)
5618 # check if root user is the current user for the actions where emerge needs this
5619 if portage.secpass < 2:
5620 # We've already allowed "--version" and "--help" above.
5621 if "--pretend" not in myopts and \
5622 myaction not in ("search","info"):
5623 need_superuser = not \
5624 ("--fetchonly" in myopts or \
5625 "--fetch-all-uri" in myopts or \
5626 myaction in ("metadata", "regen"))
5627 if portage.secpass < 1 or \
5630 access_desc = "superuser"
5632 access_desc = "portage group"
5633 # Always show portage_group_warning() when only portage group
5634 # access is required but the user is not in the portage group.
5635 from portage.data import portage_group_warning
5636 if "--ask" in myopts:
5637 myopts["--pretend"] = True
5639 print ("%s access is required... " + \
5640 "adding --pretend to options.\n") % access_desc
5641 if portage.secpass < 1 and not need_superuser:
5642 portage_group_warning()
5644 sys.stderr.write(("emerge: %s access is " + \
5645 "required.\n\n") % access_desc)
5646 if portage.secpass < 1 and not need_superuser:
5647 portage_group_warning()
5650 disable_emergelog = False
5651 for x in ("--pretend", "--fetchonly", "--fetch-all-uri"):
5653 disable_emergelog = True
5655 if myaction in ("search", "info"):
5656 disable_emergelog = True
5657 if disable_emergelog:
5658 """ Disable emergelog for everything except build or unmerge
5659 operations. This helps minimize parallel emerge.log entries that can
5660 confuse log parsers. We especially want it disabled during
5661 parallel-fetch, which uses --resume --fetchonly."""
5663 def emergelog(*pargs, **kargs):
5666 if not "--pretend" in myopts:
5667 emergelog(xterm_titles, "Started emerge on: "+\
5668 time.strftime("%b %d, %Y %H:%M:%S", time.localtime()))
5671 myelogstr=" ".join(myopts)
5673 myelogstr+=" "+myaction
5675 myelogstr+=" "+" ".join(myfiles)
5676 emergelog(xterm_titles, " *** emerge " + myelogstr)
5678 def emergeexitsig(signum, frame):
5679 signal.signal(signal.SIGINT, signal.SIG_IGN)
5680 signal.signal(signal.SIGTERM, signal.SIG_IGN)
5681 portage.util.writemsg("\n\nExiting on signal %(signal)s\n" % {"signal":signum})
5682 sys.exit(100+signum)
5683 signal.signal(signal.SIGINT, emergeexitsig)
5684 signal.signal(signal.SIGTERM, emergeexitsig)
5687 """This gets out final log message in before we quit."""
5688 if "--pretend" not in myopts:
5689 emergelog(xterm_titles, " *** terminating.")
5690 if "notitles" not in settings.features:
5692 portage.atexit_register(emergeexit)
5694 if myaction in ("config", "metadata", "regen", "sync"):
5695 if "--pretend" in myopts:
5696 sys.stderr.write(("emerge: The '%s' action does " + \
5697 "not support '--pretend'.\n") % myaction)
5699 if "sync" == myaction:
5700 action_sync(settings, trees, mtimedb, myopts, myaction)
5701 elif "metadata" == myaction:
5702 action_metadata(settings, portdb, myopts)
5703 elif myaction=="regen":
5704 validate_ebuild_environment(trees)
5705 action_regen(settings, portdb)
5707 elif "config"==myaction:
5708 validate_ebuild_environment(trees)
5709 action_config(settings, trees, myopts, myfiles)
5712 elif "info"==myaction:
5713 action_info(settings, trees, myopts, myfiles)
5716 elif "search"==myaction:
5717 validate_ebuild_environment(trees)
5718 action_search(settings, portdb, trees["/"]["vartree"],
5719 myopts, myfiles, spinner)
5720 elif "unmerge"==myaction or "prune"==myaction or "clean"==myaction:
5721 validate_ebuild_environment(trees)
5722 vartree = trees[settings["ROOT"]]["vartree"]
5723 if 1 == unmerge(settings, myopts, vartree, myaction, myfiles,
5725 if "--pretend" not in myopts:
5726 post_emerge(trees, mtimedb, os.EX_OK)
5728 elif "depclean"==myaction:
5729 validate_ebuild_environment(trees)
5730 action_depclean(settings, trees, mtimedb["ldpath"],
5732 if "--pretend" not in myopts:
5733 post_emerge(trees, mtimedb, os.EX_OK)
5734 # "update", "system", or just process files:
5736 validate_ebuild_environment(trees)
5737 if "--pretend" not in myopts:
5738 display_news_notification(trees)
5739 action_build(settings, trees, mtimedb,
5740 myopts, myaction, myfiles, spinner)
5741 if "--pretend" not in myopts:
5742 post_emerge(trees, mtimedb, os.EX_OK)
5744 display_news_notification(trees)
5746 if __name__ == "__main__":
5747 retval = emerge_main()