| Date: Mon, 6 Nov 2017 13:45:04 +0100
implement basic lockfile functions
Diffstat:
A lib/lock.py | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+), 0 deletions(-)
--- |
| t@@ -0,0 +1,30 @@
+# See LICENSE file for copyright and license details.
+
+"""
+Lockfile functions
+"""
+
+from time import time
+from os import remove
+from os.path import isfile
+import sys
+
+from lib.log import info
+
+def check_lock():
+ """
+ Checks if a lockfile is active, and creates one if not.
+ """
+ if isfile('/tmp/amprolla.lock'):
+ info('Lockfile found. Defering operation.')
+ sys.exit(1)
+
+ with open('/tmp/amprolla.lock', 'w') as lock:
+ lock.write(int(time()))
+
+
+def free_lock():
+ """
+ Frees an active lockfile.
+ """
+ remove('/tmp/amprolla.lock') |