]> git.phdru.name Git - bookmarks_db.git/blobdiff - Robots/bkmk_rforking_sub.py
Fix(Py3): Fix subrocess: pass bytes streams to `RecordFile`
[bookmarks_db.git] / Robots / bkmk_rforking_sub.py
index 63464fccff91414dee6f01303516204852491e2f..3c6846921cfd72cd19edbf3ef7c434d8ce871f84 100755 (executable)
@@ -1,44 +1,50 @@
-#! /usr/bin/env python
-"""
-   Check URL - subprocess for the forking robot
+#! /usr/bin/env python3
+"""Subprocess for the forking robot - check URL using bkmk_rurlib robot
+
+This file is a part of Bookmarks database and Internet robot.
 
-   Written by Broytman. Copyright (C) 1999-2010 PhiloSoft Design.
 """
 
+__author__ = "Oleg Broytman <phd@phdru.name>"
+__copyright__ = "Copyright (C) 1999-2023 PhiloSoft Design"
+__license__ = "GNU GPL"
 
-import sys, os
+__all__ = []
 
-lib_dir = os.path.normpath(os.path.dirname(sys.argv[0]) + os.sep + os.pardir)
-sys.path.append(lib_dir) # for bkmk_objects.py
+
+import os
+import sys
 
 try:
-   import cPickle
-   pickle = cPickle
+    import cPickle
+    pickle = cPickle
 except ImportError:
-   import pickle
+    import pickle
+
+lib_dir = os.path.normpath(os.path.dirname(os.path.dirname(sys.argv[0])))
+sys.path.append(lib_dir)  # for bkmk_objects.py
 
 from subproc import RecordFile
-import bkmk_rsimple
 
 
 def run():
-   bkmk_in = RecordFile(sys.stdin)
-   bkmk_out = RecordFile(sys.stdout)
+    bkmk_in = RecordFile(getattr(sys.stdin, 'buffer', None) or sys.stdin)
+    bkmk_out = RecordFile(getattr(sys.stdout, 'buffer', None) or sys.stdout)
 
-   from m_lib.flog import openlog
-   log = openlog("check2.log")
-   from bkmk_rsimple import robot_simple
-   robot = robot_simple(log)
+    from m_lib.flog import openlog
+    log = openlog("check2.log")
+    from robots import robot
+    robot = robot(log)
 
-   while 1:
-      bookmark = pickle.loads(bkmk_in.read_record())
-      log(bookmark.href)
-      robot.check_url(bookmark)
-      bkmk_out.write_record(pickle.dumps(bookmark))
-      log.outfile.flush()
+    while 1:
+        bookmark = pickle.loads(bkmk_in.read_record())
+        log(bookmark.href)
+        robot.check_url(bookmark)
+        bkmk_out.write_record(pickle.dumps(bookmark))
+        log.outfile.flush()
 
-   log.close()
+    log.close()
 
 
 if __name__ == '__main__':
-   run()
+    run()