]> git.mxchange.org Git - fba.git/blobdiff - fba/commands.py
Continued:
[fba.git] / fba / commands.py
index f24a8888bea5f3857bbb79f89f5391029b677bec..ef8ee42f8251967d773f651750836b7510429cf3 100644 (file)
@@ -148,7 +148,7 @@ def fetch_pixelfed_api(args: argparse.Namespace) -> int:
             if "domain" not in row:
                 logger.warning("row='%s' does not contain element 'domain' - SKIPPED!", row)
                 continue
-            elif row["domain"] is None or row["domain"] == "":
+            elif row["domain"] in [None, ""]:
                 logger.debug("row[domain]='%s' is empty - SKIPPED!", row["domain"])
                 continue
 
@@ -224,7 +224,7 @@ def fetch_bkali(args: argparse.Namespace) -> int:
             if "domain" not in entry:
                 logger.warning("entry()=%d does not contain 'domain' - SKIPPED!", len(entry))
                 continue
-            elif entry["domain"] is None or entry["domain"] == "":
+            elif entry["domain"] in [None, ""]:
                 logger.debug("entry[domain]='%s' is empty - SKIPPED!", entry["domain"])
                 continue
             elif not domain_helper.is_wanted(entry["domain"]):
@@ -367,7 +367,7 @@ def fetch_blocks(args: argparse.Namespace) -> int:
             block["reason"]  = tidyup.reason(block["reason"]) if block["reason"] is not None and block["reason"] != "" else None
             logger.debug("blocked='%s',reason='%s' - AFTER!", block["blocked"], block["reason"])
 
-            if block["blocked"] is None or block["blocked"] == "":
+            if block["blocked"] in [None, ""]:
                 logger.warning("block[blocked]='%s' is empty, blocker='%s'", block["blocked"], blocker)
                 continue
             elif block["blocked"].endswith(".onion"):
@@ -418,7 +418,7 @@ def fetch_blocks(args: argparse.Namespace) -> int:
                 nodeinfo_url     = row["nodeinfo_url"]
 
             logger.debug("Looking up instance by domain, blocked='%s'", block["blocked"])
-            if block["blocked"] is None or block["blocked"] == "":
+            if block["blocked"] in [None, ""]:
                 logger.debug("block[blocked]='%s' is empty - SKIPPED!", block["blocked"])
                 continue
 
@@ -550,7 +550,7 @@ def fetch_observer(args: argparse.Namespace) -> int:
             domain = tidyup.domain(domain) if domain not in [None, ""] else None
             logger.debug("domain='%s' - AFTER!", domain)
 
-            if domain is None or domain == "":
+            if domain in [None, ""]:
                 logger.debug("domain='%s' is empty after tidyup.domain() - SKIPPED!", domain)
                 continue
 
@@ -807,7 +807,7 @@ def fetch_fba_rss(args: argparse.Namespace) -> int:
             domain = tidyup.domain(domain) if domain not in[None, ""] else None
 
             logger.debug("domain='%s' - AFTER!", domain)
-            if domain is None or domain == "":
+            if domain in [None, ""]:
                 logger.debug("domain='%s' is empty after tidyup.domain() - SKIPPED!", domain)
                 continue
 
@@ -892,7 +892,7 @@ def fetch_fbabot_atom(args: argparse.Namespace) -> int:
                     domain = tidyup.domain(href) if href not in [None, ""] else None
 
                     logger.debug("domain='%s' - AFTER!", domain)
-                    if domain is None or domain == "":
+                    if domain in [None, ""]:
                         logger.debug("domain='%s' is empty after tidyup.domain() - SKIPPED!", domain)
                         continue
 
@@ -957,9 +957,12 @@ def fetch_instances(args: argparse.Namespace) -> int:
         origin = row["origin"]
         software = row["software"]
 
