import re
import reqto
import json
+import os
import sqlite3
import sys
+import tempfile
import time
import validators
+import zc.lockfile
with open("config.json") as f:
config = json.loads(f.read())
re.compile("^[a-f0-9]{7}$"),
]
+# Lock file
+lockfile = tempfile.gettempdir() + '/.' + __name__ + '.lock'
+LOCK = None
+
##### Cache #####
def is_cache_initialized(key: str) -> bool:
string = re.sub("(.+)\@", "", string)
return string
+
+def lock_process():
+ global LOCK
+ try:
+ print(f"DEBUG: Acquiring lock: '{lockfile}'")
+ LOCK = zc.lockfile.LockFile(lockfile)
+ print("DEBUG: Lock obtained.")
+
+ except zc.lockfile.LockError:
+ print(f"ERROR: Cannot aquire lock: '{lockfile}'")
+ sys.exit(100)
+
+def shutdown():
+ print("DEBUG: Closing database connection ...")
+ connection.close()
+ print("DEBUG: Releasing lock ...")
+ LOCK.close()
+ print(f"DEBUG: Deleting lockfile='{lockfile}' ...")
+ os.remove(lockfile)
+ print("DEBUG: Shutdown completed.")