Detabification
darcs-hash:20050309213911-d1718-9178fb47bfab689495a2d2ac5756f21b94ada951.gz
This commit is contained in:
parent
abb6d25e47
commit
448c39dd6d
1 changed files with 47 additions and 47 deletions
|
@ -69,42 +69,42 @@ def make_lock(lock_name, lock_comment='',nowait=0, quiet=False) :
|
||||||
return make_lock(lock_name, lock_comment)
|
return make_lock(lock_name, lock_comment)
|
||||||
|
|
||||||
if os.path.isfile(lock_file) :
|
if os.path.isfile(lock_file) :
|
||||||
### Lock existant
|
### Lock existant
|
||||||
|
|
||||||
# Lecture du lock
|
# Lecture du lock
|
||||||
fd = open(lock_file, "r")
|
fd = open(lock_file, "r")
|
||||||
pid= fd.readline().strip()
|
pid= fd.readline().strip()
|
||||||
user = fd.readline().strip()
|
user = fd.readline().strip()
|
||||||
fd.close()
|
fd.close()
|
||||||
|
|
||||||
# Informations sur le processus lockant
|
# Informations sur le processus lockant
|
||||||
if os.system( "ps ax | grep -q '^%s '" % pid ) :
|
if os.system( "ps ax | grep -q '^%s '" % pid ) :
|
||||||
# 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:
|
if not quiet:
|
||||||
sys.stderr.write('Lock : %s\n' % lock_file)
|
sys.stderr.write('Lock : %s\n' % lock_file)
|
||||||
l=getoutput("ps -ax -o pid,etime | awk '($1 == %s)'" % pid)
|
l=getoutput("ps -ax -o pid,etime | awk '($1 == %s)'" % pid)
|
||||||
data = [ user , pid , l.strip() ]
|
data = [ user , pid , l.strip() ]
|
||||||
|
|
||||||
# Formatate de etime
|
# Formatate de etime
|
||||||
s = data[-1].split('-')
|
s = data[-1].split('-')
|
||||||
if len(s)==2 :
|
if len(s)==2 :
|
||||||
txt = '%s jour(s) ' % s[0]
|
txt = '%s jour(s) ' % s[0]
|
||||||
s=s[1]
|
s=s[1]
|
||||||
else :
|
else :
|
||||||
txt = ''
|
txt = ''
|
||||||
s=s[0]
|
s=s[0]
|
||||||
|
|
||||||
s = s.split(':')
|
s = s.split(':')
|
||||||
if len(s) == 3 :
|
if len(s) == 3 :
|
||||||
txt = '%sh%smin%ss' % tuple(s)
|
txt = '%sh%smin%ss' % tuple(s)
|
||||||
elif len(s) == 2 :
|
elif len(s) == 2 :
|
||||||
txt = '%smin%ss' % tuple(s)
|
txt = '%smin%ss' % tuple(s)
|
||||||
else :
|
else :
|
||||||
txt = '???'
|
txt = '???'
|
||||||
|
|
||||||
data[-1]=txt
|
data[-1]=txt
|
||||||
|
|
||||||
if not quiet:
|
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) )
|
||||||
|
@ -112,14 +112,14 @@ def make_lock(lock_name, lock_comment='',nowait=0, quiet=False) :
|
||||||
else:
|
else:
|
||||||
# On va plutot lever une exception
|
# On va plutot lever une exception
|
||||||
raise AssertionError(tuple(data))
|
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')
|
||||||
for i in range(8) :
|
for i in range(8) :
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
a.cycle()
|
a.cycle()
|
||||||
sys.stdout.write('\r')
|
sys.stdout.write('\r')
|
||||||
return make_lock(lock_name, lock_comment)
|
return make_lock(lock_name, lock_comment)
|
||||||
|
|
||||||
### Prise du lock
|
### Prise du lock
|
||||||
lock_fd = file(lock_file,"w")
|
lock_fd = file(lock_file,"w")
|
||||||
|
@ -140,9 +140,9 @@ def remove_lock( lock_name ) :
|
||||||
lock_dir = '/var/lock/gestion'
|
lock_dir = '/var/lock/gestion'
|
||||||
lock_file = "%s/%s" % (lock_dir, lock_name)
|
lock_file = "%s/%s" % (lock_dir, lock_name)
|
||||||
try :
|
try :
|
||||||
fd = open(lock_file, "r")
|
fd = open(lock_file, "r")
|
||||||
if fd.readline().strip()=="%s" % os.getpid():
|
if fd.readline().strip()=="%s" % os.getpid():
|
||||||
os.remove(lock_file)
|
os.remove(lock_file)
|
||||||
fd.close()
|
fd.close()
|
||||||
except :
|
except :
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue