]> git.mxchange.org Git - fba.git/blob - fba/boot.py
Continued:
[fba.git] / fba / boot.py
1 # Fedi API Block - An aggregator for fetching blocking data from fediverse nodes
2 # Copyright (C) 2023 Free Software Foundation
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Affero General Public License as published
6 # by the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU Affero General Public License for more details.
13 #
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
16
17 import argparse
18
19 from fba import commands
20 from fba import fba
21
22 from fba.helpers import locking
23
24 _PARSER = None
25
26 def init_parser():
27     # DEBUG: print("DEBUG: init_parser(): CALLED!")
28     global _PARSER
29
30     # DEBUG: print("DEBUG: Initializing parser ...")
31     _PARSER = argparse.ArgumentParser(
32         description="Fetches block reasons from the fediverse",
33         epilog="Please note that some commands have optional arguments, you may want to try fba.py <command> --help to find them out.",
34     )
35     subparser_command = _PARSER.add_subparsers(
36         dest="command",
37         title="Commands to execute",
38         required=True,
39         help="Command to perform",
40     )
41
42     ### Check instance ###
43     parser = subparser_command.add_parser(
44         "check_instance",
45         help="Checks given instance if it exists and returns proper exit code"
46     )
47     parser.add_argument("--domain", required=True, help="Instance name (aka. domain) to check")
48     parser.set_defaults(command=commands.check_instance)
49
50     ### Fetch from bka.li ###
51     parser = subparser_command.add_parser(
52         "fetch_bkali",
53         help="Fetches domain names from bka.li API",
54     )
55     parser.set_defaults(command=commands.fetch_bkali)
56
57     ### Fetch blocks from registered instances or given ###
58     parser = subparser_command.add_parser(
59         "fetch_blocks",
60         help="Fetches blocks from registered instances (run command fetch_instances first!).",
61     )
62     parser.add_argument("--domain", help="Instance name (aka. domain) to fetch blocks from")
63     parser.set_defaults(command=commands.fetch_blocks)
64
65     ### Fetch blocks from chaos.social ###
66     parser = subparser_command.add_parser(
67         "fetch_cs",
68         help="Fetches blocks from chaos.social's meta sub domain.",
69     )
70     parser.set_defaults(command=commands.fetch_cs)
71
72     ### Fetch blocks from a FBA-specific RSS feed  ###
73     parser = subparser_command.add_parser(
74         "fetch_fba_rss",
75         help="Fetches domains from a FBA-specific RSS feed.",
76     )
77     parser.add_argument("--feed", required=True, help="RSS feed to fetch domains from (e.g. https://fba.ryoma.agency/rss?domain=foo.bar).")
78     parser.set_defaults(command=commands.fetch_fba_rss)
79
80     ### Fetch blocks from FBA's bot account ###
81     parser = subparser_command.add_parser(
82         "fetch_fbabot_atom",
83         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.",
84     )
85     parser.set_defaults(command=commands.fetch_fbabot_atom)
86
87     ### Fetch blocks from oliphant's GIT repository ###
88     parser = subparser_command.add_parser(
89         "fetch_oliphant",
90         help="Fetches CSV files (block recommendations) for more possible instances to disover",
91     )
92     parser.add_argument("--domain", help="Instance name (aka. domain) to check")
93     parser.set_defaults(command=commands.fetch_oliphant)
94
95     ### Fetch instances from given initial instance ###
96     parser = subparser_command.add_parser(
97         "fetch_instances",
98         help="Fetches instances (aka. \"domains\") from an initial instance.",
99     )
100     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 .")
101     parser.add_argument("--single", action="store_true", help="Only fetch given instance.")
102     parser.set_defaults(command=commands.fetch_instances)
103
104     ### Fetch blocks from static text file(s) ###
105     parser = subparser_command.add_parser(
106         "fetch_txt",
107         help="Fetches text/plain files as simple domain lists",
108     )
109     parser.set_defaults(command=commands.fetch_txt)
110
111     # DEBUG: print("DEBUG: init_parser(): EXIT!")
112
113 def run_command():
114     # DEBUG: print("DEBUG: run_command(): CALLED!")
115     args = _PARSER.parse_args()
116     # DEBUG: print(f"DEBUG: args[{type(args)}]={args}")
117     status = args.command(args)
118     # DEBUG: print("DEBUG: status={status} - EXIT!")
119     return status if isinstance(status, int) else 0
120
121 def shutdown():
122     # DEBUG: print("DEBUG: Closing database connection ...")
123     fba.connection.close()
124     locking.release()
125     # DEBUG: print("DEBUG: Shutdown completed.")