# along with this program. If not, see <https://www.gnu.org/licenses/>.
import argparse
-import os
-import sys
-import tempfile
-import zc.lockfile
from fba import commands
from fba import fba
+from fba import locking
-# Lock file
-lockfile = tempfile.gettempdir() + '/fba.lock'
-LOCK = None
_PARSER = None
-def acquire_lock():
- global LOCK
- 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)
-
def init_parser():
- # DEBUG: # DEBUG: print("DEBUG: init_parser(): CALLED!")
+ # DEBUG: print("DEBUG: init_parser(): CALLED!")
global _PARSER
- # DEBUG: # DEBUG: print("DEBUG: Initializing parser ...")
+ # DEBUG: print("DEBUG: Initializing parser ...")
_PARSER = argparse.ArgumentParser(
description="Fetches block reasons from the fediverse",
epilog="Please note that some commands have optional arguments, you may want to try fba.py <command> --help to find them out.",
parser.add_argument("--single", action="store_true", help="Only fetch given instance.")
parser.set_defaults(command=commands.fetch_instances)
- # DEBUG: # DEBUG: print("DEBUG: init_parser(): EXIT!")
+ # DEBUG: print("DEBUG: init_parser(): EXIT!")
def run_command():
- # DEBUG: # DEBUG: print("DEBUG: run_command(): CALLED!")
+ # DEBUG: print("DEBUG: run_command(): CALLED!")
args = _PARSER.parse_args()
- # DEBUG: # DEBUG: print(f"DEBUG: args[{type(args)}]={args}")
+ # DEBUG: print(f"DEBUG: args[{type(args)}]={args}")
status = args.command(args)
- # DEBUG: # DEBUG: print("DEBUG: status={status} - EXIT!")
+ # DEBUG: print("DEBUG: status={status} - EXIT!")
return status if isinstance(status, int) else 0
def shutdown():
# DEBUG: print("DEBUG: Closing database connection ...")
fba.connection.close()
-
- if LOCK is not None:
- # DEBUG: print("DEBUG: Releasing lock ...")
- LOCK.close()
- # DEBUG: print(f"DEBUG: Deleting lockfile='{lockfile}' ...")
- os.remove(lockfile)
-
+ locking.release()
# DEBUG: print("DEBUG: Shutdown completed.")