Option quiet pour le lock

darcs-hash:20041205123023-d1718-526a0448dff827f459a187594773375cf6224610.gz
This commit is contained in:
bernat 2004-12-05 13:30:23 +01:00
parent e9cd4db258
commit 3311711bb5

View file

@ -13,7 +13,7 @@ from user_tests import getuser
from fcntl import lockf, LOCK_EX, LOCK_NB, LOCK_UN from fcntl import lockf, LOCK_EX, LOCK_NB, LOCK_UN
import errno import errno
def make_lock(lock_name, lock_comment='',nowait=1) : def make_lock(lock_name, lock_comment='',nowait=1, quiet=False) :
""" Création d'un lock """ Création d'un lock
si nowait=1 fait un sys.exit(254) quand un ancien lock actif est rencontré si nowait=1 fait un sys.exit(254) quand un ancien lock actif est rencontré
""" """
@ -45,6 +45,7 @@ def make_lock(lock_name, lock_comment='',nowait=1) :
# Le script lockant ne tourne plus # Le script lockant ne tourne plus
os.remove(lock_file) os.remove(lock_file)
elif nowait : elif nowait :
if not quiet:
sys.stderr.write('Lock : %s\n' % lock_file) sys.stderr.write('Lock : %s\n' % lock_file)
l=getoutput('ps -o etime --no-headers %s' % pid) l=getoutput('ps -o etime --no-headers %s' % pid)
data = [ user , pid , l.strip() ] data = [ user , pid , l.strip() ]
@ -68,8 +69,12 @@ def make_lock(lock_name, lock_comment='',nowait=1) :
data[-1]=txt data[-1]=txt
if not quiet:
sys.stderr.write('\tpropriétaire : %s\n\tpid : %s\n\tdémarré depuis %s\n' % tuple(data) ) sys.stderr.write('\tpropriétaire : %s\n\tpid : %s\n\tdémarré depuis %s\n' % tuple(data) )
sys.exit(254) sys.exit(254)
else:
# On va plutot lever une exception
raise AssertionError(tuple(data))
else : else :
# Il faut attendre # Il faut attendre
a = affich_tools.anim('\tattente du lock') a = affich_tools.anim('\tattente du lock')