From 3ecc6a4234aea84798583e66560957326ea23d21 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 6 Jun 2023 11:35:11 +0200 Subject: [PATCH] Continued: - `inspect.currentframe().f_code.co_name` is one LARGE way for finding out current function's name but it does not involve any private functions being called publicly - still PHP has __FUNCTION__ for this purpose ... --- fba/commands.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/fba/commands.py b/fba/commands.py index 852b522..74871ec 100644 --- a/fba/commands.py +++ b/fba/commands.py @@ -17,6 +17,7 @@ import argparse import atoma import bs4 +import inspect import itertools import json import re @@ -92,7 +93,7 @@ def fetch_bkali(args: argparse.Namespace): print(f"INFO: Adding {len(domains)} new instances ...") for domain in domains: print(f"INFO: Fetching instances from domain='{domain}' ...") - fba.fetch_instances(domain, None, None, __name__) + fba.fetch_instances(domain, None, None, inspect.currentframe().f_code.co_name) # DEBUG: print("DEBUG: EXIT!") @@ -212,7 +213,7 @@ def fetch_blocks(args: argparse.Namespace): continue elif not fba.is_instance_registered(blocked): # DEBUG: print(f"DEBUG: Domain blocked='{blocked}' wasn't found, adding ..., blocker='{blocker}',origin='{origin}',nodeinfo_url='{nodeinfo_url}'") - fba.add_instance(blocked, blocker, __name__, nodeinfo_url) + fba.add_instance(blocked, blocker, inspect.currentframe().f_code.co_name, nodeinfo_url) if not fba.is_instance_blocked(blocker, blocked, block_level): # DEBUG: print("DEBUG: Blocking:", blocker, blocked, block_level) @@ -285,7 +286,7 @@ def fetch_blocks(args: argparse.Namespace): continue elif not fba.is_instance_registered(blocked): # DEBUG: print(f"DEBUG: Domain blocked='{blocked}' wasn't found, adding ..., blocker='{blocker}',origin='{origin}',nodeinfo_url='{nodeinfo_url}'") - fba.add_instance(blocked, blocker, __name__, nodeinfo_url) + fba.add_instance(blocked, blocker, inspect.currentframe().f_code.co_name, nodeinfo_url) # DEBUG: print("DEBUG: Updating block reason:", blocker, blocked, reason["reason"]) fba.update_block_reason(reason["reason"], blocker, blocked, block_level) @@ -398,7 +399,7 @@ def fetch_blocks(args: argparse.Namespace): continue elif not fba.is_instance_registered(blocked): # DEBUG: print(f"DEBUG: Domain blocked='{blocked}' wasn't found, adding ..., blocker='{blocker}',origin='{origin}',nodeinfo_url='{nodeinfo_url}'") - fba.add_instance(blocked, blocker, __name__, nodeinfo_url) + fba.add_instance(blocked, blocker, inspect.currentframe().f_code.co_name, nodeinfo_url) elif not validators.domain(blocked): print(f"WARNING: blocked='{blocked}',software='{software}' is not a valid domain name - skipped!") continue @@ -409,7 +410,7 @@ def fetch_blocks(args: argparse.Namespace): continue elif not fba.is_instance_registered(blocked): # DEBUG: print("DEBUG: Hash wasn't found, adding:", blocked, blocker) - fba.add_instance(blocked, blocker, __name__, nodeinfo_url) + fba.add_instance(blocked, blocker, inspect.currentframe().f_code.co_name, nodeinfo_url) blocking = blocked if blocked.count("*") <= 1 else blocked_hash # DEBUG: print(f"DEBUG: blocking='{blocking}',blocked='{blocked}',blocked_hash='{blocked_hash}'") @@ -510,7 +511,7 @@ def fetch_blocks(args: argparse.Namespace): continue elif not fba.is_instance_registered(blocked): # DEBUG: print("DEBUG: Hash wasn't found, adding:", blocked, blocker) - fba.add_instance(blocked, blocker, __name__, nodeinfo_url) + fba.add_instance(blocked, blocker, inspect.currentframe().f_code.co_name, nodeinfo_url) if not fba.is_instance_blocked(blocker, blocked, block_level): fba.block_instance(blocker, blocked, reason, block_level) @@ -577,7 +578,7 @@ def fetch_blocks(args: argparse.Namespace): continue elif not fba.is_instance_registered(blocked): # DEBUG: print(f"DEBUG: Domain blocked='{blocked}' wasn't found, adding ..., blocker='{blocker}',origin='{origin}',nodeinfo_url='{nodeinfo_url}'") - fba.add_instance(blocked, blocker, __name__, nodeinfo_url) + fba.add_instance(blocked, blocker, inspect.currentframe().f_code.co_name, nodeinfo_url) if not fba.is_instance_blocked(blocker, blocked, "reject"): # DEBUG: print(f"DEBUG: blocker='{blocker}' is blocking '{blocked}' for unknown reason at this point") @@ -652,7 +653,7 @@ def fetch_cs(args: argparse.Namespace): # DEBUG: print(f"DEBUG: row='{row}'") if not fba.is_instance_registered(row["domain"]): print(f"INFO: Fetching instances from domain='{row['domain']}' ...") - fba.fetch_instances(row["domain"], None, None, __name__) + fba.fetch_instances(row["domain"], None, None, inspect.currentframe().f_code.co_name) if not fba.is_instance_blocked('chaos.social', row["domain"], block_level): # DEBUG: print(f"DEBUG: domain='{row['domain']}',block_level='{block_level}' blocked by chaos.social, adding ...") @@ -705,7 +706,7 @@ def fetch_fba_rss(args: argparse.Namespace): print(f"INFO: Adding {len(domains)} new instances ...") for domain in domains: print(f"INFO: Fetching instances from domain='{domain}' ...") - fba.fetch_instances(domain, None, None, __name__) + fba.fetch_instances(domain, None, None, inspect.currentframe().f_code.co_name) # DEBUG: print("DEBUG: EXIT!") @@ -758,7 +759,7 @@ def fetch_fbabot_atom(args: argparse.Namespace): print(f"INFO: Adding {len(domains)} new instances ...") for domain in domains: print(f"INFO: Fetching instances from domain='{domain}' ...") - fba.fetch_instances(domain, None, None, __name__) + fba.fetch_instances(domain, None, None, inspect.currentframe().f_code.co_name) # DEBUG: print("DEBUG: EXIT!") @@ -767,7 +768,7 @@ def fetch_instances(args: argparse.Namespace): boot.acquire_lock() # Initial fetch - fba.fetch_instances(args.domain, None, None, __name__) + fba.fetch_instances(args.domain, None, None, inspect.currentframe().f_code.co_name) if args.single: # DEBUG: print(f"DEBUG: Not fetching more instances - EXIT!") @@ -787,6 +788,6 @@ def fetch_instances(args: argparse.Namespace): continue print(f"INFO: Fetching instances for instance '{row[0]}' ('{row[2]}') of origin='{row[1]}',nodeinfo_url='{row[3]}'") - fba.fetch_instances(row[0], row[1], row[2], __name__, row[3]) + fba.fetch_instances(row[0], row[1], row[2], inspect.currentframe().f_code.co_name, row[3]) # DEBUG: print("DEBUG: EXIT!") -- 2.39.5