-    if software_helper.is_relay(software):
-        logger.warning("args.domain='%s' is of software type '%s' which is not supported by this command. Please invoke fetch_relays instead.", args.domain, software)
+    if software is None:
+        logger.warning("args.domain='%s' has no software detected. You can try to run ./fba.py update_nodeinfo --domain=%s --force to get it updated.", args.domain, args.domain)
         return 102
+    elif software_helper.is_relay(software):
+        logger.warning("args.domain='%s' is of software type '%s' which is not supported by this command. Please invoke fetch_relays instead.", args.domain, software)
+        return 103
 
     # Initial fetch
     try:
@@ -969,7 +972,7 @@ def fetch_instances(args: argparse.Namespace) -> int:
         logger.warning("Exception '%s' during fetching instances (fetch_instances) from args.domain='%s'", type(exception), args.domain)
         instances.set_last_error(args.domain, exception)
         instances.update(args.domain)
-        return 100
+        return 104
 
     if args.single:
         logger.debug("Not fetching more instances - EXIT!")
@@ -1082,7 +1085,7 @@ def fetch_txt(args: argparse.Namespace) -> int:
                 domain = tidyup.domain(domain) if domain not in[None, ""] else None
 
                 logger.debug("domain='%s' - AFTER!", domain)
-                if domain is None or domain == "":
+                if domain in [None, ""]:
                     logger.debug("domain='%s' is empty after tidyup.domain() - SKIPPED!", domain)
                     continue
                 elif not domain_helper.is_wanted(domain):
@@ -1138,7 +1141,7 @@ def fetch_fedipact(args: argparse.Namespace) -> int:
             domain = tidyup.domain(row.contents[0]) if row.contents[0] not in [None, ""] else None
 
             logger.debug("domain='%s' - AFTER!", domain)
-            if domain is None or domain == "":
+            if domain in [None, ""]:
                 logger.debug("domain='%s' is empty after tidyup.domain() - SKIPPED!", domain)
                 continue
 
@@ -1278,12 +1281,16 @@ def recheck_obfuscation(args: argparse.Namespace) -> int:
         if (args.force is None or not args.force) and args.domain is None and args.software is None and instances.is_recent(row["domain"], "last_blocked"):
             logger.debug("row[domain]='%s' has been recently checked, args.force[]='%s' - SKIPPED!", row["domain"], type(args.force))
             continue
+        elif blacklist.is_blacklisted(row["domain"]):
+            logger.warning("row[domain]='%s' is blacklisted - SKIPPED!", row["domain"])
+            continue
 
         logger.debug("Invoking federation.fetch_blocks(%s) ...", row["domain"])
         blocking = federation.fetch_blocks(row["domain"])
 
         logger.debug("blocking()=%d", len(blocking))
         if len(blocking) == 0:
+            logger.debug("Empty blocking list, trying individual fetch_blocks() for row[software]='%s' ...", row["software"])
             if row["software"] == "pleroma":
                 logger.debug("domain='%s',software='%s'", row["domain"], row["software"])
                 blocking = pleroma.fetch_blocks(row["domain"])
@@ -1304,7 +1311,7 @@ def recheck_obfuscation(args: argparse.Namespace) -> int:
 
         # c.s isn't part of oliphant's "hidden" blocklists
         logger.debug("row[domain]='%s'", row["domain"])
-        if row["domain"] != "chaos.social" and not software_helper.is_relay(row["software"]) and not blocklists.has(row["domain"]):
+        if row["domain"] != "chaos.social" and row["software"] is not None and not software_helper.is_relay(row["software"]) and not blocklists.has(row["domain"]):
             logger.debug("Invoking instances.set_total_blocks(%s, %d) ...", row["domain"], len(blocking))
             instances.set_last_blocked(row["domain"])
             instances.set_total_blocks(row["domain"], blocking)
@@ -1440,7 +1447,7 @@ def fetch_fedilist(args: argparse.Namespace) -> int:
         domain = tidyup.domain(row["hostname"]) if row["hostname"] not in [None, ""] else None
         logger.debug("domain='%s' - AFTER!", domain)
 
