]> git.phdru.name Git - bookmarks_db.git/commitdiff
Feat(Python3): Use print() function
authorOleg Broytman <phd@phdru.name>
Sat, 13 May 2017 16:20:21 +0000 (19:20 +0300)
committerOleg Broytman <phd@phdru.name>
Sat, 13 May 2017 16:20:21 +0000 (19:20 +0300)
14 files changed:
bkmk-add.py
bkmk2db.py
bkmk_parser.py
check_dups.py
check_title.py
check_url.py
check_urls.py
convert_st.py
db2bkmk.py
parse_html/__main__.py
set-real_title.py
set-title-list.py
sort_db.py
subproc.py

index b882cf9082e22e7b0a807e0bba81c8b4f9decc3c..f0db4eaf7e0b3d7f592c4db24a7aca16dceba828 100755 (executable)
@@ -6,7 +6,7 @@ This file is a part of Bookmarks database and Internet robot.
 """
 
 __author__ = "Oleg Broytman <phd@phdru.name>"
-__copyright__ = "Copyright (C) 2002-2014 PhiloSoft Design"
+__copyright__ = "Copyright (C) 2002-2017 PhiloSoft Design"
 __license__ = "GNU GPL"
 
 import sys, os, time
@@ -46,7 +46,7 @@ def run():
    root_folder = storage.load()
 
    if report_stats:
-      print "Ok"
+      print("Ok")
 
    href = args[0]
    now = int(time.time())
@@ -74,7 +74,7 @@ def run():
       storage.store(root_folder)
 
       if report_stats:
-         print "Ok"
+         print("Ok")
 
 
 if __name__ == '__main__':
index 34fca60d21fa8ced2434430a1c0de314440d4f33..b8905324ab2d620b04acb03b57dfc920390d54f0 100755 (executable)
@@ -4,15 +4,17 @@
 This file is a part of Bookmarks database and Internet robot.
 """
 
-__author__ = "Oleg Broytman <phd@phdru.name>"
-__copyright__ = "Copyright (C) 1997-2012 PhiloSoft Design"
-__license__ = "GNU GPL"
-
+from __future__ import print_function
 import sys, os
 from getopt import getopt
 from bkmk_parser import BkmkParser
 
 
+__author__ = "Oleg Broytman <phd@phdru.name>"
+__copyright__ = "Copyright (C) 1997-2017 PhiloSoft Design"
+__license__ = "GNU GPL"
+
+
 def run():
    optlist, args = getopt(sys.argv[1:], "is")
 
@@ -59,7 +61,7 @@ def run():
       try:
          size = os.path.getsize(filename)
       except:
-         print filename, ": no such file"
+         print(filename, ": no such file")
          sys.exit(1)
 
 
@@ -106,10 +108,10 @@ def run():
       del pbar
 
    if report_stats:
-      print "Ok"
-      print line_no, "lines proceed"
-      print parser.urls, "urls found"
-      print parser.objects, "objects created"
+      print("Ok")
+      print(line_no, "lines proceed")
+      print(parser.urls, "urls found")
+      print(parser.objects, "objects created")
 
    if ok:
       from storage import storage
index 02116ccf025c9edacd119362331b64174ce89767..7430c08044fb6abfbc11e275f78a05076e42d597 100644 (file)
@@ -4,7 +4,7 @@ This file is a part of Bookmarks database and Internet robot.
 """
 
 __author__ = "Oleg Broytman <phd@phdru.name>"
-__copyright__ = "Copyright (C) 1997-2012 PhiloSoft Design"
+__copyright__ = "Copyright (C) 1997-2017 PhiloSoft Design"
 __license__ = "GNU GPL"
 
 __all__ = ['BkmkParser']
@@ -20,7 +20,7 @@ DEBUG = os.environ.has_key("BKMK_DEBUG")
 
 if DEBUG:
    def debug(note):
-      print note
+      print(note)
 
    def dump_names(folder_stack):
       l = []
index eebd09b20ac0c09691262cf032e804131c542c55..f635c23ad9c48011c619a5ec0fcfaa4dcef3c818 100755 (executable)
@@ -4,12 +4,14 @@
 This file is a part of Bookmarks database and Internet robot.
 """
 
