Sync to Trunk

This commit is contained in:
John Schember 2009-06-04 06:16:37 -04:00
commit d7015bdf36
10 changed files with 62 additions and 11 deletions

View File

@ -19,7 +19,7 @@ from modulegraph.find_modules import find_modules
PYTHON = '/Library/Frameworks/Python.framework/Versions/Current/bin/python'
class BuildAPP(py2app):
QT_PREFIX = '/Users/kovid/qt'
QT_PREFIX = '/Volumes/sw/qt'
LOADER_TEMPLATE = \
r'''#!/usr/bin/env python
import os, sys, glob

View File

@ -181,6 +181,10 @@ class MetadataReaderPlugin(Plugin):
type = _('Metadata reader')
def __init__(self, *args, **kwargs):
Plugin.__init__(self, *args, **kwargs)
self.quick = False
def get_metadata(self, stream, type):
'''
Return metadata for the file represented by stream (a file like object

View File

@ -182,7 +182,9 @@ class PDFMetadataReader(MetadataReaderPlugin):
description = _('Read metadata from %s files')%'PDF'
def get_metadata(self, stream, ftype):
from calibre.ebooks.metadata.pdf import get_metadata
from calibre.ebooks.metadata.pdf import get_metadata, get_quick_metadata
if self.quick:
return get_quick_metadata(stream)
return get_metadata(stream)
class RARMetadataReader(MetadataReaderPlugin):

View File

@ -145,6 +145,20 @@ def metadata_writers():
ans.add(plugin)
return ans
class QuickMetadata(object):
def __init__(self):
self.quick = False
def __enter__(self):
self.quick = True
def __exit__(self, *args):
self.quick = False
quick_metadata = QuickMetadata()
def get_file_type_metadata(stream, ftype):
mi = MetaInformation(None, None)
ftype = ftype.lower().strip()
@ -153,6 +167,7 @@ def get_file_type_metadata(stream, ftype):
if not is_disabled(plugin):
with plugin:
try:
plugin.quick = quick_metadata.quick
mi = plugin.get_metadata(stream, ftype.lower().strip())
break
except:

View File

@ -110,8 +110,7 @@ class JETBOOK(USBMS):
return txt
from calibre.devices.usbms.driver import metadata_from_formats
mi = metadata_from_formats([path])
mi = cls.metadata_from_formats([path])
if (mi.title==_('Unknown') or mi.authors==[_('Unknown')]) \
and '#' in mi.title:

View File

@ -53,8 +53,7 @@ class KINDLE(USBMS):
@classmethod
def metadata_from_path(cls, path):
from calibre.ebooks.metadata.meta import metadata_from_formats
mi = metadata_from_formats([path])
mi = cls.metadata_from_formats([path])
if mi.title == _('Unknown') or ('-asin' in mi.title and '-type' in mi.title):
match = cls.WIRELESS_FILE_NAME_PATTERN.match(os.path.basename(path))
if match is not None:

View File

@ -376,13 +376,14 @@ class Device(DeviceConfig, DevicePlugin):
def node_mountpoint(self, node):
def de_octal(raw):
return re.sub(r'\\0\d+', lambda m: chr(int(m.group()[1:], 8)), raw)
def de_mangle(raw):
return raw.replace('\\040', ' ').replace('\\011', '\t').replace('\\012',
'\n').replace('\\0134', '\\')
for line in open('/proc/mounts').readlines():
line = line.split()
if line[0] == node:
return de_octal(line[1])
return de_mangle(line[1])
return None
def find_largest_partition(self, path):

View File

@ -211,8 +211,15 @@ class USBMS(CLI, Device):
@classmethod
def metadata_from_path(cls, path):
return cls.metadata_from_formats([path])
@classmethod
def metadata_from_formats(cls, fmts):
from calibre.ebooks.metadata.meta import metadata_from_formats
return metadata_from_formats([path])
from calibre.customize.ui import quick_metadata
with quick_metadata:
return metadata_from_formats(fmts)
@classmethod
def book_from_path(cls, path):

View File

@ -18,7 +18,16 @@ except:
from calibre.ebooks.metadata import MetaInformation, authors_to_string
from calibre.utils.pdftk import set_metadata as pdftk_set_metadata
from calibre.utils.podofo import get_metadata as podofo_get_metadata, \
set_metadata as podofo_set_metadata, Unavailable, write_first_page
set_metadata as podofo_set_metadata, Unavailable, write_first_page, \
get_metadata_quick
def get_quick_metadata(stream):
raw = stream.read()
mi = get_metadata_quick(raw)
if mi.title == '_':
mi.title = getattr(stream, 'name', _('Unknown'))
mi.title = mi.title.rpartition('.')[0]
return mi
def get_metadata(stream, extract_cover=True):

View File

@ -80,6 +80,21 @@ def get_metadata(stream):
if os.path.exists(pt.name): os.remove(pt.name)
return mi
def get_metadata_quick(raw):
p = podofo.PDFDoc()
p.load(raw)
title = p.title
if not title:
title = '_'
author = p.author
authors = string_to_authors(author) if author else [_('Unknown')]
creator = p.creator
mi = MetaInformation(title, authors)
if creator:
mi.book_producer = creator
return mi
def get_metadata_(path):
p = podofo.PDFDoc()
p.open(path)