Import initial !

darcs-hash:20040831131446-d1718-0734aa73d3b8481b3b4b861e447e85128e488e8a.gz
This commit is contained in:
bernat 2004-08-31 15:14:46 +02:00
parent c9083dfd86
commit 6626a44f15
20 changed files with 6494 additions and 0 deletions

50
gestion/lock.py Executable file
View file

@ -0,0 +1,50 @@
#!/usr/bin/env python
# -*- coding: iso-8859-15 -*-
""" Gestion de lock
Copyright (C) Frédéric Pauget
Licence : GPLv2
"""
import os,string,time,sys,pwd, affich_tools
def make_lock(lock_name, lock_comment='') :
""" Création d'un lock """
lock_file = '/var/lock/' + lock_name
if os.path.isfile(lock_file) :
### Lock existant
# Lecture du lock
fd = open(lock_file, "r")
pid= fd.readline().strip()
fd.close()
# Informations sur le processus lockant
if os.system( "ps %s > /dev/null 2>&1" % pid ) :
# Le script lockant ne tourne plus
os.remove(lock_file)
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=open(lock_file, "w")
lock_fd.write("%s\n%s\n%s" % (os.getpid(), pwd.getpwuid(os.getuid())[0], lock_comment) )
lock_fd.close()
def remove_lock( lock_name ) :
""" Destruction du lock """
lock_file = '/var/lock/' + lock_name
try :
fd = open(lock_file, "r")
if fd.readline().strip()=="%s" % os.getpid():
os.remove(lock_file)
fd.close()
except :
None