示例#1
0
def autoresolve(args):
    success, depgraph = False, None
    while not success:
        action, opts, files = parse_opts(args, silent=True)
        config = load_emerge_config(action=action, args=files, opts=opts)
        print(("Targets: %s\nOptions: %s\nCalculating dependency  "
               % (files, opts)), end="")
        # print("Calculating dependency  ", end="")
        success, depgraph, _ = calcdep(config)
        print()
        if success:
            break
        newpkgs = []
        depgraph.display_problems()
        newpkgs += fix_conflict(depgraph)
        added = False
        reinstalls = opts.get("--reinstall-atoms", [])
        oneshot = opts.get("--oneshot", False)
        for pkg in newpkgs:
            if pkg not in files and pkg not in reinstalls:
                # print("Adding %s" % opt)
                if oneshot:
                    args.append(pkg)
                else:
                    args.append("--reinstall-atoms=" + pkg)
                added = True
        if not added:
            return False, depgraph, args
    return True, depgraph, args
示例#2
0
	def fix(self, **kwargs):
		"""Attempt to fix any failed merges."""
		module_output = kwargs.get('module_output', None)
		failed_pkgs = self._failed_pkgs()
		if not failed_pkgs:
			return ['No failed merges found.']

		pkg_invalid_entries = set()
		pkg_atoms = set()
		self._get_pkg_atoms(failed_pkgs, pkg_atoms, pkg_invalid_entries)
		if pkg_invalid_entries:
			return pkg_invalid_entries

		try:
			self._tracking_file.save(failed_pkgs)
		except IOError as ex:
			errors = ['Unable to save failed merges to tracking file: %s\n'
				% str(ex)]
			errors.append(', '.join(sorted(failed_pkgs)))
			return errors
		self._remove_failed_dirs(failed_pkgs)
		results = self._emerge_pkg_atoms(module_output, pkg_atoms)
		# list any new failed merges
		for pkg in sorted(self._scan()):
			results.append("'%s' still found as a failed merge." % pkg)
		# reload config and remove successful packages from tracking file
		emerge_config = load_emerge_config()
		vardb = emerge_config.target_config.trees['vartree'].dbapi
		still_failed_pkgs = {}
		for pkg, mtime in failed_pkgs.items():
			pkg_name = '%s' % pkg.replace(MERGING_IDENTIFIER, '')
			if not vardb.cpv_exists(pkg_name):
				still_failed_pkgs[pkg] = mtime
		self._tracking_file.save(still_failed_pkgs)
		return results
示例#3
0
    def _get_pkg_atoms(self, failed_pkgs, pkg_atoms, pkg_invalid_entries):
        """
		Get the package atoms for the specified failed packages.

		@param failed_pkgs: failed packages to iterate
		@type failed_pkgs: dict
		@param pkg_atoms: append package atoms to this set
		@type pkg_atoms: set
		@param pkg_invalid_entries: append any packages that are invalid to this set
		@type pkg_invalid_entries: set
		"""

        emerge_config = load_emerge_config()
        portdb = emerge_config.target_config.trees['porttree'].dbapi
        for failed_pkg in failed_pkgs:
            # validate pkg name
            pkg_name = '%s' % failed_pkg.replace(MERGING_IDENTIFIER, '')
            pkg_atom = '=%s' % pkg_name

            if not isvalidatom(pkg_atom):
                pkg_invalid_entries.append("'%s' is an invalid package atom." %
                                           pkg_atom)
            if not portdb.cpv_exists(pkg_name):
                pkg_invalid_entries.append(
                    "'%s' does not exist in the portage tree." % pkg_name)
            pkg_atoms.add(pkg_atom)
示例#4
0
	def _get_pkg_atoms(self, failed_pkgs, pkg_atoms, pkg_invalid_entries):
		"""
		Get the package atoms for the specified failed packages.

		@param failed_pkgs: failed packages to iterate
		@type failed_pkgs: dict
		@param pkg_atoms: add package atoms to this set
		@type pkg_atoms: set
		@param pkg_invalid_entries: add any packages that are invalid to this set
		@type pkg_invalid_entries: set
		"""

		emerge_config = load_emerge_config()
		portdb = emerge_config.target_config.trees['porttree'].dbapi
		for failed_pkg in failed_pkgs:
			# validate pkg name
			pkg_name = '%s' % failed_pkg.replace(MERGING_IDENTIFIER, '')
			pkg_atom = '=%s' % pkg_name

			if not isvalidatom(pkg_atom):
				pkg_invalid_entries.add("'%s' is an invalid package atom."
					% pkg_atom)
			if not portdb.cpv_exists(pkg_name):
				pkg_invalid_entries.add(
					"'%s' does not exist in the portage tree." % pkg_name)
			pkg_atoms.add(pkg_atom)