+from __future__ import print_function
+import sys
+
+
 __author__ = "Oleg Broytman <phd@phdru.name>"
-__copyright__ = "Copyright (C) 2000-2012 PhiloSoft Design"
+__copyright__ = "Copyright (C) 2000-2017 PhiloSoft Design"
 __license__ = "GNU GPL"
 
-import sys
-
 
 log_file = None
 
@@ -19,7 +21,7 @@ def report_dup(href, object_no):
    if log_file:
       log_file.write("%s\n" % s)
    else:
-      print s
+      print(s)
 
 
 def run():
@@ -41,7 +43,7 @@ def run():
       pass
 
    if report_stats:
-      print "Broytman check_dups, Copyright (C) 2000-2007 PhiloSoft Design"
+      print("Broytman check_dups, Copyright (C) 2000-2017 PhiloSoft Design")
 
    if args:
       sys.stderr.write("check_urls: too many arguments\n")
@@ -64,7 +66,7 @@ def run():
    objects = len(root_folder.linear)
 
    if report_stats:
-      print "Ok"
+      print("Ok")
 
 
    dup_dict = {}
@@ -84,8 +86,8 @@ def run():
       log_file.close()
 
    if report_stats:
-      print "Ok"
-      print objects, "objects passed"
+      print("Ok")
+      print(objects, "objects passed")
 
 
 if __name__ == '__main__':
index 02c8e9ced9feee35c7062f4a38c96b051856bf52..c93964f986cd473a9c4d23c8b42b1b49d15db846 100755 (executable)
@@ -4,14 +4,16 @@
 This file is a part of Bookmarks database and Internet robot.
 """
 
-__author__ = "Oleg Broytman <phd@phdru.name>"
-__copyright__ = "Copyright (C) 2002-2012 PhiloSoft Design"
-__license__ = "GNU GPL"
-
+from __future__ import print_function
 import sys
 from bkmk_objects import make_linear, quote_title, unquote_title
 
 
+__author__ = "Oleg Broytman <phd@phdru.name>"
+__copyright__ = "Copyright (C) 2002-2017 PhiloSoft Design"
+__license__ = "GNU GPL"
+
+
 def run():
    from getopt import getopt
    optlist, args = getopt(sys.argv[1:], "s")
@@ -27,7 +29,7 @@ def run():
       pass
 
    if report_stats:
-      print "Broytman check_title, Copyright (C) 2002-2010 PhiloSoft Design"
+      print("Broytman check_title, Copyright (C) 2002-2017 PhiloSoft Design")
 
    if args:
       sys.stderr.write("check_title: too many arguments\n")
@@ -46,7 +48,7 @@ def run():
    objects = len(root_folder.linear)
 
    if report_stats:
-      print "Ok"
+      print("Ok")
 
 
    for object_no in range(objects):
@@ -61,19 +63,19 @@ def run():
             unquoted_title = unquote_title(quote_title(object.real_title))
             unquoted_name = unquote_title(object.name)
             if unquoted_name <> unquoted_title:
-               print object.href
-               print unquoted_name
-               print unquoted_title
-               print
+               print(object.href)
+               print(unquoted_name)
+               print(unquoted_title)
+               print()
          else:
-            print object.href
-            print object.name
-            print "NO REAL TITLE!!!"
-            print
+            print(object.href)
+            print(object.name)
+            print("NO REAL TITLE!!!")
+            print()
 
 
    if report_stats:
-      print objects, "objects passed"
+      print(objects, "objects passed")
 
 
 if __name__ == '__main__':
index d9a6c22eeb4027bd3f79b2d48d8e05d66ca5365e..8a6ec0aa5d2b11d6177d659422b0f4568856126c 100755 (executable)
@@ -5,7 +5,7 @@ This file is a part of Bookmarks database and Internet robot.
 """
 
 __author__ = "Oleg Broytman <phd@phdru.name>"
-__copyright__ = "Copyright (C) 2010-2012 PhiloSoft Design"
+__copyright__ = "Copyright (C) 2010-2017 PhiloSoft Design"
 __license__ = "GNU GPL"
 
 import sys
@@ -25,7 +25,7 @@ from Writers.bkmk_wflad import strftime
 
 
 def run():
-   print "Broytman check_url, Copyright (C) 2010 PhiloSoft Design"
+   print("Broytman check_url, Copyright (C) 2010-2017 PhiloSoft Design")
 
    if len(sys.argv) < 2:
       sys.stderr.write("Usage: check_url.py url1 [url2...]\n")
@@ -42,19 +42,19 @@ def run():
        bookmark.parent = None
 
        rcode = robot.check_url(bookmark)
-       print "check_url: %s" % rcode
+       print("check_url: %s" % rcode)
 
        if hasattr(bookmark, 'error'):
-          print bookmark.error
+          print(bookmark.error)
 
        else:
-          print """\
+          print("""\
 URL: %s
 Title: %s
 LastModified: %s
 IconURI: %s
 Icon: %s
-""" % (bookmark.href, getattr(bookmark, 'real_title', ''), strftime(bookmark.last_modified), bookmark.icon_href, bookmark.icon)
+""" % (bookmark.href, getattr(bookmark, 'real_title', ''), strftime(bookmark.last_modified), bookmark.icon_href, bookmark.icon))
 
    robot.stop()
    log.close()
index e2dac0ff3c516a65ed9f23b22d37ce050bbe6030..d6d038d2c624a116c22b60f772260095661909a1 100755 (executable)
@@ -4,12 +4,14 @@
 This file is a part of Bookmarks database and Internet robot.
 """
 
+from __future__ import print_function
+import sys, os
+
+
 __author__ = "Oleg Broytman <phd@phdru.name>"
-__copyright__ = "Copyright (C) 2000-2012 PhiloSoft Design"
+__copyright__ = "Copyright (C) 2000-2017 PhiloSoft Design"
 __license__ = "GNU GPL"
 
-import sys, os
-
 
 def run():
    from getopt import getopt
@@ -32,7 +34,7 @@ def run():
       pass
 
    if report_stats:
-      print "Broytman check_urls, Copyright (C) 1997-2010 PhiloSoft Design"
+      print("Broytman check_urls, Copyright (C) 1997-2017 PhiloSoft Design")
 
    if args:
       sys.stderr.write("check_urls: too many arguments\n")
@@ -53,12 +55,12 @@ def run():
       log = openlog("check.log")
       log("chk_urls restarted for errors")
       if report_stats:
-         print "chk_urls restarted for errors"
+         print("chk_urls restarted for errors")
    else:
       log = makelog("check.log")
       log("check_urls started")
       if report_stats:
-         print "   check_urls: normal start"
+         print("   check_urls: normal start")
 
    from storage import storage
    storage = storage()
@@ -76,7 +78,7 @@ def run():
    objects = len(root_folder.linear)
 
    if report_stats:
-      print "Ok"
+      print("Ok")
 
    if report_stats:
       if only_errors:
@@ -144,10 +146,10 @@ def run():
       del pbar
 
    if report_stats:
-      print "Ok"
-      print object_count, "objects passed"
-      print urls_no, "URLs checked"
-      print size, "bytes eaten"
+      print("Ok")
+      print(object_count, "objects passed")
+      print(urls_no, "URLs checked")
+      print(size, "bytes eaten")
 
    break_tree(root_folder.linear)
    storage.store(root_folder)
index c8a6a240fe08b7f1c9b879c4167422d672ef5b21..005710b8067d558fff6f20953640d21014404a4e 100755 (executable)
@@ -5,7 +5,7 @@ This file is a part of Bookmarks database and Internet robot.
 """
 
 __author__ = "Oleg Broytman <phd@phdru.name>"
