def import_book(self, file_path, options):
verbose = options.get('verbose')
+ if options.get('dont_build'):
+ dont_build = options.get('dont_build').lower().split(',')
+ else:
+ dont_build = None
file_base, ext = os.path.splitext(file_path)
book = Book.from_xml_file(file_path, overwrite=options.get('force'),
- build_epub=options.get('build_epub'),
- build_txt=options.get('build_txt'),
- build_pdf=options.get('build_pdf'),
- build_mobi=options.get('build_mobi'),
- search_index_tags=False)
+ dont_build=dont_build,
- search_index=options.get('search_index'),
- search_index_reuse=True,
+ search_index_tags=False)
for ebook_format in Book.ebook_formats:
if os.path.isfile(file_base + '.' + ebook_format):
getattr(book, '%s_file' % ebook_format).save(
@classmethod
def from_text_and_meta(cls, raw_file, book_info, overwrite=False,
- build_epub=True, build_txt=True, build_pdf=True, build_mobi=True, build_fb2=True,
- search_index=True, search_index_tags=True):
+ dont_build=None, search_index=True,
- search_index_tags=True, search_index_reuse=False):
++ search_index_tags=True):
+ if dont_build is None:
+ dont_build = set()
+ dont_build = set.union(set(dont_build), set(app_settings.DONT_BUILD))
# check for parts before we do anything
children = []
# delete old fragments when overwriting
book.fragments.all().delete()
-
- if book.build_html():
- # No direct saves behind this point.
- if not settings.NO_BUILD_TXT and build_txt:
- book.build_txt()
-
- if not settings.NO_BUILD_EPUB and build_epub:
- book.build_epub()
-
- if not settings.NO_BUILD_PDF and build_pdf:
- book.build_pdf()
-
- if not settings.NO_BUILD_MOBI and build_mobi:
- book.build_mobi()
-
- if not settings.NO_BUILD_FB2 and build_fb2:
- book.build_fb2()
+ # Build HTML, fix the tree tags, build cover.
+ has_own_text = bool(book.html_file.build())
+ tasks.fix_tree_tags.delay(book)
+ if 'cover' not in dont_build:
+ book.cover.build_delay()
+
+ # No saves behind this point.
+
+ if has_own_text:
+ for format_ in constants.EBOOK_FORMATS_WITHOUT_CHILDREN:
+ if format_ not in dont_build:
+ getattr(book, '%s_file' % format_).build_delay()
+ for format_ in constants.EBOOK_FORMATS_WITH_CHILDREN:
+ if format_ not in dont_build:
+ getattr(book, '%s_file' % format_).build_delay()
if not settings.NO_SEARCH_INDEX and search_index:
- book.search_index(index_tags=search_index_tags, reuse_index=search_index_reuse)
- #index_book.delay(book.id, book_info)
+ tasks.index_book.delay(book.id, book_info=book_info, index_tags=search_index_tags)
- tasks.fix_tree_tags.delay(book)
+ for child in notify_cover_changed:
+ child.parent_cover_changed()
+
cls.published.send(sender=book)
return book