From c1c90856aeffcf8f2bcb7abf39934d5e0f8be36d Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Sat, 13 May 2017 19:20:21 +0300 Subject: [PATCH] Feat(Python3): Use print() function --- bkmk-add.py | 6 ++-- bkmk2db.py | 20 ++++++++------ bkmk_parser.py | 4 +-- check_dups.py | 18 ++++++------ check_title.py | 32 ++++++++++++---------- check_url.py | 12 ++++---- check_urls.py | 24 ++++++++-------- convert_st.py | 6 ++-- db2bkmk.py | 6 ++-- parse_html/__main__.py | 13 +++++---- set-real_title.py | 18 ++++++------ set-title-list.py | 18 ++++++------ sort_db.py | 8 +++--- subproc.py | 62 +++++++++++++++++++++--------------------- 14 files changed, 130 insertions(+), 117 deletions(-) diff --git a/bkmk-add.py b/bkmk-add.py index b882cf9..f0db4ea 100755 --- a/bkmk-add.py +++ b/bkmk-add.py @@ -6,7 +6,7 @@ This file is a part of Bookmarks database and Internet robot. """ __author__ = "Oleg Broytman " -__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__': diff --git a/bkmk2db.py b/bkmk2db.py index 34fca60..b890532 100755 --- a/bkmk2db.py +++ b/bkmk2db.py @@ -4,15 +4,17 @@ This file is a part of Bookmarks database and Internet robot. """ -__author__ = "Oleg Broytman " -__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 " +__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 diff --git a/bkmk_parser.py b/bkmk_parser.py index 02116cc..7430c08 100644 --- a/bkmk_parser.py +++ b/bkmk_parser.py @@ -4,7 +4,7 @@ This file is a part of Bookmarks database and Internet robot. """ __author__ = "Oleg Broytman " -__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 = [] diff --git a/check_dups.py b/check_dups.py index eebd09b..f635c23 100755 --- a/check_dups.py +++ b/check_dups.py @@ -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 " -__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__': diff --git a/check_title.py b/check_title.py index 02c8e9c..c93964f 100755 --- a/check_title.py +++ b/check_title.py @@ -4,14 +4,16 @@ This file is a part of Bookmarks database and Internet robot. """ -__author__ = "Oleg Broytman " -__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 " +__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__': diff --git a/check_url.py b/check_url.py index d9a6c22..8a6ec0a 100755 --- a/check_url.py +++ b/check_url.py @@ -5,7 +5,7 @@ This file is a part of Bookmarks database and Internet robot. """ __author__ = "Oleg Broytman " -__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() diff --git a/check_urls.py b/check_urls.py index e2dac0f..d6d038d 100755 --- a/check_urls.py +++ b/check_urls.py @@ -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 " -__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) diff --git a/convert_st.py b/convert_st.py index c8a6a24..005710b 100755 --- a/convert_st.py +++ b/convert_st.py @@ -5,7 +5,7 @@ This file is a part of Bookmarks database and Internet robot. """ __author__ = "Oleg Broytman " -__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__': diff --git a/db2bkmk.py b/db2bkmk.py index a9e0fd4..14b02e4 100755 --- a/db2bkmk.py +++ b/db2bkmk.py @@ -5,7 +5,7 @@ This file is a part of Bookmarks database and Internet robot. """ __author__ = "Oleg Broytman " -__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__': diff --git a/parse_html/__main__.py b/parse_html/__main__.py index e5428e5..34b8ed4 100644 --- a/parse_html/__main__.py +++ b/parse_html/__main__.py @@ -4,12 +4,13 @@ This file is a part of Bookmarks database and Internet robot. """ -__author__ = "Oleg Broytman " -__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 " +__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() diff --git a/set-real_title.py b/set-real_title.py index 62ded1c..fab938f 100755 --- a/set-real_title.py +++ b/set-real_title.py @@ -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 " -__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__': diff --git a/set-title-list.py b/set-title-list.py index 2fb37ec..eb327d6 100755 --- a/set-title-list.py +++ b/set-title-list.py @@ -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 " -__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__': diff --git a/sort_db.py b/sort_db.py index f53cdd4..9a478bf 100755 --- a/sort_db.py +++ b/sort_db.py @@ -13,7 +13,7 @@ This file is a part of Bookmarks database and Internet robot. """ __author__ = "Oleg Broytman " -__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__': diff --git a/subproc.py b/subproc.py index f9a77b5..f5e89c5 100644 --- a/subproc.py +++ b/subproc.py @@ -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 -- 2.39.5