-__copyright__ = "Copyright (C) 2000-2012 PhiloSoft Design"
+__copyright__ = "Copyright (C) 2000-2017 PhiloSoft Design"
 __license__ = "GNU GPL"
 
 import sys
@@ -47,14 +47,14 @@ def run():
    root_folder = storage.load()
 
    if report_stats:
-      print "Ok"
+      print("Ok")
       sys.stdout.write("Converting to %s: " % new_storage.filename)
       sys.stdout.flush()
 
    new_storage.store(root_folder)
 
    if report_stats:
-      print "Ok"
+      print("Ok")
 
 
 if __name__ == '__main__':
index a9e0fd455aa73acb36589ef1afc7a0a2d740ef63..14b02e4b71cf3e96946662341ab13fb33d1b1282 100755 (executable)
@@ -5,7 +5,7 @@ This file is a part of Bookmarks database and Internet robot.
 """
 
 __author__ = "Oleg Broytman <phd@phdru.name>"
-__copyright__ = "Copyright (C) 2000-2012 PhiloSoft Design"
+__copyright__ = "Copyright (C) 2000-2017 PhiloSoft Design"
 __license__ = "GNU GPL"
 
 import sys
@@ -56,7 +56,7 @@ def run():
    root_folder = storage.load()
 
    if report_stats:
-      print "Ok"
+      print("Ok")
       sys.stdout.write("Writing %s: " % output_filename)
       sys.stdout.flush()
 
@@ -101,7 +101,7 @@ def run():
    outfile.close()
 
    if report_stats:
-      print "Ok"
+      print("Ok")
 
 
 if __name__ == '__main__':
index e5428e5053e6d97acc163a72216c065e408edc82..34b8ed44cf90838d17f3458f460129ea80101f1f 100644 (file)
@@ -4,12 +4,13 @@ This file is a part of Bookmarks database and Internet robot.
 
 """
 
-__author__ = "Oleg Broytman <phd@phdru.name>"
-__copyright__ = "Copyright (C) 2014 PhiloSoft Design"
-__license__ = "GNU GPL"
+from __future__ import print_function
+from .bkmk_parse_html import parse_filename
 
 
-from .bkmk_parse_html import parse_filename
+__author__ = "Oleg Broytman <phd@phdru.name>"
+__copyright__ = "Copyright (C) 2014-2017 PhiloSoft Design"
+__license__ = "GNU GPL"
 
 
 def main():
@@ -27,8 +28,8 @@ def main():
       sys.exit("Usage: main filename [charset]")
 
    parser = parse_filename(filename, charset, log=lambda s: sys.stdout.write(s + '\n'))
-   print "   refresh:", parser.refresh
-   print "   icon   :", parser.icon
+   print("   refresh:", parser.refresh)
+   print("   icon   :", parser.icon)
 
 if __name__ == '__main__':
     main()
index 62ded1c21b93cbf50ac33c79c2abe476cc728d7c..fab938f6ae6309a674cb10df7dfe2e7c11bb7368 100755 (executable)
@@ -4,12 +4,14 @@
 This file is a part of Bookmarks database and Internet robot.
 """
 
+from __future__ import print_function
+import sys
+
+
 __author__ = "Oleg Broytman <phd@phdru.name>"
-__copyright__ = "Copyright (C) 2002-2012 PhiloSoft Design"
+__copyright__ = "Copyright (C) 2002-2017 PhiloSoft Design"
 __license__ = "GNU GPL"
 
-import sys
-
 
 def run():
    from getopt import getopt
@@ -26,7 +28,7 @@ def run():
       pass
 
    if report_stats:
-      print "Broytman set-real_title, Copyright (C) 2003 PhiloSoft Design"
+      print("Broytman set-real_title, Copyright (C) 2003-2017 PhiloSoft Design")
 
    if args:
       sys.stderr.write("set-real_title: too many arguments\n")
@@ -46,7 +48,7 @@ def run():
    objects = len(root_folder.linear)
 
    if report_stats:
-      print "Ok"
+      print("Ok")
 
 
    changed = 0
@@ -77,9 +79,9 @@ def run():
       storage.store(root_folder)
 
    if changed and report_stats:
-      print "Ok"
-      print objects, "objects passed"
-      print changed, "objects changed"
+      print("Ok")
+      print(objects, "objects passed")
+      print(changed, "objects changed")
 
 
 if __name__ == '__main__':
index 2fb37eccb838b43fdde557435528719252615680..eb327d62b41b164b4fdfd57219e2dd8e668d976c 100755 (executable)
@@ -4,12 +4,14 @@
 This file is a part of Bookmarks database and Internet robot.
 """
 
