From 448c39dd6d6f85d88d749ca501f88c694959a3ed Mon Sep 17 00:00:00 2001 From: bernat Date: Wed, 9 Mar 2005 22:39:11 +0100 Subject: [PATCH] Detabification darcs-hash:20050309213911-d1718-9178fb47bfab689495a2d2ac5756f21b94ada951.gz --- gestion/lock.py | 94 ++++++++++++++++++++++++------------------------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/gestion/lock.py b/gestion/lock.py index 6d02a002..52235e5c 100755 --- a/gestion/lock.py +++ b/gestion/lock.py @@ -69,42 +69,42 @@ def make_lock(lock_name, lock_comment='',nowait=0, quiet=False) : return make_lock(lock_name, lock_comment) if os.path.isfile(lock_file) : - ### Lock existant - - # Lecture du lock - fd = open(lock_file, "r") - pid= fd.readline().strip() - user = fd.readline().strip() - fd.close() - - # Informations sur le processus lockant - if os.system( "ps ax | grep -q '^%s '" % pid ) : - # Le script lockant ne tourne plus - os.remove(lock_file) - elif nowait : + ### Lock existant + + # Lecture du lock + fd = open(lock_file, "r") + pid= fd.readline().strip() + user = fd.readline().strip() + fd.close() + + # Informations sur le processus lockant + if os.system( "ps ax | grep -q '^%s '" % pid ) : + # Le script lockant ne tourne plus + os.remove(lock_file) + elif nowait : if not quiet: sys.stderr.write('Lock : %s\n' % lock_file) - l=getoutput("ps -ax -o pid,etime | awk '($1 == %s)'" % pid) - data = [ user , pid , l.strip() ] - - # 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 = '???' + l=getoutput("ps -ax -o pid,etime | awk '($1 == %s)'" % pid) + data = [ user , pid , l.strip() ] + + # 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 + data[-1]=txt if not quiet: sys.stderr.write('\tpropriétaire : %s\n\tpid : %s\n\tdémarré depuis %s\n' % tuple(data) ) @@ -112,15 +112,15 @@ def make_lock(lock_name, lock_comment='',nowait=0, quiet=False) : else: # On va plutot lever une exception raise AssertionError(tuple(data)) - else : - # Il faut attendre - a = affich_tools.anim('\tattente du lock') - for i in range(8) : - time.sleep(1) - a.cycle() - sys.stdout.write('\r') - return make_lock(lock_name, lock_comment) - + else : + # Il faut attendre + a = affich_tools.anim('\tattente du lock') + for i in range(8) : + time.sleep(1) + a.cycle() + sys.stdout.write('\r') + return make_lock(lock_name, lock_comment) + ### Prise du lock lock_fd = file(lock_file,"w") try: @@ -140,9 +140,9 @@ def remove_lock( lock_name ) : lock_dir = '/var/lock/gestion' lock_file = "%s/%s" % (lock_dir, lock_name) try : - fd = open(lock_file, "r") - if fd.readline().strip()=="%s" % os.getpid(): - os.remove(lock_file) - fd.close() + fd = open(lock_file, "r") + if fd.readline().strip()=="%s" % os.getpid(): + os.remove(lock_file) + fd.close() except : - pass + pass