From 4d343233dcd86913b59f1744a615f86b1d1802c0 Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Sat, 12 Nov 2011 16:10:33 +0100 Subject: [PATCH] [entropy.*] drop usage of another_entropy_running(), wait_resources() or similar methods should be used --- lib/entropy/client/interfaces/methods.py | 4 ++++ lib/entropy/client/interfaces/package.py | 10 ---------- lib/entropy/security.py | 10 ---------- lib/tests/client.py | 12 ------------ sulfur/src/sulfur/__init__.py | 25 ++++-------------------- 5 files changed, 8 insertions(+), 53 deletions(-) diff --git a/lib/entropy/client/interfaces/methods.py b/lib/entropy/client/interfaces/methods.py index 78928bf7f..95decfab2 100644 --- a/lib/entropy/client/interfaces/methods.py +++ b/lib/entropy/client/interfaces/methods.py @@ -1767,10 +1767,14 @@ class MiscMixin: def another_entropy_running(self): """ Check if another Entropy instance is running. + TODO: drop method. + @deprecated: use Entropy resources methods! This will be removed SOON. @return: True if another Entropy instance is running, False otherwise. @rtype: bool """ + import warnings + warnings.warn("attention, deprecated, update your code") acquired, locked = const_setup_entropy_pid(just_read = True) return locked diff --git a/lib/entropy/client/interfaces/package.py b/lib/entropy/client/interfaces/package.py index bf1203b89..1406f7709 100644 --- a/lib/entropy/client/interfaces/package.py +++ b/lib/entropy/client/interfaces/package.py @@ -3659,16 +3659,6 @@ class Package: def run(self, xterm_header = None): self._error_on_not_prepared() - locked = self._entropy.another_entropy_running() - if locked: - self._entropy.output( - red(_("Another Entropy is currently running.")), - importance = 1, - level = "error", - header = darkred(" @@ ") - ) - return 21 - gave_up = self._entropy.wait_resources() if gave_up: return 20 diff --git a/lib/entropy/security.py b/lib/entropy/security.py index ac4ec3c2e..9dffe470d 100644 --- a/lib/entropy/security.py +++ b/lib/entropy/security.py @@ -1034,16 +1034,6 @@ class System: header = red(" @@ ") ) - locked = self._entropy.another_entropy_running() - if locked: - self._entropy.output( - red(_("Another Entropy is currently running.")), - importance = 1, - level = "error", - header = darkred(" @@ ") - ) - return 4 - gave_up = self._entropy.wait_resources() if gave_up: return 7 diff --git a/lib/tests/client.py b/lib/tests/client.py index f855d1319..0d218a79b 100644 --- a/lib/tests/client.py +++ b/lib/tests/client.py @@ -49,18 +49,6 @@ class EntropyRepositoryTest(unittest.TestCase): self.Client.destroy() self.Client.shutdown() - def test_another_instance(self): - pid = os.fork() - if pid == 0: - # child - locked = self.Client.another_entropy_running() - if locked: - os._exit(1) - os._exit(0) - else: - rc = os.waitpid(pid, 0)[1] - self.assertNotEqual(rc, 0) - def test_singleton(self): myclient = Client(installed_repo = -1) self.assertTrue(myclient is self.Client) diff --git a/sulfur/src/sulfur/__init__.py b/sulfur/src/sulfur/__init__.py index d047498a3..eb728f23d 100644 --- a/sulfur/src/sulfur/__init__.py +++ b/sulfur/src/sulfur/__init__.py @@ -96,10 +96,8 @@ class SulfurApplication(Controller, SulfurApplicationEventsMixin): else: # we don't want to interleave equo or entropy services with # sulfur. People just cannot deal with it. - locked = self._entropy.another_entropy_running() - if not locked: - locked = not entropy.tools.acquire_entropy_locks(self._entropy, - max_tries = 5) + locked = not entropy.tools.acquire_entropy_locks( + self._entropy, max_tries = 5) self._effective_root = os.getuid() == 0 if self._effective_root: self._privileges.drop() @@ -1549,17 +1547,9 @@ class SulfurApplication(Controller, SulfurApplicationEventsMixin): with self._privileges: - # preventive check against other instances - locked = self._entropy.another_entropy_running() - if locked or not entropy.tools.is_root(): - okDialog(self.ui.main, - _("Another Entropy instance is running. Cannot process queue.")) - self.progress.reset_progress() - self.switch_notebook_page('packages') - return False - self.disable_ugc = True # acquire Entropy resources here to avoid surpises afterwards + # this might be superfluous acquired = self._entropy.lock_resources() if not acquired: okDialog(self.ui.main, @@ -2367,17 +2357,10 @@ class SulfurApplication(Controller, SulfurApplicationEventsMixin): with self._privileges: - # preventive check against other instances - locked = self._entropy.another_entropy_running() - if locked or not entropy.tools.is_root(): - okDialog(self.ui.main, - _("Another Entropy instance is running. Cannot process queue.")) - self.progress.reset_progress() - self.switch_notebook_page('packages') - return False self.disable_ugc = True # acquire Entropy resources here to avoid surpises afterwards + # this might be superfluous acquired = self._entropy.lock_resources() if not acquired: okDialog(self.ui.main,