+ # Import book files
+ try:
+ book = Book.from_xml_file(file_path, overwrite=force)
+ files_imported += 1
+
+ if os.path.isfile(file_base + '.pdf'):
+ book.pdf_file.save('%s.pdf' % book.slug, File(file(file_base + '.pdf')))
+ if verbose:
+ print "Importing %s.pdf" % file_base
+ if os.path.isfile(file_base + '.odt'):
+ book.odt_file.save('%s.odt' % book.slug, File(file(file_base + '.odt')))
+ if verbose:
+ print "Importing %s.odt" % file_base
+ if os.path.isfile(file_base + '.txt'):
+ book.txt_file.save('%s.txt' % book.slug, File(file(file_base + '.txt')))
+ if verbose:
+ print "Importing %s.txt" % file_base
+
+ book.save()
+
+ except Book.AlreadyExists, msg:
+ print self.style.ERROR('%s: Book already imported. Skipping. To overwrite use --force.' %
+ file_path)
+ files_skipped += 1
+
+ # Print results
+ print
+ print "Results: %d files imported, %d skipped, %d total." % (
+ files_imported, files_skipped, files_imported + files_skipped)
+ print
+