X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=fba%2Fboot.py;h=cb3ccc9420227201df03f40d26ac5c9758c57f8b;hb=c8b6b6a4aea21b3fefc8fd4900391d59751ff814;hp=91c2880d59f595f96c9696c13fdee36cc391ee01;hpb=861fcd135469a35b848b1d026ec9bd317f34aeb4;p=fba.git diff --git a/fba/boot.py b/fba/boot.py index 91c2880..cb3ccc9 100644 --- a/fba/boot.py +++ b/fba/boot.py @@ -15,35 +15,18 @@ # along with this program. If not, see . 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 --help to find them out.", @@ -116,24 +99,18 @@ def init_parser(): 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.")