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

« back to all changes in this revision

Viewing changes to src/calibre/ebooks/metadata/lit.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:
4
4
Support for reading the metadata from a LIT file.
5
5
'''
6
6
 
7
 
import sys, cStringIO, os
 
7
import cStringIO, os
8
8
 
9
9
from calibre.ebooks.metadata import MetaInformation
10
10
from calibre.ebooks.metadata.opf2 import OPF
11
 
from calibre.ebooks.lit.reader import LitReader
12
11
 
13
12
def get_metadata(stream):
14
 
    litfile = LitReader(stream)
15
 
    src = litfile.meta.encode('utf-8')
 
13
    from calibre.ebooks.lit.reader import LitContainer
 
14
    from calibre.utils.logging import Log
 
15
    litfile = LitContainer(stream, Log())
 
16
    src = litfile.get_metadata().encode('utf-8')
 
17
    litfile = litfile._litfile
16
18
    opf = OPF(cStringIO.StringIO(src), os.getcwd())
17
19
    mi = MetaInformation(opf)
18
20
    covers = []
38
40
    mi.cover_data = ('jpg', covers[idx][0])
39
41
    return mi
40
42
 
41
 
def main(args=sys.argv):
42
 
    if len(args) != 2:
43
 
        print >>sys.stderr, _('Usage: %s file.lit') % args[0]
44
 
        return 1
45
 
    fname = args[1]
46
 
    mi = get_metadata(open(fname, 'rb'))
47
 
    print unicode(mi)
48
 
    if mi.cover_data[1]:
49
 
        cover = os.path.abspath(
50
 
            '.'.join((os.path.splitext(os.path.basename(fname))[0],
51
 
                      mi.cover_data[0])))
52
 
        open(cover, 'wb').write(mi.cover_data[1])
53
 
        print _('Cover saved to'), cover
54
 
    return 0
55
 
 
56
 
if __name__ == '__main__':
57
 
    sys.exit(main())
58