X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=fba%2Fboot.py;h=d0bc4564e58bff11675ded616cc54d02fe7c5cd6;hb=88c30cbcf5f275c39bee5426443dd5b30c51281a;hp=8f962fc05e707505d32672f75c354b83fe6e4129;hpb=ad0e8ee96f0dd23c04e491b01a23000b63cab854;p=fba.git diff --git a/fba/boot.py b/fba/boot.py index 8f962fc..d0bc456 100644 --- a/fba/boot.py +++ b/fba/boot.py @@ -14,17 +14,21 @@ # You should have received a copy of the GNU Affero General Public License # 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 # Lock file lockfile = tempfile.gettempdir() + '/fba.lock' LOCK = None +_PARSER = None -def lock_process(): +def acquire_lock(): global LOCK try: print(f"DEBUG: Acquiring lock: '{lockfile}'") @@ -35,11 +39,101 @@ def lock_process(): print(f"ERROR: Cannot aquire lock: '{lockfile}'") sys.exit(100) +def init_parser(): + # DEBUG: print("DEBUG: init_parser(): CALLED!") + global _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.", + ) + subparser_command = _PARSER.add_subparsers( + dest="command", + title="Commands to execute", + required=True, + help="Command to perform", + ) + + ### Check instance ### + parser = subparser_command.add_parser( + "check_instance", + help="Checks given instance if it exists and returns proper exit code" + ) + parser.add_argument("--domain", required=True, help="Instance name (aka. domain) to check") + parser.set_defaults(command=commands.check_instance) + + ### Fetch from bka.li ### + parser = subparser_command.add_parser( + "fetch_bkali", + help="Fetches domain names from bka.li API", + ) + parser.set_defaults(command=commands.fetch_bkali) + + ### Fetch blocks from registered instances or given ### + parser = subparser_command.add_parser( + "fetch_blocks", + help="Fetches blocks from registered instances (run command fetch_instances first!).", + ) + parser.add_argument("--domain", help="Instance name (aka. domain) to fetch blocks from") + parser.set_defaults(command=commands.fetch_blocks) + + ### Fetch blocks from chaos.social ### + parser = subparser_command.add_parser( + "fetch_cs", + help="Fetches blocks from chaos.social's meta sub domain.", + ) + parser.set_defaults(command=commands.fetch_cs) + + ### Fetch blocks from a FBA-specific RSS feed ### + parser = subparser_command.add_parser( + "fetch_fba_rss", + help="Fetches domains from a FBA-specific RSS feed.", + ) + parser.add_argument("--feed", required=True, help="RSS feed to fetch domains from (e.g. https://fba.ryoma.agency/rss?domain=foo.bar).") + parser.set_defaults(command=commands.fetch_fba_rss) + + ### Fetch blocks from FBA's bot account ### + parser = subparser_command.add_parser( + "fetch_fbabot_atom", + help="Fetches ATOM feed with domains from FBA's bot account. You may wish to re-run this command several times (at least 3 with big instances) to have a decent amount of valid instances.", + ) + parser.set_defaults(command=commands.fetch_fbabot_atom) + + ### Fetch blocks from federater ### + parser = subparser_command.add_parser( + "fetch_federater", + help="Fetches CSV file (block recommendations) for more possible instances to disover", + ) + parser.set_defaults(command=commands.fetch_federater) + + ### Fetch instances from given initial instance ### + parser = subparser_command.add_parser( + "fetch_instances", + help="Fetches instances (aka. \"domains\") from an initial instance.", + ) + parser.add_argument("--domain", required=True, help="Instance name (aka. domain) to fetch further instances from. Start with a large instance, e.g. mastodon.social .") + 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!") + +def run_command(): + # DEBUG: print("DEBUG: run_command(): CALLED!") + args = _PARSER.parse_args() + # DEBUG: print(f"DEBUG: args[{type(args)}]={args}") + status = args.command(args) + # DEBUG: print("DEBUG: status={status} - EXIT!") + return status if isinstance(status, int) else 0 + def shutdown(): print("DEBUG: Closing database connection ...") fba.connection.close() - print("DEBUG: Releasing lock ...") - LOCK.close() - print(f"DEBUG: Deleting lockfile='{lockfile}' ...") - os.remove(lockfile) + + if LOCK is not None: + print("DEBUG: Releasing lock ...") + LOCK.close() + print(f"DEBUG: Deleting lockfile='{lockfile}' ...") + os.remove(lockfile) + print("DEBUG: Shutdown completed.")