+ else:
+ sys.stdout.write('.')
+ sys.stdout.flush()
+
+ # Import book files
+ try:
+ book = Book.from_xml_file(file_path, overwrite=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'))
+ files_imported += 1
+
+ for ebook_format in Book.ebook_formats:
+ if os.path.isfile(file_base + '.' + ebook_format):
+ getattr(book, '%s_file' % ebook_format).save(
+ '%s.%s' % (book.slug, ebook_format),
+ File(file(file_base + '.' + ebook_format)))
+ if verbose:
+ print "Importing %s.%s" % (file_base, ebook_format)
+
+ book.save()
+
+ except Book.AlreadyExists, msg:
+ print self.style.ERROR('%s: Book already imported. Skipping. To overwrite use --force.' %
+ file_path)
+ files_skipped += 1
+
+ except Book.DoesNotExist, e:
+ if file_name not in postponed or postponed[file_name] < files_imported:
+ # push it back into the queue, maybe the missing child will show up
+ if verbose:
+ print self.style.NOTICE('Waiting for missing children')
+ files.append(file_name)
+ postponed[file_name] = files_imported
+ else:
+ # we're in a loop, nothing's being imported - some child is really missing
+ raise e
+
+ # Print results
+ print
+ print "Results: %d files imported, %d skipped, %d total." % (
+ files_imported, files_skipped, files_imported + files_skipped)
+ print
+
+ if wait_until:
+ print 'Waiting...'
+ try:
+ time.sleep(wait_until - time.time())
+ except IOError:
+ print "it's already too late"
+