コード例 #1
0
ファイル: entropysrv.py プロジェクト: Heather/entropy
 def acquire(self):
     """
     Overridden from BaseBinaryResourceLock.
     """
     lock = EntropyResourcesLock(output=Server)
     if self._blocking:
         lock.acquire_exclusive()
         acquired = True
     else:
         acquired = lock.wait_exclusive()
     if not acquired:
         raise EntropyResourceLock.NotAcquired(
             "unable to acquire lock")
コード例 #2
0
ファイル: command.py プロジェクト: Sabayon/entropy
    def _call_exclusive(self, func):
        """
        Execute the given function at func after acquiring Entropy
        Resources Lock, for given repository at repo.
        The signature of func is: int func(entropy_client).
        """
        client_class = None
        client = None
        acquired = False
        lock = None
        try:
            try:
                client_class = self._entropy_class()
            except PermissionDenied as err:
                print_error(err.value)
                return 1
            blocking = os.getenv("__EQUO_LOCKS_BLOCKING__")
            if blocking:
                client_class.output(darkgreen(
                        _("Acquiring Entropy Resources "
                          "Lock, please wait...")),
                              back=True)

            lock = EntropyResourcesLock(output=client_class)
            if blocking:
                lock.acquire_exclusive()
                acquired = True
            else:
                acquired = lock.wait_exclusive()
            if not acquired:
                client_class.output(
                    darkgreen(_("Another Entropy is currently running.")),
                    level="error", importance=1
                )
                return 1

            client = client_class()
            return func(client)
        finally:
            if client is not None:
                client.shutdown()
            if acquired:
                lock.release()
コード例 #3
0
ファイル: command.py プロジェクト: berkerovic/entropy
    def _call_exclusive(self, func):
        """
        Execute the given function at func after acquiring Entropy
        Resources Lock, for given repository at repo.
        The signature of func is: int func(entropy_client).
        """
        client_class = None
        client = None
        acquired = False
        lock = None
        try:
            try:
                client_class = self._entropy_class()
            except PermissionDenied as err:
                print_error(err.value)
                return 1
            blocking = os.getenv("__EQUO_LOCKS_BLOCKING__")
            if blocking:
                client_class.output(darkgreen(
                        _("Acquiring Entropy Resources "
                          "Lock, please wait...")),
                              back=True)

            lock = EntropyResourcesLock(output=client_class)
            if blocking:
                lock.acquire_exclusive()
                acquired = True
            else:
                acquired = lock.wait_exclusive()
            if not acquired:
                client_class.output(
                    darkgreen(_("Another Entropy is currently running.")),
                    level="error", importance=1
                )
                return 1

            client = client_class()
            return func(client)
        finally:
            if client is not None:
                client.shutdown()
            if acquired:
                lock.release()