]> git.phdru.name Git - m_librarian.git/commitdiff
Update code for compatibility with Python 3
authorOleg Broytman <phd@phdru.name>
Fri, 22 Jul 2016 23:55:24 +0000 (02:55 +0300)
committerOleg Broytman <phd@phdru.name>
Fri, 22 Jul 2016 23:55:24 +0000 (02:55 +0300)
It's still not tested under Python 3.

m_librarian/config.py
m_librarian/db.py
m_librarian/download.py
m_librarian/glst.py
scripts/ml-initdb.py
scripts/ml-search.py
tests/__init__.py
tests/run_all.py

index fed06ae4ac2817ac521dc180b2a81d0932814981..2540ac463097408de93019713243c4e56d6c78c0 100755 (executable)
@@ -1,5 +1,6 @@
 #! /usr/bin/env python
 
+from __future__ import print_function
 import os
 from ConfigParser import RawConfigParser
 
@@ -50,8 +51,8 @@ def get_config(config_path=None):
 
 def test():
     config_dirs = find_config_dirs()
-    print "Config dirs:", config_dirs
-    print "Config file:", find_config_file(config_dirs)
+    print("Config dirs:", config_dirs)
+    print("Config file:", find_config_file(config_dirs))
 
 if __name__ == '__main__':
     test()
index e7eea99560eadf289c8beab669c0043fa3cfdaa7..ecabfdbcfd146cf583ea2d8aa6dcfe1e1a7d1be0 100755 (executable)
@@ -1,5 +1,6 @@
 #! /usr/bin/env python
 
+from __future__ import print_function
 import os
 from sqlobject import SQLObject, StringCol, UnicodeCol, IntCol, BoolCol, \
     ForeignKey, DateCol, DatabaseIndex, RelatedJoin, \
@@ -130,7 +131,7 @@ def find_sqlite_dburi(db_dirs=None):
     else:
         # octal; -rw-------;
         # make the database file/directory readable/writeable only by the user
-        os.umask(0066)
+        os.umask(0o66)
         db_dir = db_dirs[0]
         try:
             os.makedirs(db_dir)
@@ -220,8 +221,8 @@ def update_counters():
 
 def test():
     db_dirs = find_sqlite_db_dirs()
-    print "DB dirs:", db_dirs
-    print "DB URI:", find_sqlite_dburi()
+    print("DB dirs:", db_dirs)
+    print("DB URI:", find_sqlite_dburi())
 
 if __name__ == '__main__':
     test()
index 8e309cb3cbda9a26b856d4f778fbcb25157740ab..6f4daf4fe31e17d2cb75a13e9206dff317cfa2b4 100755 (executable)
@@ -1,5 +1,6 @@
 #! /usr/bin/env python
 
+from __future__ import print_function
 import os
 from time import mktime
 from shutil import copyfileobj
@@ -108,7 +109,7 @@ def download(book, path=None, a_format=None):
 
 def test():
     _compile_format()
-    print compiled_format
+    print(compiled_format)
 
 if __name__ == '__main__':
     test()
index a4ac27d723b4b991ea70b1d6c625f7e1b91de224..f639c1b3b6d4cb58bb6c1e58e3262336376845e4 100755 (executable)
@@ -1,5 +1,6 @@
 #! /usr/bin/env python
 
+from __future__ import print_function
 import codecs
 import os
 from sqlobject import sqlhub, SQLObjectNotFound
@@ -58,7 +59,7 @@ def import_glst():
 
 def test():
     ml_dir = os.path.dirname(__file__)
-    print parse_glst_file(os.path.join(ml_dir, 'glst', 'genres_fb2.glst'))
+    print(parse_glst_file(os.path.join(ml_dir, 'glst', 'genres_fb2.glst')))
 
 if __name__ == '__main__':
     test()
