コード例 #1
0
ファイル: entropysrv.py プロジェクト: skwerlman/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
ファイル: 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")
コード例 #3
0
ファイル: command.py プロジェクト: skwerlman/entropy
    def _call_exclusive(self, func, repo):
        """
        Execute the given function at func after acquiring Entropy
        Resources Lock, for given repository at repo.
        The signature of func is: int func(entropy_server).
        """
        server = None
        server_class = None
        acquired = False
        lock = None

        # make possible to avoid dealing with the resources lock.
        # This is useful if the lock is already acquired by some
        # parent or controller process.
        skip_lock = os.getenv("EIT_NO_RESOURCES_LOCK") is not None

        try:
            try:
                server_class = self._entropy_class()
            except PermissionDenied as err:
                print_error(err.value)
                return 1

            if not skip_lock:
                lock = EntropyResourcesLock(output=server_class)
                acquired = lock.wait_exclusive()
                if not acquired:
                    server_class.output(darkgreen(
                        _("Another Entropy is currently running.")),
                                        level="error",
                                        importance=1)
                    return 1

            server = server_class(default_repository=repo)

            # make sure that repositories are closed now
            # to reset their internal states, which could have
            # become stale.
            # We cannot do this inside the API because we don't
            # know the lifecycle of EntropyRepository objects there.
            server.close_repositories()
            ServerRepositoryStatus().reset()

            return func(server)
        finally:
            if server is not None:
                server.shutdown()
            if acquired:
                lock.release()
コード例 #4
0
ファイル: command.py プロジェクト: Enlik/entropy
    def _call_exclusive(self, func, repo):
        """
        Execute the given function at func after acquiring Entropy
        Resources Lock, for given repository at repo.
        The signature of func is: int func(entropy_server).
        """
        server = None
        server_class = None
        acquired = False
        lock = None

        # make possible to avoid dealing with the resources lock.
        # This is useful if the lock is already acquired by some
        # parent or controller process.
        skip_lock = os.getenv("EIT_NO_RESOURCES_LOCK") is not None

        try:
            try:
                server_class = self._entropy_class()
            except PermissionDenied as err:
                print_error(err.value)
                return 1

            if not skip_lock:
                lock = EntropyResourcesLock(output=server_class)
                acquired = lock.wait_exclusive()
                if not acquired:
                    server_class.output(
                        darkgreen(_("Another Entropy is currently running.")), level="error", importance=1
                    )
                    return 1

            server = server_class(default_repository=repo)

            # make sure that repositories are closed now
            # to reset their internal states, which could have
            # become stale.
            # We cannot do this inside the API because we don't
            # know the lifecycle of EntropyRepository objects there.
            server.close_repositories()
            ServerRepositoryStatus().reset()

            return func(server)
        finally:
            if server is not None:
                server.shutdown()
            if acquired:
                lock.release()
コード例 #5
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()
コード例 #6
0
ファイル: command.py プロジェクト: jgarte/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()