lock.py (607B)
1 # See LICENSE file for copyright and license details. 2 3 """ 4 Lockfile functions 5 """ 6 7 from time import time 8 from os import remove 9 from os.path import isfile 10 import sys 11 12 from lib.config import lockpath 13 from lib.log import info 14 15 16 def check_lock(): 17 """ 18 Checks if a lockfile is active, and creates one if not. 19 """ 20 if isfile(lockpath): 21 info('Lockfile found. Defering operation.') 22 sys.exit(1) 23 24 with open(lockpath, 'w') as lock: 25 lock.write(str(int(time()))) 26 27 28 def free_lock(): 29 """ 30 Frees an active lockfile. 31 """ 32 if isfile(lockpath): 33 remove(lockpath)