timplement basic lockfile functions - amprolla - devuan's apt repo merger
git clone git://parazyd.org/amprolla.git
Log
Files
Refs
README
LICENSE
---
commit 32b7d87eeed5748306269f5eb1eaaf55e06bba3c
parent 953ab66e71806db1133f98badf2ce44bd787260a
Author: parazyd 
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(-)
---
diff --git a/lib/lock.py b/lib/lock.py
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')