Fix transform_abstracy + tests.
[librarian.git] / librarian / book2anything.py
index 0dcfd33..948d9fd 100755 (executable)
@@ -4,12 +4,14 @@
 # This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
 #
+from __future__ import print_function, unicode_literals
+
 import os.path
 import optparse
-
+import six
 from librarian import DirDocProvider, ParseError
 from librarian.parser import WLDocument
-from librarian.cover import DefaultEbookCover
+from librarian.cover import make_cover
 
 
 class Option(object):
@@ -92,17 +94,20 @@ class Book2Anything(object):
         # Add cover support, if any.
         if cls.uses_cover:
             if options.image_cache:
-                def cover_class(*args, **kwargs):
-                    return DefaultEbookCover(image_cache=options.image_cache, *args, **kwargs)
+                def cover_class(book_info, *args, **kwargs):
+                    return make_cover(book_info, image_cache=options.image_cache, *args, **kwargs)
                 transform_args['cover'] = cover_class
             elif not cls.cover_optional or options.with_cover:
-                transform_args['cover'] = DefaultEbookCover
+                transform_args['cover'] = make_cover
 
         # Do some real work
         try:
             for main_input in input_filenames:
                 if options.verbose:
-                    print main_input
+                    print(main_input)
+
+            if isinstance(main_input, six.binary_type):
+                main_input = main_input.decode('utf-8')
 
             # Where to find input?
             if cls.uses_provider:
@@ -126,9 +131,9 @@ class Book2Anything(object):
 
             doc.save_output_file(output, output_file, options.output_dir, options.make_dir, cls.ext)
 
-        except ParseError, e:
-            print '%(file)s:%(name)s:%(message)s' % {
+        except ParseError as e:
+            print('%(file)s:%(name)s:%(message)s' % {
                 'file': main_input,
                 'name': e.__class__.__name__,
                 'message': e
-            }
+            })