Substitute SchedulerInterface for PollScheduler.
authorZac Medico <zmedico@gentoo.org>
Sun, 7 Oct 2012 19:12:52 +0000 (12:12 -0700)
committerZac Medico <zmedico@gentoo.org>
Sun, 7 Oct 2012 19:15:52 +0000 (12:15 -0700)
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
pym/portage/dbapi/vartree.py
pym/portage/package/ebuild/_spawn_nofetch.py
pym/portage/package/ebuild/doebuild.py
pym/portage/tests/ebuild/test_doebuild_spawn.py

index 2707d22c1054aa10128340e2b64762787eec93d8..5d1110a08e59f7b48b2775d1b3af4a8ce6006650 100644 (file)
@@ -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
 
index f00a87ad2adfe6648c17f217c40958e9dd72ae1f..11d98004475c2490d6b1ae5d3f7cc9f6e9d0c025 100644 (file)
@@ -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,
index 94f8c79a31737b83ba969234441d1b853d7187df..c4e1831461ec04d7790477b06478561cf19ca283 100644 (file)
@@ -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()
index 39cd22824cf4d1e0d1b37e201f5407520df8840d..650c3633a4c6271a24988c2f13fad7f5d36f5391 100644 (file)
@@ -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()
index a0a80ace4da973e103133ec14c6dc8030789f93c..6c66f81ca7195cac92e8f0fc414fdb43da083425 100644 (file)
@@ -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