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

« back to all changes in this revision

Viewing changes to src/calibre/ebooks/epub/from_feeds.py

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-07-30 12:49:41 UTC
  • mfrom: (1.3.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090730124941-qjdsmri25zt8zocn
Tags: 0.6.3+dfsg-0ubuntu1
* New upstream release. Please see http://calibre.kovidgoyal.net/new_in_6/
  for the list of new features and changes.
* remove_postinstall.patch: Update for new version.
* build_debug.patch: Does not apply any more, disable for now. Might not be
  necessary any more.
* debian/copyright: Fix reference to versionless GPL.
* debian/rules: Drop obsolete dh_desktop call.
* debian/rules: Add workaround for weird Python 2.6 setuptools behaviour of
  putting compiled .so files into src/calibre/plugins/calibre/plugins
  instead of src/calibre/plugins.
* debian/rules: Drop hal fdi moving, new upstream version does not use hal
  any more. Drop hal dependency, too.
* debian/rules: Install udev rules into /lib/udev/rules.d.
* Add debian/calibre.preinst: Remove unmodified
  /etc/udev/rules.d/95-calibre.rules on upgrade.
* debian/control: Bump Python dependencies to 2.6, since upstream needs
  it now.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from __future__ import with_statement
2
 
__license__   = 'GPL v3'
3
 
__copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net'
4
 
__docformat__ = 'restructuredtext en'
5
 
 
6
 
'''
7
 
Convert periodical content into EPUB ebooks.
8
 
'''
9
 
import sys, glob, os
10
 
from calibre.web.feeds.main import config as feeds2disk_config, USAGE, run_recipe
11
 
from calibre.ebooks.epub.from_html import config as html2epub_config
12
 
from calibre.ptempfile import TemporaryDirectory
13
 
from calibre.ebooks.epub.from_html import convert as html2epub
14
 
from calibre import strftime, sanitize_file_name
15
 
 
16
 
def config(defaults=None):
17
 
    c = feeds2disk_config(defaults=defaults)
18
 
    c.remove('lrf')
19
 
    c.remove('epub')
20
 
    c.remove('output_dir')
21
 
    c.update(html2epub_config(defaults=defaults))
22
 
    c.remove('chapter_mark')
23
 
    return c
24
 
 
25
 
def option_parser():
26
 
    c = config()
27
 
    return c.option_parser(usage=USAGE)
28
 
 
29
 
def convert(opts, recipe_arg, notification=None):
30
 
    opts.lrf  = False
31
 
    opts.epub = True
32
 
    if opts.debug:
33
 
        opts.verbose = 2
34
 
    parser = option_parser()
35
 
    with TemporaryDirectory('_feeds2epub') as tdir:
36
 
        opts.output_dir = tdir
37
 
        recipe = run_recipe(opts, recipe_arg, parser, notification=notification)
38
 
        c = config()
39
 
        recipe_opts = c.parse_string(recipe.html2epub_options)
40
 
        c.smart_update(recipe_opts, opts)
41
 
        opts = recipe_opts
42
 
        opts.chapter_mark = 'none'
43
 
        opts.dont_split_on_page_breaks = True
44
 
        opf = glob.glob(os.path.join(tdir, '*.opf'))
45
 
        if not opf:
46
 
            raise Exception('Downloading of recipe: %s failed'%recipe_arg)
47
 
        opf = opf[0]
48
 
        
49
 
        if opts.output is None:
50
 
            fname = recipe.title + strftime(recipe.timefmt) + '.epub'
51
 
            opts.output = os.path.join(os.getcwd(), sanitize_file_name(fname))
52
 
        
53
 
        print 'Generating epub...'
54
 
        opts.encoding = 'utf-8'
55
 
        opts.remove_paragraph_spacing = True
56
 
        html2epub(opf, opts, notification=notification)
57
 
    
58
 
 
59
 
def main(args=sys.argv, notification=None, handler=None):
60
 
    parser = option_parser()
61
 
    opts, args = parser.parse_args(args)
62
 
    if len(args) != 2 and opts.feeds is None:
63
 
        parser.print_help()
64
 
        return 1
65
 
    recipe_arg = args[1] if len(args) > 1 else None
66
 
    convert(opts, recipe_arg, notification=notification)
67
 
        
68
 
    return 0
69
 
 
70
 
if __name__ == '__main__':
71
 
    sys.exit(main())
 
 
b'\\ No newline at end of file'