- # 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')