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

« back to all changes in this revision

Viewing changes to src/calibre/ebooks/lrf/feeds/convert_from.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 at kovidgoyal.net>'
4
 
'''
5
 
Convert web feeds to LRF files.
6
 
'''
7
 
from calibre.ebooks.lrf import option_parser as lrf_option_parser
8
 
from calibre.ebooks.lrf.html.convert_from import process_file
9
 
from calibre.web.feeds.main import option_parser as feeds_option_parser
10
 
from calibre.web.feeds.main import run_recipe
11
 
from calibre.ptempfile import TemporaryDirectory
12
 
from calibre import sanitize_file_name, strftime
13
 
 
14
 
import sys, os
15
 
 
16
 
def option_parser():
17
 
    parser = feeds_option_parser()
18
 
    parser.remove_option('--output-dir')
19
 
    parser.remove_option('--lrf')
20
 
    parser.subsume('FEEDS2DISK OPTIONS', _('Options to control the behavior of feeds2disk'))
21
 
    lrf_parser = lrf_option_parser('')
22
 
    lrf_parser.subsume('HTML2LRF OPTIONS', _('Options to control the behavior of html2lrf'))
23
 
    parser.merge(lrf_parser)
24
 
    return parser
25
 
 
26
 
def main(args=sys.argv, notification=None, handler=None):
27
 
    parser = option_parser()
28
 
    opts, args = parser.parse_args(args)
29
 
    opts.lrf = True
30
 
    
31
 
    if len(args) != 2 and opts.feeds is None:
32
 
        parser.print_help()
33
 
        return 1
34
 
    
35
 
    recipe_arg = args[1] if len(args) > 1 else None
36
 
    
37
 
    with TemporaryDirectory('_feeds2lrf') as tdir:
38
 
        opts.output_dir = tdir
39
 
        
40
 
        recipe = run_recipe(opts, recipe_arg, parser, notification=notification, handler=handler)
41
 
        
42
 
        htmlfile = os.path.join(tdir, 'index.html')
43
 
        if not os.access(htmlfile, os.R_OK):
44
 
            raise RuntimeError(_('Fetching of recipe failed: ')+recipe_arg)
45
 
        
46
 
        lparser = lrf_option_parser('')
47
 
        ropts = lparser.parse_args(['html2lrf']+recipe.html2lrf_options)[0]
48
 
        parser.merge_options(ropts, opts)
49
 
        
50
 
        if not opts.output:
51
 
            ext = '.lrs' if opts.lrs else '.lrf'
52
 
            fname = recipe.title + strftime(recipe.timefmt)+ext
53
 
            opts.output = os.path.join(os.getcwd(), sanitize_file_name(fname))
54
 
        print 'Generating LRF...'
55
 
        process_file(htmlfile, opts)
56
 
    return 0
57
 
 
58
 
if __name__ == '__main__':
59
 
    sys.exit(main())