mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Allow passing importable file formats as arguments to ebook-edit
This commit is contained in:
parent
33a2a38cd7
commit
5081bb93f1
@ -15,6 +15,8 @@ from calibre.ebooks.epub import initialize_container
|
|||||||
|
|
||||||
from calibre.utils.logging import default_log
|
from calibre.utils.logging import default_log
|
||||||
|
|
||||||
|
IMPORTABLE = {'htm', 'xhtml', 'html', 'xhtm', 'docx'}
|
||||||
|
|
||||||
def auto_fill_manifest(container):
|
def auto_fill_manifest(container):
|
||||||
manifest_id_map = container.manifest_id_map
|
manifest_id_map = container.manifest_id_map
|
||||||
manifest_name_map = {v:k for k, v in manifest_id_map.iteritems()}
|
manifest_name_map = {v:k for k, v in manifest_id_map.iteritems()}
|
||||||
|
@ -167,10 +167,12 @@ class Boss(QObject):
|
|||||||
create_book(d.mi, path, fmt=fmt)
|
create_book(d.mi, path, fmt=fmt)
|
||||||
self.open_book(path=path)
|
self.open_book(path=path)
|
||||||
|
|
||||||
def import_book(self):
|
def import_book(self, path=None):
|
||||||
if not self._check_before_open():
|
if not self._check_before_open():
|
||||||
return
|
return
|
||||||
d = ImportForeign(self.gui)
|
d = ImportForeign(self.gui)
|
||||||
|
if hasattr(path, 'rstrip'):
|
||||||
|
d.set_src(os.path.abspath(path))
|
||||||
if d.exec_() == d.Accepted:
|
if d.exec_() == d.Accepted:
|
||||||
from calibre.ebooks.oeb.polish.import_book import import_book_as_epub
|
from calibre.ebooks.oeb.polish.import_book import import_book_as_epub
|
||||||
src, dest = d.data
|
src, dest = d.data
|
||||||
@ -192,6 +194,9 @@ class Boss(QObject):
|
|||||||
|
|
||||||
ext = path.rpartition('.')[-1].upper()
|
ext = path.rpartition('.')[-1].upper()
|
||||||
if ext not in SUPPORTED:
|
if ext not in SUPPORTED:
|
||||||
|
from calibre.ebooks.oeb.polish.import_book import IMPORTABLE
|
||||||
|
if ext.lower() in IMPORTABLE:
|
||||||
|
return self.import_book(path)
|
||||||
return error_dialog(self.gui, _('Unsupported format'),
|
return error_dialog(self.gui, _('Unsupported format'),
|
||||||
_('Tweaking is only supported for books in the %s formats.'
|
_('Tweaking is only supported for books in the %s formats.'
|
||||||
' Convert your book to one of these formats first.') % _(' and ').join(sorted(SUPPORTED)),
|
' Convert your book to one of these formats first.') % _(' and ').join(sorted(SUPPORTED)),
|
||||||
|
@ -189,10 +189,14 @@ class ImportForeign(Dialog): # {{{
|
|||||||
l.addRow(self.bb)
|
l.addRow(self.bb)
|
||||||
|
|
||||||
def choose_source(self):
|
def choose_source(self):
|
||||||
|
from calibre.ebooks.oeb.polish.import_book import IMPORTABLE
|
||||||
path = choose_files(self, 'edit-book-choose-file-to-import', _('Choose file'), filters=[
|
path = choose_files(self, 'edit-book-choose-file-to-import', _('Choose file'), filters=[
|
||||||
(_('HTML or DOCX files'), ['htm', 'html', 'xhtml', 'xhtm', 'docx'])], select_only_single_file=True)
|
(_('Importable files'), list(IMPORTABLE))], select_only_single_file=True)
|
||||||
if path:
|
if path:
|
||||||
self.src.setText(path[0])
|
self.set_src(path[0])
|
||||||
|
|
||||||
|
def set_src(self, path):
|
||||||
|
self.src.setText(path)
|
||||||
self.dest.setText(self.data[1])
|
self.dest.setText(self.data[1])
|
||||||
|
|
||||||
def choose_destination(self):
|
def choose_destination(self):
|
||||||
|
@ -549,11 +549,12 @@ class PostInstall:
|
|||||||
from calibre.utils.smtp import option_parser as smtp_op
|
from calibre.utils.smtp import option_parser as smtp_op
|
||||||
from calibre.library.server.main import option_parser as serv_op
|
from calibre.library.server.main import option_parser as serv_op
|
||||||
from calibre.ebooks.oeb.polish.main import option_parser as polish_op, SUPPORTED
|
from calibre.ebooks.oeb.polish.main import option_parser as polish_op, SUPPORTED
|
||||||
|
from calibre.ebooks.oeb.polish.import_book import IMPORTABLE
|
||||||
from calibre.debug import option_parser as debug_op
|
from calibre.debug import option_parser as debug_op
|
||||||
from calibre.ebooks import BOOK_EXTENSIONS
|
from calibre.ebooks import BOOK_EXTENSIONS
|
||||||
from calibre.customize.ui import available_input_formats
|
from calibre.customize.ui import available_input_formats
|
||||||
input_formats = sorted(all_input_formats())
|
input_formats = sorted(all_input_formats())
|
||||||
tweak_formats = sorted(x.lower() for x in SUPPORTED)
|
tweak_formats = sorted(x.lower() for x in SUPPORTED|IMPORTABLE)
|
||||||
zsh = ZshCompleter(self.opts)
|
zsh = ZshCompleter(self.opts)
|
||||||
bc = os.path.join(os.path.dirname(self.opts.staging_sharedir),
|
bc = os.path.join(os.path.dirname(self.opts.staging_sharedir),
|
||||||
'bash-completion')
|
'bash-completion')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user