On attend plus le lock : on rale et on quitte.
darcs-hash:20040915210652-41617-1e2ab9b10f7fa5773d84c7ac52958c0398e86236.gz
This commit is contained in:
parent
7c697abdcf
commit
cd174ee0d8
2 changed files with 32 additions and 3 deletions
|
@ -8,9 +8,12 @@ Licence : GPLv2
|
|||
"""
|
||||
|
||||
import os,string,time,sys, affich_tools
|
||||
from commands import getoutput
|
||||
|
||||
def make_lock(lock_name, lock_comment='') :
|
||||
""" Création d'un lock """
|
||||
def make_lock(lock_name, lock_comment='',nowait=1) :
|
||||
""" Création d'un lock
|
||||
si nowait=0 fait un sys.exit(254) quand un ancien lock actif est rencontré
|
||||
"""
|
||||
lock_file = '/var/lock/' + lock_name
|
||||
if os.path.isfile(lock_file) :
|
||||
### Lock existant
|
||||
|
@ -24,6 +27,32 @@ def make_lock(lock_name, lock_comment='') :
|
|||
if os.system( "ps %s > /dev/null 2>&1" % pid ) :
|
||||
# Le script lockant ne tourne plus
|
||||
os.remove(lock_file)
|
||||
elif nowait :
|
||||
sys.stderr.write('Lock : %s\n' % lock_file)
|
||||
l=getoutput('ps -o user,pid,etime --no-headers %s' % pid)
|
||||
data = l.split()
|
||||
|
||||
# Formatate de etime
|
||||
s = data[-1].split('-')
|
||||
if len(s)==2 :
|
||||
txt = '%s jour(s) ' % s[0]
|
||||
s=s[1]
|
||||
else :
|
||||
txt = ''
|
||||
s=s[0]
|
||||
|
||||
s = s.split(':')
|
||||
if len(s) == 3 :
|
||||
txt = '%sh%smin%ss' % tuple(s)
|
||||
elif len(s) == 2 :
|
||||
txt = '%smin%ss' % tuple(s)
|
||||
else :
|
||||
txt = '???'
|
||||
|
||||
data[-1]=txt
|
||||
|
||||
sys.stderr.write('\tpropriétaire : %s\n\tpid : %s\n\tdémarré depuis %s\n' % tuple(data) )
|
||||
sys.exit(254)
|
||||
else :
|
||||
# Il faut attendre
|
||||
a = affich_tools.anim('\tattente du lock')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue