~ubuntu-branches/ubuntu/karmic/calibre/karmic

« back to all changes in this revision

Viewing changes to src/calibre/ebooks/rb/output.py

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-07-30 12:49:41 UTC
  • mto: This revision was merged to the branch mainline in revision 13.
  • Revision ID: james.westby@ubuntu.com-20090730124941-kviipg9ypwgppulc
Tags: upstream-0.6.3+dfsg
ImportĀ upstreamĀ versionĀ 0.6.3+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
 
 
3
__license__ = 'GPL 3'
 
4
__copyright__ = '2009, John Schember <john@nachtimwald.com>'
 
5
__docformat__ = 'restructuredtext en'
 
6
 
 
7
import os
 
8
 
 
9
from calibre.customize.conversion import OutputFormatPlugin
 
10
from calibre.ebooks.rb.writer import RBWriter
 
11
 
 
12
class RBOutput(OutputFormatPlugin):
 
13
 
 
14
    name = 'RB Output'
 
15
    author = 'John Schember'
 
16
    file_type = 'rb'
 
17
 
 
18
    def convert(self, oeb_book, output_path, input_plugin, opts, log):
 
19
        close = False
 
20
        if not hasattr(output_path, 'write'):
 
21
            close = True
 
22
            if not os.path.exists(os.path.dirname(output_path)) and os.path.dirname(output_path) != '':
 
23
                os.makedirs(os.path.dirname(output_path))
 
24
            out_stream = open(output_path, 'wb')
 
25
        else:
 
26
            out_stream = output_path
 
27
 
 
28
        writer = RBWriter(opts, log)
 
29
 
 
30
        out_stream.seek(0)
 
31
        out_stream.truncate()
 
32
 
 
33
        writer.write_content(oeb_book, out_stream, oeb_book.metadata)
 
34
 
 
35
        if close:
 
36
            out_stream.close()