def _call_shared(self, func): """ Execute the given function at func after acquiring Entropy Resources Lock in shared mode, 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 lock = EntropyResourcesLock(output=client_class) lock.acquire_shared() acquired = True client = client_class() return func(client) finally: if client is not None: client.shutdown() if acquired: lock.release()
def _upgrade_respawn(self, entropy_client, inst_repo): """ Respawn the upgrade activity if required. """ # It might be an Entropy bug and Entropy was proritized in the # install queue, ignoring the rest of available packages. # So, respawning myself again using execvp() should be a much # better idea. with inst_repo.shared(): outcome = entropy_client.calculate_updates() if outcome['update']: entropy_client.output( "%s." % ( purple(_("There are more updates to install, " "reloading Entropy")),), header=teal(" @@ ")) # then spawn a new process entropy_client.shutdown() # hack to tell the resurrected equo to block on # locking acquisition os.environ['__EQUO_LOCKS_BLOCKING__'] = "1" # we will acquire them again in blocking mode, cross # fingers lock = EntropyResourcesLock(output=entropy_client) lock.release() os.execvp("equo", sys.argv)
def _upgrade_respawn(self, entropy_client, inst_repo): """ Respawn the upgrade activity if required. """ # It might be an Entropy bug and Entropy was proritized in the # install queue, ignoring the rest of available packages. # So, respawning myself again using execvp() should be a much # better idea. with inst_repo.shared(): outcome = entropy_client.calculate_updates() if outcome['update']: entropy_client.output("%s." % (purple( _("There are more updates to install, " "reloading Entropy")), ), header=teal(" @@ ")) # then spawn a new process entropy_client.shutdown() # hack to tell the resurrected equo to block on # locking acquisition os.environ['__EQUO_LOCKS_BLOCKING__'] = "1" # we will acquire them again in blocking mode, cross # fingers lock = EntropyResourcesLock(output=entropy_client) lock.release() os.execvp("equo", sys.argv)
def _call_shared(self, func, repo): """ Execute the given function at func after acquiring Entropy Resources Lock in shared mode, 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) lock.acquire_shared() acquired = True 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()
def _call_shared(self, func, repo): """ Execute the given function at func after acquiring Entropy Resources Lock in shared mode, 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) lock.acquire_shared() acquired = True 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()
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()
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()
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 try: try: server_class = self._entropy_class() except PermissionDenied as err: print_error(err.value) return 1 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()
def release(self): """ Overridden from BaseBinaryResourceLock. """ lock = EntropyResourcesLock(output=Server) lock.release()