+from __future__ import print_function
+import sys
+
+
 __author__ = "Oleg Broytman <phd@phdru.name>"
-__copyright__ = "Copyright (C) 2003-2012 PhiloSoft Design"
+__copyright__ = "Copyright (C) 2003-2017 PhiloSoft Design"
 __license__ = "GNU GPL"
 
-import sys
-
 
 def run():
    from getopt import getopt
@@ -26,7 +28,7 @@ def run():
       pass
 
    if report_stats:
-      print "Broytman set-title-list, Copyright (C) 2003-2007 PhiloSoft Design"
+      print("Broytman set-title-list, Copyright (C) 2003-2017 PhiloSoft Design")
 
    if len(args) <> 1:
       sys.stderr.write("Usage: set-title-list [-s] title_list_file\n")
@@ -78,7 +80,7 @@ def run():
    objects = len(root_folder.linear)
 
    if report_stats:
-      print "Ok"
+      print("Ok")
 
 
    # Run through the list of objects and check URLs/titles
@@ -108,9 +110,9 @@ def run():
       storage.store(root_folder)
 
    if changed and report_stats:
-      print "Ok"
-      print objects, "objects passed"
-      print changed, "objects changed"
+      print("Ok")
+      print(objects, "objects passed")
+      print(changed, "objects changed")
 
 
 if __name__ == '__main__':
