fnp
/
librarian.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Limit image size, fixes #4464.
[librarian.git]
/
src
/
librarian
/
book2anything.py
diff --git
a/src/librarian/book2anything.py
b/src/librarian/book2anything.py
old mode 100755
(executable)
new mode 100644
(file)
index
d954ce6
..
b9e2a33
--- a/
src/librarian/book2anything.py
+++ b/
src/librarian/book2anything.py
@@
-1,20
+1,14
@@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-#
# This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
# This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
-# Copyright © Fundacja
Nowoczesna Polska
. See NOTICE for more information.
+# Copyright © Fundacja
Wolne Lektury
. See NOTICE for more information.
#
#
-from __future__ import print_function, unicode_literals
-
import os.path
import optparse
import os.path
import optparse
-import six
from librarian import DirDocProvider, ParseError
from librarian.parser import WLDocument
from librarian import DirDocProvider, ParseError
from librarian.parser import WLDocument
-from librarian.cover import make_cover
+from librarian.cover import make_cover
, COVER_CLASSES
-class Option
(object)
:
+class Option:
"""Option for optparse. Use it like `optparse.OptionParser.add_option`."""
def __init__(self, *names, **options):
self.names = names
"""Option for optparse. Use it like `optparse.OptionParser.add_option`."""
def __init__(self, *names, **options):
self.names = names
@@
-30,7
+24,7
@@
class Option(object):
return getattr(options, self.name())
return getattr(options, self.name())
-class Book2Anything
(object)
:
+class Book2Anything:
"""A class for creating book2... scripts.
Subclass it for any format you want to convert to.
"""A class for creating book2... scripts.
Subclass it for any format you want to convert to.
@@
-82,6
+76,10
@@
class Book2Anything(object):
help='prefix for image download cache'
+ (' (implies --with-cover)' if cls.cover_optional else '')
)
help='prefix for image download cache'
+ (' (implies --with-cover)' if cls.cover_optional else '')
)
+ parser.add_option(
+ '--cover-class', dest='cover_class',
+ help='cover class name'
+ )
for option in (
cls.parser_options
+ cls.transform_options
for option in (
cls.parser_options
+ cls.transform_options
@@
-118,11
+116,14
@@
class Book2Anything(object):
def cover_class(book_info, *args, **kwargs):
return make_cover(
book_info, image_cache=options.image_cache,
def cover_class(book_info, *args, **kwargs):
return make_cover(
book_info, image_cache=options.image_cache,
+ cover_class=options.cover_class,
*args, **kwargs
)
transform_args['cover'] = cover_class
elif not cls.cover_optional or options.with_cover:
*args, **kwargs
)
transform_args['cover'] = cover_class
elif not cls.cover_optional or options.with_cover:
- transform_args['cover'] = make_cover
+ cover_class = COVER_CLASSES.get(
+ options.cover_class, make_cover)
+ transform_args['cover'] = cover_class
# Do some real work
try:
# Do some real work
try:
@@
-130,7
+131,7
@@
class Book2Anything(object):
if options.verbose:
print(main_input)
if options.verbose:
print(main_input)
- if isinstance(main_input,
six.binary_type
):
+ if isinstance(main_input,
bytes
):
main_input = main_input.decode('utf-8')
# Where to find input?
main_input = main_input.decode('utf-8')
# Where to find input?