示例#5
0
    def update_news(self, repos=None):
        try:
            if self.config['news_reporter'] == 'portage':
                try:
                    from portage import db, root
                    from portage.news import count_unread_news, \
                        display_news_notifications
                    portdb = db[root]["porttree"].dbapi
                    vardb = db[root]["vartree"].dbapi
                    # get the actual repo_name from portage
                    # because it may be different than layman's name for it
                    repo_names = []
                    for repo in repos:
                        if isinstance(repo, bytes):
                            repo = repo.decode('UTF-8')
                        ovl = self._get_installed_db().select(repo)
                        ovl_path = os.path.join(ovl.config['storage'], repo)
                        name = portdb.getRepositoryName(ovl_path)
                        if name:
                            repo_names.append(name)
                    self.output.debug(
                        "LaymanAPI: update_news(); repo_names = " +
                        str(repo_names), 4)
                    news_counts = count_unread_news(portdb, vardb, repo_names)
                    display_news_notifications(news_counts)
                except ImportError:
                    # deprecated funtionality, remove when the above method
                    # is available in all portage versions
                    self.output.info(
                        "New portage news functionality not "
                        "available, using fallback method", 5)
                    from _emerge.actions import (display_news_notification,
                                                 load_emerge_config)
                    settings, trees, mtimedb = load_emerge_config()
                    display_news_notification(
                        trees[settings["ROOT"]]["root_config"], {})

            elif self.config['news_reporter'] == 'custom':
                if self.config['custom_news_func'] is None:
                    _temp = __import__('custom_news_pkg', globals(), locals(),
                                       ['layman_news_func'], -1)
                    self.config['custom_news_func'] = _temp.custom_news_func
                self.config['custom_news_func'](repos)

            elif self.config['news_reporter'] == 'pkgcore':
                # pkgcore is not yet capable
                return
        except Exception as err:
            msg = "update_news() failed running %s news reporter function\n" +\
                  "Error was; %s"
            self._error(msg % (self.config['news_reporter'], err))
        return
示例#6
0
文件: api.py 项目: wking/layman
    def update_news(self, repos=None):
        try:
            if self.config['news_reporter'] == 'portage':
                try:
                    from portage import db, root
                    from portage.news import count_unread_news, \
                        display_news_notifications
                    portdb = db[root]["porttree"].dbapi
                    vardb = db[root]["vartree"].dbapi
                    # get the actual repo_name from portage
                    # because it may be different than layman's name for it
                    repo_names = []
                    for repo in repos:
                        if isinstance(repo, bytes):
                            repo = repo.decode('UTF-8')
                        ovl = self._get_installed_db().select(repo)
                        ovl_path = os.path.join(ovl.config['storage'], repo)
                        name = portdb.getRepositoryName(ovl_path)
                        if name:
                            repo_names.append(name)
                    self.output.debug("LaymanAPI: update_news(); repo_names = "
                        + str(repo_names), 4)
                    news_counts = count_unread_news(portdb, vardb, repo_names)
                    display_news_notifications(news_counts)
                except ImportError:
                    # deprecated funtionality, remove when the above method
                    # is available in all portage versions
                    self.output.info("New portage news functionality not "
                        "available, using fallback method", 5)
                    from _emerge.actions import (display_news_notification,
                        load_emerge_config)
                    settings, trees, mtimedb = load_emerge_config()
                    display_news_notification(
                        trees[settings["ROOT"]]["root_config"], {})

            elif self.config['news_reporter'] == 'custom':
                if self.config['custom_news_func'] is None:
                    _temp = __import__(
                        'custom_news_pkg', globals(), locals(),
                        ['layman_news_func'], -1)
                    self.config['custom_news_func'] = _temp.custom_news_func
                self.config['custom_news_func'](repos)

            elif self.config['news_reporter'] == 'pkgcore':
                # pkgcore is not yet capable
                return
        except Exception as err:
            msg = "update_news() failed running %s news reporter function\n" +\
                  "Error was; %s"
            self._error(msg % (self.config['news_reporter'], err))
        return
示例#7
0
    def _get_dbs(self):
        """
        Return a tuple containing (vardb, portdb)
        """
        emerge_config = load_emerge_config()
        emerge_settings, emerge_trees, _mtimedb = emerge_config
        settings = portage.config(clone=emerge_settings)

        portdb = emerge_trees[settings["ROOT"]]["porttree"].dbapi
        if not portdb.frozen:
            portdb.freeze()
        vardb = emerge_trees[settings["ROOT"]]["vartree"].dbapi

        return vardb, portdb
示例#8
0
    def _get_dbs(self):
        """
        Return a tuple containing (vardb, portdb)
        """
        emerge_config = load_emerge_config()
        emerge_settings, emerge_trees, _mtimedb = emerge_config
        settings = portage.config(clone=emerge_settings)

        portdb = emerge_trees[settings["ROOT"]]["porttree"].dbapi
        if not portdb.frozen:
            portdb.freeze()
        vardb = emerge_trees[settings["ROOT"]]["vartree"].dbapi

        return vardb, portdb
示例#9
0
文件: portage.py 项目: gr-sp/pybombs
 def __init__(self, logger):
     ExternPackager.__init__(self, logger)
     self.available = False
     try:
         from _emerge import search
         from _emerge import actions
         from _emerge.actions import load_emerge_config
         self.portage = __import__('portage')
         self.re = __import__('re')
         emerge_config = load_emerge_config()
         self.root_config = emerge_config.running_config
         # search init args:
         # (self,root_config,spinner,searchdesc,verbose,usepkg,usepkgconly,search_index=True)
         self.search = search.search(self.root_config,False,False,False,True,False)
         self.search._vardb.cp_all()
         self.available = True
     except ImportError :
         self.available = False