index f53cdd4d71b57c20558859220721671e06dbd397..9a478bf75c394513411e762c2ccc2cdb9d4a30cf 100755 (executable)
@@ -13,7 +13,7 @@ This file is a part of Bookmarks database and Internet robot.
 """
 
 __author__ = "Oleg Broytman <phd@phdru.name>"
-__copyright__ = "Copyright (C) 2000-2014 PhiloSoft Design"
+__copyright__ = "Copyright (C) 2000-2017 PhiloSoft Design"
 __license__ = "GNU GPL"
 
 import sys
@@ -81,7 +81,7 @@ def run():
    root_folder = storage.load()
 
    if report_stats:
-      print "Ok"
+      print("Ok")
       sys.stdout.write("Sorting (by %s): " % sort_by)
       sys.stdout.flush()
 
@@ -102,7 +102,7 @@ def run():
       output_filename = output_filename + "-reverse"
 
    if report_stats:
-      print "done"
+      print("done")
       sys.stdout.write("Writing %s: " % output_filename)
       sys.stdout.flush()
 
@@ -113,7 +113,7 @@ def run():
    outfile.close()
 
    if report_stats:
-      print "Ok"
+      print("Ok")
 
 
 if __name__ == '__main__':
index f9a77b5f6a8d70488e80dc22894940452d938f88..f5e89c5ffc75c003e22b8335ea4bdb9d9d39d9c9 100644 (file)
@@ -272,9 +272,9 @@ class Subprocess:
             os.kill(self.pid, signal.SIGSTOP)
         except os.error:
             if verbose:
-                print "Stop failed for '%s' - '%s'" % (self.cmd, sys.exc_value)
+                print("Stop failed for '%s' - '%s'" % (self.cmd, sys.exc_value))
             return 0
-        if verbose: print "Stopped '%s'" % self.cmd
+        if verbose: print("Stopped '%s'" % self.cmd)
         return 'stopped'
 
     def cont(self, verbose=0):
@@ -284,10 +284,10 @@ class Subprocess:
             os.kill(self.pid, signal.SIGCONT)
         except os.error:
             if verbose:
-                print ("Continue failed for '%s' - '%s'" %
-                       (self.cmd, sys.exc_value))
+                print(("Continue failed for '%s' - '%s'" %
+                       (self.cmd, sys.exc_value)))
             return 0
-        if verbose: print "Continued '%s'" % self.cmd
+        if verbose: print("Continued '%s'" % self.cmd)
         return 'continued'
 
     def die(self):
@@ -315,9 +315,9 @@ class Subprocess:
                 # WNOHANG == 1 on sunos, presumably same elsewhere.
                 if os.waitpid(self.pid, os.WNOHANG):
                     if self.expire_noisily:
-                        print ("\n(%s subproc %d '%s' / %s)" %
+                        print(("\n(%s subproc %d '%s' / %s)" %
                                (sig[0], self.pid, self.cmd,
-                                hex(id(self))[2:]))
+                                hex(id(self))[2:])))
                     for i in self.pipefiles:
                         os.close(i)
                     self.pid = 0
@@ -644,41 +644,41 @@ class Ph:
 #############################################################################
 
 def test(p=0):
-    print "\tOpening subprocess:"
+    print("\tOpening subprocess:")
     p = Subprocess('cat', 1)            # set to expire noisily...
-    print p
-    print "\tOpening bogus subprocess, should fail:"
+    print(p)
+    print("\tOpening bogus subprocess, should fail:")
     try:
         b = Subprocess('/', 1)
-        print "\tOops!  Null-named subprocess startup *succeeded*?!?"
+        print("\tOops!  Null-named subprocess startup *succeeded*?!?")
     except SubprocessError:
-        print "\t...yep, it failed."
-    print '\tWrite, then read, two newline-teriminated lines, using readline:'
+        print("\t...yep, it failed.")
+    print('\tWrite, then read, two newline-teriminated lines, using readline:')
     p.write('first full line written\n'); p.write('second.\n')
-    print `p.readline()`
-    print `p.readline()`
-    print '\tThree lines, last sans newline, read using combination:'
+    print(`p.readline()`)
+    print(`p.readline()`)
+    print('\tThree lines, last sans newline, read using combination:')
     p.write('first\n'); p.write('second\n'); p.write('third, (no cr)')
-    print '\tFirst line via readline:'
-    print `p.readline()`
-    print '\tRest via readPendingChars:'
-    print p.readPendingChars()
-    print "\tStopping then continuing subprocess (verbose):"
+    print('\tFirst line via readline:')
+    print(`p.readline()`)
+    print('\tRest via readPendingChars:')
+    print(p.readPendingChars())
+    print("\tStopping then continuing subprocess (verbose):")
     if not p.stop(1):                   # verbose stop
-        print '\t** Stop seems to have failed!'
+        print('\t** Stop seems to have failed!')
     else:
-        print '\tWriting line while subprocess is paused...'
+        print('\tWriting line while subprocess is paused...')
         p.write('written while subprocess paused\n')
-        print '\tNonblocking read of paused subprocess (should be empty):'
-        print p.readPendingChars()
-        print '\tContinuing subprocess (verbose):'
+        print('\tNonblocking read of paused subprocess (should be empty):')
+        print(p.readPendingChars())
+        print('\tContinuing subprocess (verbose):')
         if not p.cont(1):               # verbose continue
-            print '\t** Continue seems to have failed!  Probly lost subproc...'
+            print('\t** Continue seems to have failed!  Probly lost subproc...')
             return p
         else:
-            print '\tReading accumulated line, blocking read:'
-            print p.readline()
-            print "\tDeleting subproc, which was set to die noisily:"
+            print('\tReading accumulated line, blocking read:')
+            print(p.readline())
+            print("\tDeleting subproc, which was set to die noisily:")
             del p
-            print "\tDone."
+            print("\tDone.")
             return None