index 0d4e73b6467d7e93bff7febe22e9622ad3b8e64b..6535d4559827ac37b7b4ffa36925f39604ff03b5 100755 (executable)
@@ -1,5 +1,6 @@
 #! /usr/bin/env python
 
+from __future__ import print_function
 import argparse
 from m_librarian.config import get_config
 from m_librarian.db import open_db, init_db
@@ -18,6 +19,6 @@ if __name__ == '__main__':
     init_db()
     old, new = import_glst()
     if old:
-        print "Imported %d genres (ignored %d existing)" % (new, old)
+        print("Imported %d genres (ignored %d existing)" % (new, old))
     else:
-        print "Imported %d genres" % new
+        print("Imported %d genres" % new)
index bd5df8cdf2341d0f2a619bf6d2be178a5d59aa12..1aad934555c609c773376dde5522a67f121c6e7d 100755 (executable)
@@ -1,5 +1,6 @@
 #! /usr/bin/env python
 
+from __future__ import print_function
 import argparse
 import sys
 from sqlobject.sqlbuilder import CONCAT
@@ -35,7 +36,7 @@ def _guess_case_sensitivity(values):
 
 
 def print_count(count):
-    print _("Found").encode(default_encoding), ":", count
+    print(_("Found").encode(default_encoding), ":", count)
 
 
 def _search_authors(case_sensitive, search_type, args):
@@ -63,11 +64,11 @@ def _search_authors(case_sensitive, search_type, args):
         return
     count = 0
     for author in authors:
-        print author.fullname.encode(default_encoding), \
-            (u"(%s: %d)" % (_('books'), author.count))\
-            .encode(default_encoding),
+        print(author.fullname.encode(default_encoding),
+            (u"(%s: %d)" % (_('books'), author.count))
+            .encode(default_encoding), end='')
         if args.verbose >= 1:
-            print "(id=%d)" % author.id,
+            print("(id=%d)" % author.id, end='')
         print
         count += 1
     print_count(count)
@@ -157,38 +158,38 @@ def _search_books(case_sensitive, search_type, args):
             sys.exit(1)
     count = 0
     for book in books:
-        print book.title.encode(default_encoding),
+        print(book.title.encode(default_encoding), end='')
         if args.verbose >= 1:
-            print "(id=%d)" % book.id,
+            print("(id=%d)" % book.id, end='')
         print
         if args.verbose >= 1:
-            print " ", _("Author(s)").encode(default_encoding), ":",
+            print(" ", _("Author(s)").encode(default_encoding), ":", end='')
             for author in book.authors:
-                print author.fullname.encode(default_encoding),
+                print(author.fullname.encode(default_encoding), end='')
             print
-            print " ", _("Genre(s)").encode(default_encoding), ":",
+            print(" ", _("Genre(s)").encode(default_encoding), ":", end='')
             for genre in book.genres:
-                print (genre.title or genre.name).encode(default_encoding),
+                print((genre.title or genre.name).encode(default_encoding), end='')
             print
             if book.series:
-                print " ", _("Series").encode(default_encoding), ":",
-                print book.series.encode(default_encoding), \
-                    "(%d)" % book.ser_no
+                print(" ", _("Series").encode(default_encoding), ":", end='')
+                print(book.series.encode(default_encoding),
+                    "(%d)" % book.ser_no)
 
         if args.verbose >= 2:
-            print " ", _("Date").encode(default_encoding), ":", book.date
-            print " ", _("Language").encode(default_encoding), ":", \
-                book.language.name.encode(default_encoding)
+            print(" ", _("Date").encode(default_encoding), ":", book.date)
+            print(" ", _("Language").encode(default_encoding), ":",
+                book.language.name.encode(default_encoding))
 
         if args.verbose >= 3:
