From 1d0403ffdd9465cab721dabb80eec18c0f5abdcc Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Sun, 7 Oct 2012 12:12:52 -0700 Subject: [PATCH] Substitute SchedulerInterface for PollScheduler. SchedulerInterface suffices for all of these cases. EventLoop(main=False) is used for thread safety where API consumers may be using threads. --- pym/_emerge/actions.py | 14 ++++++++------ pym/portage/dbapi/vartree.py | 6 +++--- pym/portage/package/ebuild/_spawn_nofetch.py | 8 +++++--- pym/portage/package/ebuild/doebuild.py | 7 ++++--- pym/portage/tests/ebuild/test_doebuild_spawn.py | 7 ++++--- 5 files changed, 24 insertions(+), 18 deletions(-) diff --git a/pym/_emerge/actions.py b/pym/_emerge/actions.py index 2707d22c1..5d1110a08 100644 --- a/pym/_emerge/actions.py +++ b/pym/_emerge/actions.py @@ -49,6 +49,8 @@ from portage._sets.base import InternalPackageSet from portage.util import cmp_sort_key, writemsg, \ writemsg_level, writemsg_stdout from portage.util.digraph import digraph +from portage.util._async.SchedulerInterface import SchedulerInterface +from portage.util._eventloop.global_event_loop import global_event_loop from portage._global_updates import _global_updates from _emerge.clear_caches import clear_caches @@ -61,7 +63,6 @@ from _emerge.emergelog import emergelog from _emerge.is_valid_package_atom import is_valid_package_atom from _emerge.MetadataRegen import MetadataRegen from _emerge.Package import Package -from _emerge.PollScheduler import PollScheduler from _emerge.ProgressHandler import ProgressHandler from _emerge.RootConfig import RootConfig from _emerge.Scheduler import Scheduler @@ -2684,12 +2685,13 @@ def action_uninstall(settings, trees, ldpath_mtimes, # Use the same logic as the Scheduler class to trigger redirection # of ebuild pkg_prerm/postrm phase output to logs as appropriate # for options such as --jobs, --quiet and --quiet-build. - sched = PollScheduler(main=True) max_jobs = opts.get("--jobs", 1) - sched._background = (max_jobs is True or max_jobs > 1 or + background = (max_jobs is True or max_jobs > 1 or "--quiet" in opts or opts.get("--quiet-build") == "y") + sched_iface = SchedulerInterface(global_event_loop(), + is_background=lambda: background) - if sched._background: + if background: settings.unlock() settings["PORTAGE_BACKGROUND"] = "1" settings.backup_changes("PORTAGE_BACKGROUND") @@ -2701,11 +2703,11 @@ def action_uninstall(settings, trees, ldpath_mtimes, ordered = action == 'unmerge' rval = unmerge(trees[settings['EROOT']]['root_config'], opts, action, valid_atoms, ldpath_mtimes, ordered=ordered, - scheduler=sched.sched_iface) + scheduler=sched_iface) else: rval = action_depclean(settings, trees, ldpath_mtimes, opts, action, valid_atoms, spinner, - scheduler=sched.sched_iface) + scheduler=sched_iface) return rval diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py index f00a87ad2..11d980044 100644 --- a/pym/portage/dbapi/vartree.py +++ b/pym/portage/dbapi/vartree.py @@ -32,6 +32,7 @@ portage.proxy.lazyimport.lazyimport(globals(), 'portage.util.movefile:movefile', 'portage.util._dyn_libs.PreservedLibsRegistry:PreservedLibsRegistry', 'portage.util._dyn_libs.LinkageMapELF:LinkageMapELF@LinkageMap', + 'portage.util._async.SchedulerInterface:SchedulerInterface', 'portage.util._eventloop.EventLoop:EventLoop', 'portage.versions:best,catpkgsplit,catsplit,cpv_getkey,vercmp,' + \ '_pkgsplit@pkgsplit,_pkg_str', @@ -61,7 +62,6 @@ from portage import _unicode_encode from _emerge.EbuildBuildDir import EbuildBuildDir from _emerge.EbuildPhase import EbuildPhase from _emerge.emergelog import emergelog -from _emerge.PollScheduler import PollScheduler from _emerge.MiscFunctionsProcess import MiscFunctionsProcess from _emerge.SpawnProcess import SpawnProcess @@ -1782,7 +1782,7 @@ class dblink(object): if self._scheduler is None: # We create a scheduler instance and use it to # log unmerge output separately from merge output. - self._scheduler = PollScheduler().sched_iface + self._scheduler = SchedulerInterface(EventLoop(main=False)) if self.settings.get("PORTAGE_BACKGROUND") == "subprocess": if self.settings.get("PORTAGE_BACKGROUND_UNMERGE") == "1": self.settings["PORTAGE_BACKGROUND"] = "1" @@ -4631,7 +4631,7 @@ class dblink(object): self.lockdb() self.vartree.dbapi._bump_mtime(self.mycpv) if self._scheduler is None: - self._scheduler = PollScheduler().sched_iface + self._scheduler = SchedulerInterface(EventLoop(main=False)) try: retval = self.treewalk(mergeroot, myroot, inforoot, myebuild, cleanup=cleanup, mydbapi=mydbapi, prev_mtimes=prev_mtimes, diff --git a/pym/portage/package/ebuild/_spawn_nofetch.py b/pym/portage/package/ebuild/_spawn_nofetch.py index 94f8c79a3..c4e183146 100644 --- a/pym/portage/package/ebuild/_spawn_nofetch.py +++ b/pym/portage/package/ebuild/_spawn_nofetch.py @@ -1,4 +1,4 @@ -# Copyright 2010-2011 Gentoo Foundation +# Copyright 2010-2012 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 import tempfile @@ -10,8 +10,9 @@ from portage.elog import elog_process from portage.package.ebuild.config import config from portage.package.ebuild.doebuild import doebuild_environment from portage.package.ebuild.prepare_build_dirs import prepare_build_dirs +from portage.util._async.SchedulerInterface import SchedulerInterface +from portage.util._eventloop.EventLoop import EventLoop from _emerge.EbuildPhase import EbuildPhase -from _emerge.PollScheduler import PollScheduler def spawn_nofetch(portdb, ebuild_path, settings=None): """ @@ -77,7 +78,8 @@ def spawn_nofetch(portdb, ebuild_path, settings=None): prepare_build_dirs(settings=settings) ebuild_phase = EbuildPhase(background=False, - phase='nofetch', scheduler=PollScheduler().sched_iface, + phase='nofetch', + scheduler=SchedulerInterface(EventLoop(main=False)), settings=settings) ebuild_phase.start() ebuild_phase.wait() diff --git a/pym/portage/package/ebuild/doebuild.py b/pym/portage/package/ebuild/doebuild.py index 39cd22824..650c3633a 100644 --- a/pym/portage/package/ebuild/doebuild.py +++ b/pym/portage/package/ebuild/doebuild.py @@ -29,6 +29,7 @@ portage.proxy.lazyimport.lazyimport(globals(), 'portage.dep._slot_operator:evaluate_slot_operator_equal_deps', 'portage.package.ebuild._spawn_nofetch:spawn_nofetch', 'portage.util._desktop_entry:validate_desktop_entry', + 'portage.util._async.SchedulerInterface:SchedulerInterface', 'portage.util._eventloop.EventLoop:EventLoop', 'portage.util.ExtractKernelVersion:ExtractKernelVersion' ) @@ -66,7 +67,6 @@ from _emerge.EbuildBuildDir import EbuildBuildDir from _emerge.EbuildPhase import EbuildPhase from _emerge.EbuildSpawnProcess import EbuildSpawnProcess from _emerge.Package import Package -from _emerge.PollScheduler import PollScheduler from _emerge.RootConfig import RootConfig _unsandboxed_phases = frozenset([ @@ -134,7 +134,7 @@ def _spawn_phase(phase, settings, actionmap=None, **kwargs): return _doebuild_spawn(phase, settings, actionmap=actionmap, **kwargs) ebuild_phase = EbuildPhase(actionmap=actionmap, background=False, - phase=phase, scheduler=PollScheduler().sched_iface, + phase=phase, scheduler=SchedulerInterface(EventLoop(main=False)), settings=settings) ebuild_phase.start() ebuild_phase.wait() @@ -1458,7 +1458,8 @@ def spawn(mystring, mysettings, debug=0, free=0, droppriv=0, sesandbox=0, fakero proc = EbuildSpawnProcess( background=False, args=mystring, - scheduler=PollScheduler().sched_iface, spawn_func=spawn_func, + scheduler=SchedulerInterface(EventLoop(main=False)), + spawn_func=spawn_func, settings=mysettings, **keywords) proc.start() diff --git a/pym/portage/tests/ebuild/test_doebuild_spawn.py b/pym/portage/tests/ebuild/test_doebuild_spawn.py index a0a80ace4..6c66f81ca 100644 --- a/pym/portage/tests/ebuild/test_doebuild_spawn.py +++ b/pym/portage/tests/ebuild/test_doebuild_spawn.py @@ -1,4 +1,4 @@ -# Copyright 2010-2011 Gentoo Foundation +# Copyright 2010-2012 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 from portage import os @@ -9,10 +9,11 @@ from portage.package.ebuild.config import config from portage.package.ebuild.doebuild import spawn as doebuild_spawn from portage.tests import TestCase from portage.tests.resolver.ResolverPlayground import ResolverPlayground +from portage.util._async.SchedulerInterface import SchedulerInterface +from portage.util._eventloop.global_event_loop import global_event_loop from _emerge.EbuildPhase import EbuildPhase from _emerge.MiscFunctionsProcess import MiscFunctionsProcess from _emerge.Package import Package -from _emerge.PollScheduler import PollScheduler class DoebuildSpawnTestCase(TestCase): """ @@ -59,7 +60,7 @@ class DoebuildSpawnTestCase(TestCase): # has been sourced already. open(os.path.join(settings['T'], 'environment'), 'wb').close() - scheduler = PollScheduler().sched_iface + scheduler = SchedulerInterface(global_event_loop()) for phase in ('_internal_test',): # Test EbuildSpawnProcess by calling doebuild.spawn() with -- 2.26.2