diff --git a/src/calibre/ebooks/metadata/pml.py b/src/calibre/ebooks/metadata/pml.py index dff791cb0b..499cf75d2c 100644 --- a/src/calibre/ebooks/metadata/pml.py +++ b/src/calibre/ebooks/metadata/pml.py @@ -1,9 +1,13 @@ -'''Read meta information from TXT files''' - -from __future__ import with_statement +# -*- coding: utf-8 -*- __license__ = 'GPL v3' __copyright__ = '2009, John Schember ' +__docformat__ = 'restructuredtext en' + +''' +Read meta information from TXT files +''' + import os import glob @@ -57,20 +61,15 @@ def get_metadata(stream, extract_cover=True): return mi def get_cover(name, tdir, top_level=False): - cover_path = [] + cover_path = '' cover_data = None if top_level: - cover_path = glob.glob(os.path.join(tdir, 'cover.png')) - # Images not in top level try bookname_img directory because - # that's where Dropbook likes to see them. + cover_path = os.path.join(tdir, 'cover.png') if os.path.exists(os.path.join(tdir, 'cover.png')) else '' if not cover_path: - cover_path = glob.glob(os.path.join(tdir, name + '_img', 'cover.png')) - # No images in Dropbook location try generic images directory - if not cover_path: - cover_path = glob.glob(os.path.join(os.path.join(tdir, 'images'), 'cover.png')) + cover_path = os.path.join(tdir, name + '_img', 'cover.png') if os.path.exists(os.path.join(tdir, name + '_img', 'cover.png')) else os.path.join(os.path.join(tdir, 'images'), 'cover.png') if os.path.exists(os.path.join(os.path.join(tdir, 'images'), 'cover.png')) else '' if cover_path: - with open(cover_path[0], 'r+b') as cstream: + with open(cover_path, 'r+b') as cstream: cover_data = cstream.read() return ('png', cover_data)