-            print " ", _("Archive").encode(default_encoding), ":", book.archive
-            print " ", _("File").encode(default_encoding), ":", book.file
-            print " ", _("Extension").encode(default_encoding), ":", \
-                book.extension.name.encode(default_encoding)
-            print " ", _("Size").encode(default_encoding), ":", \
-                book.size, _("bytes").encode(default_encoding)
-            print " ", _("Deleted").encode(default_encoding), ":", \
-                _(str(book.deleted)).encode(default_encoding)
+            print(" ", _("Archive").encode(default_encoding), ":", book.archive)
+            print(" ", _("File").encode(default_encoding), ":", book.file)
+            print(" ", _("Extension").encode(default_encoding), ":",
+                book.extension.name.encode(default_encoding))
+            print(" ", _("Size").encode(default_encoding), ":",
+                book.size, _("bytes").encode(default_encoding))
+            print(" ", _("Deleted").encode(default_encoding), ":",
+                _(str(book.deleted)).encode(default_encoding))
         if args.get or args.get_many:
             download(book, args.path, args.format)
         count += 1
@@ -208,10 +209,11 @@ def _search_extensions(case_sensitive, search_type, args):
         return
     count = 0
     for ext in extensions:
-        print ext.name.encode(default_encoding), \
+        print(ext.name.encode(default_encoding),
             (u"(%s: %d)" % (_('books'), ext.count)).encode(default_encoding),
+            end='')
         if args.verbose >= 1:
-            print "(id=%d)" % ext.id,
+            print("(id=%d)" % ext.id, end='')
         print
         count += 1
     print_count(count)
@@ -229,10 +231,11 @@ def _search_genres(case_sensitive, search_type, args):
     for genre in genres:
         names = filter(None, (genre.name, genre.title))
         fullname = u' '.join(names)
-        print fullname.encode(default_encoding), \
+        print(fullname.encode(default_encoding),
             (u"(%s: %d)" % (_('books'), genre.count)).encode(default_encoding),
+            end='')
         if args.verbose >= 1:
-            print "(id=%d)" % genre.id,
+            print("(id=%d)" % genre.id, end='')
         print
         count += 1
     print_count(count)
@@ -251,10 +254,11 @@ def _search_languages(case_sensitive, search_type, args):
         return
     count = 0
     for lang in languages:
-        print lang.name.encode(default_encoding), \
+        print(lang.name.encode(default_encoding),
             (u"(%s: %d)" % (_('books'), lang.count)).encode(default_encoding),
+            end='')
         if args.verbose >= 1:
-            print "(id=%d)" % lang.id,
+            print("(id=%d)" % lang.id, end='')
         print
         count += 1
     print_count(count)
@@ -311,7 +315,7 @@ if __name__ == '__main__':
     parser.add_argument('--lid', type=int, help='search by language\'s id')
     parser.add_argument('-P', '--path', help='path to the library archives')
     parser.add_argument('-F', '--format',
-                        help='download format, default is %f')
+                        help='download format, default is %%f')
     parser.add_argument('--get', action='store_true',
                         help='download exactly one book')
     parser.add_argument('--get-many', type=int,
index e40219aa38a0010d0601a0ed32216206baf78abf..e55661f9673427fac81535862bee5987575a2d24 100644 (file)
@@ -29,7 +29,7 @@ class TestCase(unittest.TestCase):
 def main():
     try:
         unittest.main(testRunner=unittest.TextTestRunner())
-    except SystemExit, msg:
+    except SystemExit as msg:
         result = msg.args[0]
     else:
         result = 0
index 2e217bf31e814c42286fc7a96912fd53e6c3680b..c04d9ed372f2baa2a6b4ba2dc4b8ef0b58da7936 100755 (executable)
@@ -1,6 +1,7 @@
 #! /usr/bin/env python
 
 
+from __future__ import print_function
 import os
 import sys
 import subprocess
@@ -31,7 +32,7 @@ def main():
     os.environ["PYTHONPATH"] = os.curdir
 
     for test in sorted(tests):
-        print test
+        print(test)
         subprocess.call((sys.executable, '-m', test))
 
 if __name__ == '__main__':