Update lock managet app

Add keyword arguments. Sort imports. Move settings and test
literals to their own module.

Signed-off-by: Roberto Rosario <Roberto.Rosario@mayan-edms.com>
This commit is contained in:
Roberto Rosario
2019-01-21 02:50:34 -04:00
parent 027a853885
commit 09edab5027
11 changed files with 43 additions and 28 deletions

View File

@@ -1,8 +1,8 @@
from __future__ import unicode_literals
import hashlib
import logging
import json
import logging
import os
import threading
import time
@@ -23,7 +23,9 @@ lock = threading.Lock()
logger = logging.getLogger(__name__)
lock_file = os.path.join(
setting_temporary_directory.value, hashlib.sha256(force_bytes(settings.SECRET_KEY)).hexdigest()
setting_temporary_directory.value, hashlib.sha256(
force_bytes(settings.SECRET_KEY)
).hexdigest()
)
open(lock_file, 'a').close()
logger.debug('lock_file: %s', lock_file)
@@ -76,7 +78,7 @@ class FileLock(LockingBackend):
data = file_object.read()
if data:
file_locks = json.loads(data)
file_locks = json.loads(s=data)
else:
file_locks = {}
@@ -103,7 +105,7 @@ class FileLock(LockingBackend):
with open(self.__class__.lock_file, 'r+') as file_object:
locks.lock(f=file_object, flags=locks.LOCK_EX)
try:
file_locks = json.loads(file_object.read())
file_locks = json.loads(s=file_object.read())
except EOFError:
file_locks = {}