示例#10
0
 def __init__(self, logger):
     ExternPackager.__init__(self, logger)
     self.available = False
     try:
         from _emerge import search
         from _emerge import actions
         from _emerge.actions import load_emerge_config
         self.portage = __import__('portage')
         self.re = __import__('re')
         emerge_config = load_emerge_config()
         self.root_config = emerge_config.running_config
         # search init args:
         # (self,root_config,spinner,searchdesc,verbose,usepkg,usepkgconly,search_index=True)
         self.search = search.search(self.root_config,False,False,False,True,False)
         self.search._vardb.cp_all()
         self.available = True
     except ImportError :
         self.available = False
示例#11
0
    def fix(self, **kwargs):
        """Attempt to fix any failed merges."""
        module_output = kwargs.get('module_output', None)
        failed_pkgs = self._failed_pkgs()
        if not failed_pkgs:
            return ['No failed merges found.']

        pkg_invalid_entries = set()
        pkg_atoms = set()
        self._get_pkg_atoms(failed_pkgs, pkg_atoms, pkg_invalid_entries)
        if pkg_invalid_entries:
            return pkg_invalid_entries

        try:
            self._tracking_file.save(failed_pkgs)
        except IOError as ex:
            errors = [
                'Unable to save failed merges to tracking file: %s\n' % str(ex)
            ]
            errors.append(', '.join(sorted(failed_pkgs)))
            return errors
        self._remove_failed_dirs(failed_pkgs)
        results = self._emerge_pkg_atoms(module_output, pkg_atoms)
        # list any new failed merges
        for pkg in sorted(self._scan()):
            results.append("'%s' still found as a failed merge." % pkg)
        # reload config and remove successful packages from tracking file
        emerge_config = load_emerge_config()
        vardb = emerge_config.target_config.trees['vartree'].dbapi
        still_failed_pkgs = {}
        for pkg, mtime in failed_pkgs.items():
            pkg_name = '%s' % pkg.replace(MERGING_IDENTIFIER, '')
            if not vardb.cpv_exists(pkg_name):
                still_failed_pkgs[pkg] = mtime
        self._tracking_file.save(still_failed_pkgs)
        return results
示例#12
0
def main(argv):

    if len(argv) <= 1:
        print('one argument required: the json file.', file=sys.stderr)
        return 1

    # init portage stuff
    settings, trees, mtimedb = load_emerge_config()
    root_config = trees[settings['ROOT']]['root_config']
    s = search(root_config, False, False, False, False, False)

    desc_tree = description_tree.DescriptionTree(parse_sysreq=False)

    # identifier => list of dependencies
    dependencies = dict()

    # list of licenses
    licenses = list()

    for pkg in desc_tree.packages():
        try:
            desc = desc_tree[pkg]
        except exception.DescriptionTreeException as err:
            print('DescriptionTree error: %s' % err, file=sys.stderr)
            return 1

        if desc.license not in licenses:
            licenses.append(desc.license)

        deps = []

        if desc.systemrequirements is not None:
            deps += [i.strip() for i in desc.systemrequirements.split(',')]

        if desc.buildrequires is not None:
            deps += [i.strip() for i in desc.buildrequires.split(',')]

        for dep in deps:
            match = description.re_depends.match(dep)
            if match is not None:
                my_dep = match.group(1)
                my_match = my_dep.split('-')[0]
                if my_match not in dependencies:
                    dependencies[my_match] = [my_dep]
                else:
                    dependencies[my_match].append(my_dep)

    json_dict = dict(
        dependencies=dict(),
        licenses=dict(),
    )

    try:
        with open(argv[1], 'r') as fp:
            json_dict = json.load(fp)
    except:
        pass

    print('***** Dependencies *****\n')
    for dep in dependencies:
        s.execute(dep)
        print(dep)
        temp = []
        for i in range(len(s.matches['pkg'])):
            print('    %i: %s' % (i, s.matches['pkg'][i][0]))
            temp.append(s.matches['pkg'][i][0])

        if dependencies[dep][0] in json_dict['dependencies']:
            if py3k:
                select = input('Select a package [%s]: ' % \
                    json_dict['dependencies'][dependencies[dep][0]])
            else:
                select = raw_input('Select a package [%s]: ' % \
                    json_dict['dependencies'][dependencies[dep][0]])
        else:
            if py3k:
                select = input('Select a package: ')
            else:
                select = raw_input('Select a package: ')
        try:
            for dep_name in dependencies[dep]:
                json_dict['dependencies'][dep_name] = temp[int(select)]
        except:
            if select != '' or dependencies[dep][0] not in json_dict[
                    'dependencies']:
                for dep_name in dependencies[dep]:
                    json_dict['dependencies'][dep_name] = select
        print('Selected: %s' % json_dict['dependencies'][dependencies[dep][0]])
        print()

    print('***** Licenses *****\n')
    for lic in licenses:
        if lic in json_dict['licenses']:
            if py3k:
                temp = input('%s [%s]: ' % (
                    lic,
                    json_dict['licenses'][lic],
                ))
            else:
                temp = raw_input('%s [%s]: ' % (
                    lic,
                    json_dict['licenses'][lic],
                ))
            if temp != '':
                json_dict['licenses'][lic] = temp
        else:
            if py3k:
                json_dict['licenses'][lic] = input('%s: ' % lic)
            else:
                json_dict['licenses'][lic] = raw_input('%s: ' % lic)
        print('Selected: %s' % json_dict['licenses'][lic])
        print()

    try:
        with open(argv[1], 'w') as fp:
            json.dump(json_dict, fp, sort_keys=True, indent=4)
    except:
        print('failed to save the json file.', file=sys.stderr)
        return 1

    return 0
