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)
|
||||
|
||||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue