From: Roland Häder Date: Mon, 12 Jun 2023 23:25:57 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=8a7f65b64649d35128e63696505db12879583dfc;p=fba.git Continued: - moved fba.locking to fba.helpers --- diff --git a/fba/__init__.py b/fba/__init__.py index ceb63ed..d22410d 100644 --- a/fba/__init__.py +++ b/fba/__init__.py @@ -22,7 +22,6 @@ __all__ = [ 'federation', 'fba', 'helpers', - 'locking', 'model', 'network', 'networks', diff --git a/fba/boot.py b/fba/boot.py index a602e3d..1ed06ef 100644 --- a/fba/boot.py +++ b/fba/boot.py @@ -18,7 +18,8 @@ import argparse from fba import commands from fba import fba -from fba import locking + +from fba.helpers import locking _PARSER = None diff --git a/fba/commands.py b/fba/commands.py index ad5b7ca..63c185f 100644 --- a/fba/commands.py +++ b/fba/commands.py @@ -30,9 +30,9 @@ from fba import blacklist from fba import config from fba import federation from fba import fba -from fba import locking from fba import network +from fba.helpers import locking from fba.helpers import tidyup from fba.models import blocks diff --git a/fba/helpers/__init__.py b/fba/helpers/__init__.py index 3e811e9..b6b121a 100644 --- a/fba/helpers/__init__.py +++ b/fba/helpers/__init__.py @@ -16,6 +16,7 @@ __all__ = [ 'cache', 'dicts', + 'locking', 'tidyup', 'version', ] diff --git a/fba/helpers/locking.py b/fba/helpers/locking.py new file mode 100644 index 0000000..27f5eac --- /dev/null +++ b/fba/helpers/locking.py @@ -0,0 +1,49 @@ +# Fedi API Block - An aggregator for fetching blocking data from fediverse nodes +# Copyright (C) 2023 Free Software Foundation +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +import os +import sys +import tempfile +import zc.lockfile + +# Lock file +lockfile = tempfile.gettempdir() + '/fba.lock' +LOCK = None + +def acquire(): + global LOCK + # DEBUG: print("DEBUG: CALLED!") + + try: + # DEBUG: print(f"DEBUG: Acquiring lock: '{lockfile}'") + LOCK = zc.lockfile.LockFile(lockfile) + # DEBUG: print("DEBUG: Lock obtained.") + + except zc.lockfile.LockError: + print(f"ERROR: Cannot aquire lock: '{lockfile}'") + sys.exit(100) + + # DEBUG: print("DEBUG: EXIT!") + +def release(): + # DEBUG: print("DEBUG: CALLED!") + if LOCK is not None: + # DEBUG: print("DEBUG: Releasing lock ...") + LOCK.close() + # DEBUG: print(f"DEBUG: Deleting lockfile='{lockfile}' ...") + os.remove(lockfile) + + # DEBUG: print("DEBUG: EXIT!") diff --git a/fba/locking.py b/fba/locking.py deleted file mode 100644 index 27f5eac..0000000 --- a/fba/locking.py +++ /dev/null @@ -1,49 +0,0 @@ -# Fedi API Block - An aggregator for fetching blocking data from fediverse nodes -# Copyright (C) 2023 Free Software Foundation -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . - -import os -import sys -import tempfile -import zc.lockfile - -# Lock file -lockfile = tempfile.gettempdir() + '/fba.lock' -LOCK = None - -def acquire(): - global LOCK - # DEBUG: print("DEBUG: CALLED!") - - try: - # DEBUG: print(f"DEBUG: Acquiring lock: '{lockfile}'") - LOCK = zc.lockfile.LockFile(lockfile) - # DEBUG: print("DEBUG: Lock obtained.") - - except zc.lockfile.LockError: - print(f"ERROR: Cannot aquire lock: '{lockfile}'") - sys.exit(100) - - # DEBUG: print("DEBUG: EXIT!") - -def release(): - # DEBUG: print("DEBUG: CALLED!") - if LOCK is not None: - # DEBUG: print("DEBUG: Releasing lock ...") - LOCK.close() - # DEBUG: print(f"DEBUG: Deleting lockfile='{lockfile}' ...") - os.remove(lockfile) - - # DEBUG: print("DEBUG: EXIT!")