+@task(ignore_result=True, rate_limit=settings.CATALOGUE_MOBI_RATE_LIMIT)
+def build_fb2(book_id, *args, **kwargs):
+ """(Re)builds the MOBI file for a book."""
+ from django.core.files import File
+ from catalogue.models import Book
+ from catalogue.utils import remove_zip
+
+ fb2 = Book.objects.get(pk=book_id).wldocument().as_fb2()
+ # Save the file in new instance. Building FB2 takes time and we don't want
+ # to overwrite any interim changes.
+ book = Book.objects.get(id=book_id)
+ book.fb2_file.save('%s.fb2' % book.slug,
+ File(open(fb2.get_filename())))
+
+ # remove zip with all mobi files
+ remove_zip(settings.ALL_FB2_ZIP)
+
+