]> git.phdru.name Git - bookmarks_db.git/commitdiff
Feat(Robots): Do not return error from `check_url()`
authorOleg Broytman <phd@phdru.name>
Tue, 6 Aug 2024 16:01:37 +0000 (19:01 +0300)
committerOleg Broytman <phd@phdru.name>
Tue, 6 Aug 2024 17:53:31 +0000 (20:53 +0300)
Break the entire program with `Ctrl-C`.

Robots/bkmk_rforking.py
Robots/bkmk_robot_base.py
bkmk-add.py
check_urls.py
check_urls_db.py

index 7b458df0ca8767cba61c3c1b76a3d8d5579b03f3..c956d135e8d73f2186d1064abcfe014d2ed494e7 100644 (file)
@@ -104,10 +104,7 @@ class robot_forking(Robot):
             sys.stderr.flush()
 
         except KeyboardInterrupt:
-            return 0
-
-        # Tested
-        return 1
+            return
 
     def stop(self):
         stop_subp(None)  # Stop subprocess; do not log restarting
index b2e444220a4bf00e701f3bc5b933eaba20c91813..6d3479a236131460aaab2a872d9ced802f402d8a 100644 (file)
@@ -107,11 +107,11 @@ class robot_base(Robot):
 
             if error is not None:
                 bookmark.error = error
-                return 1
+                return
 
             if http_status_code and (http_status_code >= 300):
                 self.set_redirect(bookmark, http_status_code, redirect_to)
-                return 1
+                return
 
             size = 0
             last_modified = None
@@ -321,7 +321,7 @@ class robot_base(Robot):
 
         except KeyboardInterrupt:
             self.log("Keyboard interrupt (^C)")
-            return 0
+            return
 
         except socket.error as e:
             bookmark.error = get_error(e)
@@ -336,9 +336,6 @@ class robot_base(Robot):
         finally:
             self.finish_check_url(bookmark)
 
-        # Tested
-        return 1
-
     def smart_get(self, bookmark, url, accept_charset=False):
         split_results = urlsplit(url)
         url_proto = split_results.scheme
index 239ce4ecdd3c203c0e5c5527d6db84ff8018ef07..768af058672e8d23a78ac956c8f3e8b302131bdb 100755 (executable)
@@ -60,25 +60,25 @@ def run():
     print("Using", robot)
     _robot = robot(None)
 
-    if _robot.check_url(bookmark):  # get real title and last modified date
-        if title:  # forced title
-            bookmark.name = title
-        elif hasattr(bookmark, "real_title"):
-            bookmark.name = bookmark.real_title
-        if report_stats:
-            sys.stdout.write("Adding %s with title '%s'\n"
-                             % (href, bookmark.name))
-        del bookmark.parent
-        root_folder.append(bookmark)
-
-        if report_stats:
-            sys.stdout.write("Storing %s: " % storage.filename)
-            sys.stdout.flush()
-
-        storage.store(root_folder)
-
-        if report_stats:
-            print("Ok")
+    _robot.check_url(bookmark)  # get real title and last modified date
+    if title:  # forced title
+        bookmark.name = title
+    elif hasattr(bookmark, "real_title"):
+        bookmark.name = bookmark.real_title
+    if report_stats:
+        sys.stdout.write("Adding %s with title '%s'\n"
+                         % (href, bookmark.name))
+    del bookmark.parent
+    root_folder.append(bookmark)
+
+    if report_stats:
+        sys.stdout.write("Storing %s: " % storage.filename)
+        sys.stdout.flush()
+
+    storage.store(root_folder)
+
+    if report_stats:
+        print("Ok")
 
 
 if __name__ == '__main__':
index 0be8f563b7e56917744d89f657e86f3495209f18..9009d006b1a5f5ef80b99b123f3d74649c17f6ad 100755 (executable)
@@ -48,8 +48,7 @@ def run():
         bookmark = Bookmark(href=url, add_date=None)
         bookmark.parent = None
 
-        rcode = robot.check_url(bookmark)
-        print("check_urls: %s" % rcode)
+        robot.check_url(bookmark)
 
         if hasattr(bookmark, 'error'):
             print(bookmark.error)
index b8db63982f69192dd38a11595cba861dcf07db31..dbab6bf0f31d51ebb3d9db3e91820068b2ba904d 100755 (executable)
@@ -99,7 +99,6 @@ def run():
     size = 0
 
     checked = {}
-    rcode = 1
 
     for object_no in range(objects):
         if show_pbar:
@@ -134,18 +133,14 @@ def run():
                                 getattr(old_object, attr_name))
             else:
                 log("Checking %s" % href)
-                rcode = robot.check_url(object)
-
-                if rcode:
-                    checked[href] = object_no
-                    urls_no = urls_no + 1
-                    try:
-                        size = size + int(object.size)
-                    except (AttributeError, TypeError, ValueError):
-                        pass  # Some object does not have a size :(
-                else:
-                    log("Interrupted by user (^C)")
-                    break
+                robot.check_url(object)
+
+                checked[href] = object_no
+                urls_no = urls_no + 1
+                try:
+                    size = size + int(object.size)
+                except (AttributeError, TypeError, ValueError):
+                    pass  # Some object does not have a size :(
     robot.stop()
 
     if show_pbar:
@@ -161,8 +156,7 @@ def run():
     del root_folder.linear
     storage.store(root_folder)
 
-    if rcode:
-        log("check_urls_db finished ok")
+    log("check_urls_db finished ok")
     log.close()