示例#13
0
def emerge_main():
	global portage	# NFC why this is necessary now - genone
	portage._disable_legacy_globals()
	# Disable color until we're sure that it should be enabled (after
	# EMERGE_DEFAULT_OPTS has been parsed).
	portage.output.havecolor = 0
	# This first pass is just for options that need to be known as early as
	# possible, such as --config-root.  They will be parsed again later,
	# together with EMERGE_DEFAULT_OPTS (which may vary depending on the
	# the value of --config-root).
	myaction, myopts, myfiles = parse_opts(sys.argv[1:], silent=True)
	if "--debug" in myopts:
		os.environ["PORTAGE_DEBUG"] = "1"
	if "--config-root" in myopts:
		os.environ["PORTAGE_CONFIGROOT"] = myopts["--config-root"]
	if "--root" in myopts:
		os.environ["ROOT"] = myopts["--root"]
	if "--accept-properties" in myopts:
		os.environ["ACCEPT_PROPERTIES"] = myopts["--accept-properties"]

	# Portage needs to ensure a sane umask for the files it creates.
	os.umask(0o22)
	settings, trees, mtimedb = load_emerge_config()
	portdb = trees[settings["ROOT"]]["porttree"].dbapi
	rval = profile_check(trees, myaction)
	if rval != os.EX_OK:
		return rval

	if myaction not in ('help', 'info', 'version') and \
		_global_updates(trees, mtimedb["updates"]):
		mtimedb.commit()
		# Reload the whole config from scratch.
		settings, trees, mtimedb = load_emerge_config(trees=trees)
		portdb = trees[settings["ROOT"]]["porttree"].dbapi

	xterm_titles = "notitles" not in settings.features
	if xterm_titles:
		xtermTitle("emerge")

	tmpcmdline = []
	if "--ignore-default-opts" not in myopts:
		tmpcmdline.extend(settings["EMERGE_DEFAULT_OPTS"].split())
	tmpcmdline.extend(sys.argv[1:])
	myaction, myopts, myfiles = parse_opts(tmpcmdline)

	if "--digest" in myopts:
		os.environ["FEATURES"] = os.environ.get("FEATURES","") + " digest"
		# Reload the whole config from scratch so that the portdbapi internal
		# config is updated with new FEATURES.
		settings, trees, mtimedb = load_emerge_config(trees=trees)
		portdb = trees[settings["ROOT"]]["porttree"].dbapi

	adjust_configs(myopts, trees)
	apply_priorities(settings)

	if myaction == 'version':
		writemsg_stdout(getportageversion(
			settings["PORTDIR"], settings["ROOT"],
			settings.profile_path, settings["CHOST"],
			trees[settings["ROOT"]]["vartree"].dbapi) + '\n', noiselevel=-1)
		return 0
	elif myaction == 'help':
		_emerge.help.help(myopts, portage.output.havecolor)
		return 0

	spinner = stdout_spinner()
	if "candy" in settings.features:
		spinner.update = spinner.update_scroll

	if "--quiet" not in myopts:
		portage.deprecated_profile_check(settings=settings)
		repo_name_check(trees)
		repo_name_duplicate_check(trees)
		config_protect_check(trees)
	check_procfs()

	if "getbinpkg" in settings.features:
		myopts["--getbinpkg"] = True

	if "--getbinpkgonly" in myopts:
		myopts["--getbinpkg"] = True

	if "--getbinpkgonly" in myopts:
		myopts["--usepkgonly"] = True

	if "--getbinpkg" in myopts:
		myopts["--usepkg"] = True

	if "--usepkgonly" in myopts:
		myopts["--usepkg"] = True

	if "buildpkg" in settings.features or "--buildpkgonly" in myopts:
		myopts["--buildpkg"] = True

	if "--buildpkgonly" in myopts:
		# --buildpkgonly will not merge anything, so
		# it cancels all binary package options.
		for opt in ("--getbinpkg", "--getbinpkgonly",
			"--usepkg", "--usepkgonly"):
			myopts.pop(opt, None)

	for mytrees in trees.values():
		mydb = mytrees["porttree"].dbapi
		# Freeze the portdbapi for performance (memoize all xmatch results).
		mydb.freeze()

		if "--usepkg" in myopts:
			# Populate the bintree with current --getbinpkg setting.
			# This needs to happen before expand_set_arguments(), in case
			# any sets use the bintree.
			mytrees["bintree"].populate(
				getbinpkgs="--getbinpkg" in myopts)

	del mytrees, mydb

	if "moo" in myfiles:
		print("""

  Larry loves Gentoo (""" + platform.system() + """)

 _______________________
< Have you mooed today? >
 -----------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\ 
                ||----w |
                ||     ||

""")

	for x in myfiles:
		ext = os.path.splitext(x)[1]
		if (ext == ".ebuild" or ext == ".tbz2") and os.path.exists(os.path.abspath(x)):
			print(colorize("BAD", "\n*** emerging by path is broken and may not always work!!!\n"))
			break

	root_config = trees[settings["ROOT"]]["root_config"]
	if myaction == "list-sets":
		writemsg_stdout("".join("%s\n" % s for s in sorted(root_config.sets)))
		return os.EX_OK

	ensure_required_sets(trees)

	# only expand sets for actions taking package arguments
	oldargs = myfiles[:]
	if myaction in ("clean", "config", "depclean", "info", "prune", "unmerge", None):
		myfiles, retval = expand_set_arguments(myfiles, myaction, root_config)
		if retval != os.EX_OK:
			return retval

		# Need to handle empty sets specially, otherwise emerge will react 
		# with the help message for empty argument lists
		if oldargs and not myfiles:
			print("emerge: no targets left after set expansion")
			return 0

	if ("--tree" in myopts) and ("--columns" in myopts):
		print("emerge: can't specify both of \"--tree\" and \"--columns\".")
		return 1

	if '--emptytree' in myopts and '--noreplace' in myopts:
		writemsg_level("emerge: can't specify both of " + \
			"\"--emptytree\" and \"--noreplace\".\n",
			level=logging.ERROR, noiselevel=-1)
		return 1

	if ("--quiet" in myopts):
		spinner.update = spinner.update_quiet
		portage.util.noiselimit = -1

	if "--fetch-all-uri" in myopts:
		myopts["--fetchonly"] = True

	if "--skipfirst" in myopts and "--resume" not in myopts:
		myopts["--resume"] = True

	# Allow -p to remove --ask
	if "--pretend" in myopts:
		myopts.pop("--ask", None)

	# forbid --ask when not in a terminal
	# note: this breaks `emerge --ask | tee logfile`, but that doesn't work anyway.
	if ("--ask" in myopts) and (not sys.stdin.isatty()):
		portage.writemsg("!!! \"--ask\" should only be used in a terminal. Exiting.\n",
			noiselevel=-1)
		return 1

	if settings.get("PORTAGE_DEBUG", "") == "1":
		spinner.update = spinner.update_quiet
		portage.debug=1
		if "python-trace" in settings.features:
			import portage.debug
			portage.debug.set_trace(True)

	if not ("--quiet" in myopts):
		if '--nospinner' in myopts or \
			settings.get('TERM') == 'dumb' or \
			not sys.stdout.isatty():
			spinner.update = spinner.update_basic

	if "--debug" in myopts:
		print("myaction", myaction)
		print("myopts", myopts)

	if not myaction and not myfiles and "--resume" not in myopts:
		_emerge.help.help(myopts, portage.output.havecolor)
		return 1

	pretend = "--pretend" in myopts
	fetchonly = "--fetchonly" in myopts or "--fetch-all-uri" in myopts
	buildpkgonly = "--buildpkgonly" in myopts

	# check if root user is the current user for the actions where emerge needs this
	if portage.secpass < 2:
		# We've already allowed "--version" and "--help" above.
		if "--pretend" not in myopts and myaction not in ("search","info"):
			need_superuser = myaction in ('clean', 'depclean', 'deselect',
				'prune', 'unmerge') or not \
				(fetchonly or \
				(buildpkgonly and secpass >= 1) or \
				myaction in ("metadata", "regen") or \
				(myaction == "sync" and os.access(settings["PORTDIR"], os.W_OK)))
			if portage.secpass < 1 or \
				need_superuser:
				if need_superuser:
					access_desc = "superuser"
				else:
					access_desc = "portage group"
				# Always show portage_group_warning() when only portage group
				# access is required but the user is not in the portage group.
				from portage.data import portage_group_warning
				if "--ask" in myopts:
					myopts["--pretend"] = True
					del myopts["--ask"]
					print(("%s access is required... " + \
						"adding --pretend to options\n") % access_desc)
					if portage.secpass < 1 and not need_superuser:
						portage_group_warning()
				else:
					sys.stderr.write(("emerge: %s access is required\n") \
						% access_desc)
					if portage.secpass < 1 and not need_superuser:
						portage_group_warning()
					return 1

	disable_emergelog = False
	for x in ("--pretend", "--fetchonly", "--fetch-all-uri"):
		if x in myopts:
			disable_emergelog = True
			break
	if myaction in ("search", "info"):
		disable_emergelog = True
	if disable_emergelog:
		""" Disable emergelog for everything except build or unmerge
		operations.  This helps minimize parallel emerge.log entries that can
		confuse log parsers.  We especially want it disabled during
		parallel-fetch, which uses --resume --fetchonly."""
		_emerge.emergelog._disable = True

	else:
		if 'EMERGE_LOG_DIR' in settings:
			try:
				# At least the parent needs to exist for the lock file.
				portage.util.ensure_dirs(settings['EMERGE_LOG_DIR'])
			except portage.exception.PortageException as e:
				writemsg_level("!!! Error creating directory for " + \
					"EMERGE_LOG_DIR='%s':\n!!! %s\n" % \
					(settings['EMERGE_LOG_DIR'], e),
					noiselevel=-1, level=logging.ERROR)
			else:
				global _emerge_log_dir
				_emerge_log_dir = settings['EMERGE_LOG_DIR']

	if not "--pretend" in myopts:
		emergelog(xterm_titles, "Started emerge on: "+\
			_unicode_decode(
				time.strftime("%b %d, %Y %H:%M:%S", time.localtime()),
				encoding=_encodings['content'], errors='replace'))
		myelogstr=""
		if myopts:
			myelogstr=" ".join(myopts)
		if myaction:
			myelogstr+=" "+myaction
		if myfiles:
			myelogstr += " " + " ".join(oldargs)
		emergelog(xterm_titles, " *** emerge " + myelogstr)
	del oldargs

	def emergeexitsig(signum, frame):
		signal.signal(signal.SIGINT, signal.SIG_IGN)
		signal.signal(signal.SIGTERM, signal.SIG_IGN)
		portage.util.writemsg("\n\nExiting on signal %(signal)s\n" % {"signal":signum})
		sys.exit(100+signum)
	signal.signal(signal.SIGINT, emergeexitsig)
	signal.signal(signal.SIGTERM, emergeexitsig)

	def emergeexit():
		"""This gets out final log message in before we quit."""
		if "--pretend" not in myopts:
			emergelog(xterm_titles, " *** terminating.")
		if xterm_titles:
			xtermTitleReset()
	portage.atexit_register(emergeexit)

	if myaction in ("config", "metadata", "regen", "sync"):
		if "--pretend" in myopts:
			sys.stderr.write(("emerge: The '%s' action does " + \
				"not support '--pretend'.\n") % myaction)
			return 1

	if "sync" == myaction:
		return action_sync(settings, trees, mtimedb, myopts, myaction)
	elif "metadata" == myaction:
		action_metadata(settings, portdb, myopts)
	elif myaction=="regen":
		validate_ebuild_environment(trees)
		return action_regen(settings, portdb, myopts.get("--jobs"),
			myopts.get("--load-average"))
	# HELP action
	elif "config"==myaction:
		validate_ebuild_environment(trees)
		action_config(settings, trees, myopts, myfiles)

	# SEARCH action
	elif "search"==myaction:
		validate_ebuild_environment(trees)
		action_search(trees[settings["ROOT"]]["root_config"],
			myopts, myfiles, spinner)

	elif myaction in ('clean', 'depclean', 'deselect', 'prune', 'unmerge'):
		validate_ebuild_environment(trees)
		rval = action_uninstall(settings, trees, mtimedb["ldpath"],
			myopts, myaction, myfiles, spinner)
		if not (myaction == 'deselect' or buildpkgonly or fetchonly or pretend):
			post_emerge(root_config, myopts, mtimedb, rval)
		return rval

	elif myaction == 'info':

		# Ensure atoms are valid before calling unmerge().
		vardb = trees[settings["ROOT"]]["vartree"].dbapi
		portdb = trees[settings["ROOT"]]["porttree"].dbapi
		bindb = trees[settings["ROOT"]]["bintree"].dbapi
		valid_atoms = []
		for x in myfiles:
			if is_valid_package_atom(x):
				try:
					#look at the installed files first, if there is no match
					#look at the ebuilds, since EAPI 4 allows running pkg_info
					#on non-installed packages
					valid_atom = dep_expand(x, mydb=vardb, settings=settings)
					if valid_atom.cp.split("/")[0] == "null":
						valid_atom = dep_expand(x, mydb=portdb, settings=settings)
					if valid_atom.cp.split("/")[0] == "null" and "--usepkg" in myopts:
						valid_atom = dep_expand(x, mydb=bindb, settings=settings)
					valid_atoms.append(valid_atom)
				except portage.exception.AmbiguousPackageName as e:
					msg = "The short ebuild name \"" + x + \
						"\" is ambiguous.  Please specify " + \
						"one of the following " + \
						"fully-qualified ebuild names instead:"
					for line in textwrap.wrap(msg, 70):
						writemsg_level("!!! %s\n" % (line,),
							level=logging.ERROR, noiselevel=-1)
					for i in e[0]:
						writemsg_level("    %s\n" % colorize("INFORM", i),
							level=logging.ERROR, noiselevel=-1)
					writemsg_level("\n", level=logging.ERROR, noiselevel=-1)
					return 1
				continue
			msg = []
			msg.append("'%s' is not a valid package atom." % (x,))
			msg.append("Please check ebuild(5) for full details.")
			writemsg_level("".join("!!! %s\n" % line for line in msg),
				level=logging.ERROR, noiselevel=-1)
			return 1

		return action_info(settings, trees, myopts, valid_atoms)

	# "update", "system", or just process files:
	else:
		validate_ebuild_environment(trees)

		for x in myfiles:
			if x.startswith(SETPREFIX) or \
				is_valid_package_atom(x):
				continue
			if x[:1] == os.sep:
				continue
			try:
				os.lstat(x)
				continue
			except OSError:
				pass
			msg = []
			msg.append("'%s' is not a valid package atom." % (x,))
			msg.append("Please check ebuild(5) for full details.")
			writemsg_level("".join("!!! %s\n" % line for line in msg),
				level=logging.ERROR, noiselevel=-1)
			return 1

		if "--pretend" not in myopts:
			display_news_notification(root_config, myopts)
		retval = action_build(settings, trees, mtimedb,
			myopts, myaction, myfiles, spinner)
		root_config = trees[settings["ROOT"]]["root_config"]
		post_emerge(root_config, myopts, mtimedb, retval)

		return retval
示例#14
0
    def Initialize(self, args):
        """Initializer. Parses arguments and sets up portage state."""

        # Parse and strip out args that are just intended for parallel_emerge.
        emerge_args = self.ParseParallelEmergeArgs(args)

        if self.sysroot and self.board:
            cros_build_lib.Die('--sysroot and --board are incompatible.')

        # Setup various environment variables based on our current board. These
        # variables are normally setup inside emerge-${BOARD}, but since we don't
        # call that script, we have to set it up here. These variables serve to
        # point our tools at /build/BOARD and to setup cross compiles to the
        # appropriate board as configured in toolchain.conf.
        if self.board:
            self.sysroot = os.environ.get(
                'SYSROOT', cros_build_lib.GetSysroot(self.board))

        if self.sysroot:
            os.environ['PORTAGE_CONFIGROOT'] = self.sysroot
            os.environ['SYSROOT'] = self.sysroot

        # Turn off interactive delays
        os.environ['EBEEP_IGNORE'] = '1'
        os.environ['EPAUSE_IGNORE'] = '1'
        os.environ['CLEAN_DELAY'] = '0'

        # Parse the emerge options.
        action, opts, cmdline_packages = parse_opts(emerge_args, silent=True)

        # Set environment variables based on options. Portage normally sets these
        # environment variables in emerge_main, but we can't use that function,
        # because it also does a bunch of other stuff that we don't want.
        # TODO(davidjames): Patch portage to move this logic into a function we can
        # reuse here.
        if '--debug' in opts:
            os.environ['PORTAGE_DEBUG'] = '1'
        if '--config-root' in opts:
            os.environ['PORTAGE_CONFIGROOT'] = opts['--config-root']
        if '--root' in opts:
            os.environ['ROOT'] = opts['--root']
        elif self.board and 'ROOT' not in os.environ:
            os.environ['ROOT'] = self.sysroot
        if '--accept-properties' in opts:
            os.environ['ACCEPT_PROPERTIES'] = opts['--accept-properties']

        # If we're installing packages to the board, we can disable vardb locks.
        # This is safe because we only run up to one instance of parallel_emerge in
        # parallel.
        # TODO(davidjames): Enable this for the host too.
        if self.sysroot:
            os.environ.setdefault('PORTAGE_LOCKS', 'false')

        # Now that we've setup the necessary environment variables, we can load the
        # emerge config from disk.
        # pylint: disable=unpacking-non-sequence
        settings, trees, mtimedb = load_emerge_config()

        # Add in EMERGE_DEFAULT_OPTS, if specified.
        tmpcmdline = []
        if '--ignore-default-opts' not in opts:
            tmpcmdline.extend(settings['EMERGE_DEFAULT_OPTS'].split())
        tmpcmdline.extend(emerge_args)
        action, opts, cmdline_packages = parse_opts(tmpcmdline)

        # If we're installing to the board, we want the --root-deps option so that
        # portage will install the build dependencies to that location as well.
        if self.sysroot:
            opts.setdefault('--root-deps', True)

        # Check whether our portage tree is out of date. Typically, this happens
        # when you're setting up a new portage tree, such as in setup_board and
        # make_chroot. In that case, portage applies a bunch of global updates
        # here. Once the updates are finished, we need to commit any changes
        # that the global update made to our mtimedb, and reload the config.
        #
        # Portage normally handles this logic in emerge_main, but again, we can't
        # use that function here.
        if _global_updates(trees, mtimedb['updates']):
            mtimedb.commit()
            # pylint: disable=unpacking-non-sequence
            settings, trees, mtimedb = load_emerge_config(trees=trees)

        # Setup implied options. Portage normally handles this logic in
        # emerge_main.
        if '--buildpkgonly' in opts or 'buildpkg' in settings.features:
            opts.setdefault('--buildpkg', True)
        if '--getbinpkgonly' in opts:
            opts.setdefault('--usepkgonly', True)
            opts.setdefault('--getbinpkg', True)
        if 'getbinpkg' in settings.features:
            # Per emerge_main, FEATURES=getbinpkg overrides --getbinpkg=n
            opts['--getbinpkg'] = True
        if '--getbinpkg' in opts or '--usepkgonly' in opts:
            opts.setdefault('--usepkg', True)
        if '--fetch-all-uri' in opts:
            opts.setdefault('--fetchonly', True)
        if '--skipfirst' in opts:
            opts.setdefault('--resume', True)
        if '--buildpkgonly' in opts:
            # --buildpkgonly will not merge anything, so it overrides all binary
            # package options.
            for opt in ('--getbinpkg', '--getbinpkgonly', '--usepkg',
                        '--usepkgonly'):
                opts.pop(opt, None)
        if (settings.get('PORTAGE_DEBUG', '') == '1'
                and 'python-trace' in settings.features):
            portage.debug.set_trace(True)

        # Complain about unsupported options
        for opt in ('--ask', '--ask-enter-invalid', '--resume', '--skipfirst'):
            if opt in opts:
                print('%s is not supported by parallel_emerge' % opt)
                sys.exit(1)

        # Make emerge specific adjustments to the config (e.g. colors!)
        adjust_configs(opts, trees)

        # Save our configuration so far in the emerge object
        emerge = self.emerge
        emerge.action, emerge.opts = action, opts
        emerge.settings, emerge.trees, emerge.mtimedb = settings, trees, mtimedb
        emerge.cmdline_packages = cmdline_packages
        root = settings['ROOT']
        emerge.root_config = trees[root]['root_config']

        if '--usepkg' in opts:
            emerge.trees[root]['bintree'].populate('--getbinpkg' in opts)
