import sys
import tempfile
import zc.lockfile
+
from fba import commands
from fba import fba
def acquire_lock():
global LOCK
try:
- print(f"DEBUG: Acquiring lock: '{lockfile}'")
+ # DEBUG: print(f"DEBUG: Acquiring lock: '{lockfile}'")
LOCK = zc.lockfile.LockFile(lockfile)
- print("DEBUG: Lock obtained.")
+ # DEBUG: print("DEBUG: Lock obtained.")
except zc.lockfile.LockError:
print(f"ERROR: Cannot aquire lock: '{lockfile}'")
sys.exit(100)
def init_parser():
- # DEBUG: print("DEBUG: init_parser(): CALLED!")
+ # DEBUG: # DEBUG: print("DEBUG: init_parser(): CALLED!")
global _PARSER
- # DEBUG: print("DEBUG: Initializing parser ...")
+ # DEBUG: # 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: print("DEBUG: init_parser(): EXIT!")
+ # DEBUG: # DEBUG: print("DEBUG: init_parser(): EXIT!")
def run_command():
- # DEBUG: print("DEBUG: run_command(): CALLED!")
+ # DEBUG: # DEBUG: print("DEBUG: run_command(): CALLED!")
args = _PARSER.parse_args()
- # DEBUG: print(f"DEBUG: args[{type(args)}]={args}")
+ # DEBUG: # DEBUG: print(f"DEBUG: args[{type(args)}]={args}")
status = args.command(args)
- # DEBUG: print("DEBUG: status={status} - EXIT!")
- return status if type(status) == int else 0
+ # DEBUG: # DEBUG: print("DEBUG: status={status} - EXIT!")
+ return status if isinstance(status, int) else 0
def shutdown():
- print("DEBUG: Closing database connection ...")
+ # DEBUG: print("DEBUG: Closing database connection ...")
fba.connection.close()
- if LOCK != None:
- print("DEBUG: Releasing lock ...")
+ if LOCK is not None:
+ # DEBUG: print("DEBUG: Releasing lock ...")
LOCK.close()
- print(f"DEBUG: Deleting lockfile='{lockfile}' ...")
+ # DEBUG: print(f"DEBUG: Deleting lockfile='{lockfile}' ...")
os.remove(lockfile)
- print("DEBUG: Shutdown completed.")
+ # DEBUG: print("DEBUG: Shutdown completed.")