From ea7e5af4c175d24ff98c03c5b03cd614dad217d0 Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Sat, 30 Jul 2011 23:02:57 +0200 Subject: [PATCH] [entropy.tools] acquire_entropy_locks: make it modular, add acquire_entropy_resources_locks --- libraries/entropy/tools.py | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/libraries/entropy/tools.py b/libraries/entropy/tools.py index 743473dd9..0463940a5 100644 --- a/libraries/entropy/tools.py +++ b/libraries/entropy/tools.py @@ -2918,20 +2918,40 @@ def release_lock(lock_file, lock_map): if err.errno != errno.ENOENT: raise -def acquire_entropy_locks(entropy_client): +def acquire_entropy_locks(entropy_client, blocking = False): """ Acquire Entropy Client/Server file locks. + + @param entropy_client: any Entropy Client based instance + @type entropy_client: entropy.client.interfaces.Client + @keyword blocking: acquire locks in blocking mode? + @type blocking: bool """ locked = entropy_client.another_entropy_running() if locked: return False + return acquire_entropy_resources_locks(entropy_client, + blocking = blocking) - gave_up = entropy_client.wait_resources() - if gave_up: - return False +def acquire_entropy_resources_locks(entropy_client, blocking = False): + """ + Acquire Entropy Resources General Lock. + This lock is controlling write access to entropy package metadata and + other writeable destinations. + Can be unlocked by simply calling release_entropy_locks(). + + @param entropy_client: any Entropy Client based instance + @type entropy_client: entropy.client.interfaces.Client + @keyword blocking: acquire locks in blocking mode? + @type blocking: bool + """ + if not blocking: + gave_up = entropy_client.wait_resources() + if gave_up: + return False # acquire resources lock - acquired = entropy_client.lock_resources() + acquired = entropy_client.lock_resources(blocking = blocking) if not acquired: return False @@ -2940,5 +2960,8 @@ def acquire_entropy_locks(entropy_client): def release_entropy_locks(entropy_client): """ Release Entropy Client/Server file locks. + + @param entropy_client: any Entropy Client based instance + @type entropy_client: entropy.client.interfaces.Client """ entropy_client.unlock_resources()