示例#15
0
def main(argv):

    if len(argv) <= 1:
        print('one argument required: the json file.', file=sys.stderr)
        return 1

    # init portage stuff
    settings, trees, mtimedb = load_emerge_config()
    root_config = trees[settings['ROOT']]['root_config']
    s = search(root_config, False, False, False, False, False)

    desc_tree = description_tree.DescriptionTree(parse_sysreq = False)

    # identifier => list of dependencies
    dependencies = dict()
    
    # list of licenses
    licenses = list()

    for pkg in desc_tree.packages():
        try:
            desc = desc_tree[pkg]
        except exception.DescriptionTreeException as err:
            print('DescriptionTree error: %s' % err, file=sys.stderr)
            return 1
        
        if desc.license not in licenses:
            licenses.append(desc.license)
        
        deps = []

        if desc.systemrequirements is not None:
            deps += [i.strip() for i in desc.systemrequirements.split(',')]

        if desc.buildrequires is not None:
            deps += [i.strip() for i in desc.buildrequires.split(',')]

        for dep in deps:
            match = description.re_depends.match(dep)
            if match is not None:
                my_dep = match.group(1)
                my_match = my_dep.split('-')[0]
                if my_match not in dependencies:
                    dependencies[my_match] = [my_dep]
                else:
                    dependencies[my_match].append(my_dep)
    
    json_dict = dict(
        dependencies = dict(),
        licenses = dict(),
    )

    try:
        with open(argv[1], 'r') as fp:
            json_dict = json.load(fp)
    except:
        pass
    
    print('***** Dependencies *****\n')
    for dep in dependencies:
        s.execute(dep)
        print(dep)
        temp = []
        for i in range(len(s.matches['pkg'])):
            print('    %i: %s' % (i, s.matches['pkg'][i][0]))
            temp.append(s.matches['pkg'][i][0])

        if dependencies[dep][0] in json_dict['dependencies']:
            if py3k:
                select = input('Select a package [%s]: ' % \
                    json_dict['dependencies'][dependencies[dep][0]])
            else:
                select = raw_input('Select a package [%s]: ' % \
                    json_dict['dependencies'][dependencies[dep][0]])
        else:
            if py3k:
                select = input('Select a package: ')
            else:
                select = raw_input('Select a package: ')
        try:
            for dep_name in dependencies[dep]:
                json_dict['dependencies'][dep_name] = temp[int(select)]
        except:
            if select != '' or dependencies[dep][0] not in json_dict['dependencies']:
                for dep_name in dependencies[dep]:
                    json_dict['dependencies'][dep_name] = select
        print('Selected: %s' % json_dict['dependencies'][dependencies[dep][0]])
        print()
    
    print('***** Licenses *****\n')
    for lic in licenses:
        if lic in json_dict['licenses']:
            if py3k:
                temp = input(
                    '%s [%s]: ' % (
                        lic,
                        json_dict['licenses'][lic],
                    )
                )
            else:
                temp = raw_input(
                    '%s [%s]: ' % (
                        lic,
                        json_dict['licenses'][lic],
                    )
                )
            if temp != '':
                json_dict['licenses'][lic] = temp
        else:
            if py3k:
                json_dict['licenses'][lic] = input('%s: ' % lic)
            else:
                json_dict['licenses'][lic] = raw_input('%s: ' % lic)
        print('Selected: %s' % json_dict['licenses'][lic])
        print()

    try:
        with open(argv[1], 'w') as fp:
            json.dump(json_dict, fp, sort_keys=True, indent=4)
    except:
        print('failed to save the json file.', file=sys.stderr)
        return 1

    return 0
示例#16
0
					for ext in dir_extensions:
						try:
							os.unlink(dir_file + ext + ".old")
						except EnvironmentError as e:
							if e.errno != errno.ENOENT:
								raise
							del e
	
					#update mtime so we can potentially avoid regenerating.
					prev_mtimes[inforoot] = os.stat(inforoot)[stat.ST_MTIME]
	
				if badcount:
					out.eerror("Processed %d info files; %d errors." % \
						(icount, badcount))
					writemsg_level(errmsg, level=logging.ERROR, noiselevel=-1)
				else:
					if icount > 0:
						out.einfo("Processed %d info files." % (icount,))

if __name__ == "__main__":
	settings, trees, mtimedb = load_emerge_config()
	x=PluginPhaseAdapter("/", settings, trees, mtimedb)
	a=InfoPlugin()
	b=EtcConfigPlugin()
	x.configure(a)
	x.configure(b)
	print(a.needsToRun())
	print(a.run())
	print(b.needsToRun())
	print(b.run())