diff --git a/gestion/gen_confs/generate.py b/gestion/gen_confs/generate.py index fe254325..e9a0a49a 100755 --- a/gestion/gen_confs/generate.py +++ b/gestion/gen_confs/generate.py @@ -19,7 +19,7 @@ if os.getuid() != 0: signal.signal(signal.SIGINT,signal.SIG_IGN) # Pas de Ctrl-C db = crans_ldap() -make_lock('auto_generate') +make_lock('auto_generate',0) ##### Options fournies ? try : diff --git a/gestion/lock.py b/gestion/lock.py index 93dc2806..2b532653 100755 --- a/gestion/lock.py +++ b/gestion/lock.py @@ -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')