- # read metadata from the first file
- if file_path:
- if slug:
- raise ValueError('slug or file_path should be specified, not both')
- f = open(file_path, 'r')
- input_xml = etree.parse(f)
- f.close()
- else:
- if not slug:
- raise ValueError('either slug or file_path should be specified')
- input_xml = etree.parse(provider[slug])
-
- metadata = input_xml.find('.//'+RDFNS('Description'))
- if metadata is None:
- raise NoDublinCore('Document has no DublinCore - which is required.')
- book_info = BookInfo.from_element(input_xml)
-
- # if output to dir, create the file
- if output_dir is not None:
- if make_dir:
- author = unicode(book_info.author)
- output_dir = os.path.join(output_dir, author)
- try:
- os.makedirs(output_dir)
- except OSError:
- pass
- if slug:
- output_file = os.path.join(output_dir, '%s.mobi' % slug)
- else:
- output_file = os.path.join(output_dir, os.path.splitext(os.path.basename(file_path))[0] + '.mobi')
-
- # provide a cover by default
- if not cover:
- cover = WLCover
- cover_file = NamedTemporaryFile(suffix='.png', delete=False)
- c = cover(book_info.author.readable(), book_info.title)
- c.save(cover_file)
-
- epub_file = NamedTemporaryFile(suffix='.epub', delete=False)
- if not flags:
- flags = []
- flags = list(flags) + ['without-fonts']
- epub.transform(provider, file_path=file_path, output_file=epub_file, verbose=verbose,
- sample=sample, html_toc=True, flags=flags, style=get_resource('mobi/style.css'))