-        if domain is None or domain == "":
+        if domain in [None, ""]:
             logger.debug("domain='%s' is empty after tidyup.domain(): row[hostname]='%s' - SKIPPED!", domain, row["hostname"])
             continue
 
@@ -1482,6 +1489,9 @@ def update_nodeinfo(args: argparse.Namespace) -> int:
     elif args.no_software:
         logger.info("Fetching domains with no software type detected ...")
         database.cursor.execute("SELECT domain, software FROM instances WHERE software IS NULL ORDER BY last_updated ASC")
+    elif args.with_software:
+        logger.info("Fetching domains with any software type detected ...")
+        database.cursor.execute("SELECT domain, software FROM instances WHERE software IS NOT NULL ORDER BY last_updated ASC")
     elif args.no_auto:
         logger.info("Fetching domains with other detection mode than AUTO_DISOVERY being set ...")
         database.cursor.execute("SELECT domain, software FROM instances WHERE detection_mode IS NOT NULL AND detection_mode != 'AUTO_DISCOVERY' ORDER BY last_updated ASC")
@@ -1501,6 +1511,9 @@ def update_nodeinfo(args: argparse.Namespace) -> int:
         if not args.force and instances.is_recent(row["domain"], "last_nodeinfo"):
             logger.debug("row[domain]='%s' has been recently checked - SKIPPED!", row["domain"])
             continue
+        elif blacklist.is_blacklisted(row["domain"]):
+            logger.debug("row[domain]='%s' is blacklisted - SKIPPED!", row["domain"])
+            continue
 
         try:
             logger.info("Checking nodeinfo for row[domain]='%s',row[software]='%s' (%s%%) ...", row["domain"], row["software"], "{:5.1f}".format(cnt / len(domains) * 100))
@@ -1698,11 +1711,11 @@ def fetch_relays(args: argparse.Namespace) -> int:
     logger.info("Checking %d relays ...", len(rows))
     for row in rows:
         logger.debug("row[domain]='%s',row[software]='%s' ...", row["domain"], row["software"])
-        peers = list()
         if not args.force and instances.is_recent(row["domain"]):
             logger.debug("row[domain]='%s' has been recently fetched - SKIPPED!", row["domain"])
             continue
 
+        peers = list()
         try:
             if row["software"] == "pub-relay":
                 logger.info("Fetching row[nodeinfo_url]='%s' from relay row[domain]='%s',row[software]='%s' ...", row["nodeinfo_url"], row["domain"], row["software"])
@@ -1780,7 +1793,7 @@ def fetch_relays(args: argparse.Namespace) -> int:
                     domain = tidyup.domain(domain) if domain not in[None, ""] else None
                     logger.debug("domain='%s' - AFTER!", domain)
 
-                    if domain is None or domain == "":
+                    if domain in [None, ""]:
                         logger.debug("domain='%s' is empty after tidyup.domain() from origin='%s' - SKIPPED!", domain, row["domain"])
                         continue
                     elif domain not in peers:
@@ -1822,7 +1835,7 @@ def fetch_relays(args: argparse.Namespace) -> int:
                 domain = tidyup.domain(domain) if domain not in[None, ""] else None
                 logger.debug("domain='%s' - AFTER!", domain)
 
-                if domain is None or domain == "":
+                if domain in [None, ""]:
                     logger.debug("domain='%s' is empty after tidyup.domain() from origin='%s' - SKIPPED!", domain, row["domain"])
                     continue
                 elif domain not in peers:
@@ -1846,7 +1859,7 @@ def fetch_relays(args: argparse.Namespace) -> int:
                 domain = tidyup.domain(domain) if domain not in[None, ""] else None
                 logger.debug("domain='%s' - AFTER!", domain)
 
-                if domain is None or domain == "":
+                if domain in [None, ""]:
                     logger.debug("domain='%s' is empty after tidyup.domain() from origin='%s' - SKIPPED!", domain, row["domain"])
                     continue
                 elif domain not in peers: