[damned-lies] Use pathlib.Path for LOCK_DIR
- From: Claude Paroz <claudep src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies] Use pathlib.Path for LOCK_DIR
- Date: Wed, 17 Mar 2021 20:43:24 +0000 (UTC)
commit 5a5c7e22c20cd7255d5370f249f6f39a604b43dc
Author: Claude Paroz <claude 2xlibre net>
Date: Wed Mar 17 21:41:23 2021 +0100
Use pathlib.Path for LOCK_DIR
damnedlies/settings.py | 2 +-
stats/models.py | 12 ++++++------
2 files changed, 7 insertions(+), 7 deletions(-)
---
diff --git a/damnedlies/settings.py b/damnedlies/settings.py
index d0e56263..88210d0f 100644
--- a/damnedlies/settings.py
+++ b/damnedlies/settings.py
@@ -182,7 +182,7 @@ GETTEXT_ITS_DATA = {
GITLAB_TOKEN = 'fill_with_real_token'
-LOCK_DIR = '/var/lock'
+LOCK_DIR = Path('/var/lock')
try:
from .local_settings import *
diff --git a/stats/models.py b/stats/models.py
index 0a119d8c..fb27f1f4 100644
--- a/stats/models.py
+++ b/stats/models.py
@@ -186,27 +186,27 @@ class ModuleLock:
def __init__(self, mod):
assert isinstance(mod, Module)
self.module = mod
- self.dirpath = os.path.join(settings.LOCK_DIR, "updating-%s" % self.module.name)
+ self.dirpath = settings.LOCK_DIR / f"updating-{self.module.name}"
def __enter__(self):
while True:
try:
- os.mkdir(self.dirpath)
+ self.dirpath.mkdir()
break
except FileExistsError:
- if (datetime.now() - datetime.fromtimestamp(os.path.getctime(self.dirpath))).days > 1:
+ if (datetime.now() - datetime.fromtimestamp(self.dirpath.stat().st_ctime)).days > 1:
# After more than one day, something was blocked, force release the lock.
- os.rmdir(self.dirpath)
+ self.dirpath.rmdir()
else:
# Something is happening on the module, let's wait.
sleep(10)
def __exit__(self, *exc_info):
- os.rmdir(self.dirpath)
+ self.dirpath.rmdir()
@property
def is_locked(self):
- return os.path.exists(self.dirpath)
+ return self.dirpath.exists()
@total_ordering
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]