Pull from driver-dev

This commit is contained in:
Kovid Goyal 2009-06-17 21:53:30 -07:00
commit 0c34dc4870
13 changed files with 80 additions and 33 deletions

View File

@ -242,9 +242,9 @@ class KindleDXOutput(OutputProfile):
description = _('This profile is intended for the Amazon Kindle DX.') description = _('This profile is intended for the Amazon Kindle DX.')
# Screen size is a best guess # Screen size is a best guess
screen_size = (1200, 824) screen_size = (824, 1200)
dpi = 150.0 dpi = 150.0
comic_screen_size = (1180, 800) comic_screen_size = (775, 1128)
@classmethod @classmethod
def tags_to_string(cls, tags): def tags_to_string(cls, tags):

View File

@ -1,9 +1,12 @@
__license__ = 'GPL v3' __license__ = 'GPL v3'
__copyright__ = '2009, Tijmen Ruizendaal <tijmen at mybebook.com>' __copyright__ = '2009, Tijmen Ruizendaal <tijmen at mybebook.com>'
''' '''
Device driver for BeBook Device driver for BeBook
''' '''
import re
from calibre.devices.usbms.driver import USBMS from calibre.devices.usbms.driver import USBMS
class BEBOOK(USBMS): class BEBOOK(USBMS):
@ -24,8 +27,8 @@ class BEBOOK(USBMS):
WINDOWS_MAIN_MEM = 'FILE-STOR_GADGET' WINDOWS_MAIN_MEM = 'FILE-STOR_GADGET'
WINDOWS_CARD_A_MEM = 'FILE-STOR_GADGET' WINDOWS_CARD_A_MEM = 'FILE-STOR_GADGET'
OSX_MAIN_MEM = 'BeBook Internal Memory' OSX_MAIN_MEM = 'Linux File-Stor Gadget Media'
OSX_CARD_A_MEM = 'BeBook Storage Card' OSX_CARD_A_MEM = 'Linux File-Stor Gadget Media'
MAIN_MEMORY_VOLUME_LABEL = 'BeBook Internal Memory' MAIN_MEMORY_VOLUME_LABEL = 'BeBook Internal Memory'
STORAGE_CARD_VOLUME_LABEL = 'BeBook Storage Card' STORAGE_CARD_VOLUME_LABEL = 'BeBook Storage Card'
@ -41,8 +44,35 @@ class BEBOOK(USBMS):
drives['main'] = card drives['main'] = card
drives['carda'] = main drives['carda'] = main
if card and not main:
drives['main'] = card
drives['carda'] = None
return drives return drives
def osx_sort_names(self, names):
main = names.get('main', None)
card = names.get('carda', None)
try:
main_num = int(re.findall('\d+', main)[0]) if main else None
except:
main_num = None
try:
card_num = int(re.findall('\d+', card)[0]) if card else None
except:
card_num = None
if card_num is not None and main_num is not None and card_num < main_num:
names['main'] = card
names['carda'] = main
if card and not main:
names['main'] = card
names['carda'] = None
return names
def linux_swap_drives(self, drives): def linux_swap_drives(self, drives):
if len(drives) < 2: return drives if len(drives) < 2: return drives
drives = list(drives) drives = list(drives)

View File

@ -235,12 +235,13 @@ class Device(DeviceConfig, DevicePlugin):
wmi = __import__('wmi', globals(), locals(), [], -1) wmi = __import__('wmi', globals(), locals(), [], -1)
c = wmi.WMI(find_classes=False) c = wmi.WMI(find_classes=False)
for drive in c.Win32_DiskDrive(): for drive in c.Win32_DiskDrive():
if self.windows_match_device(drive, 'WINDOWS_CARD_A_MEM'): if self.windows_match_device(drive, 'WINDOWS_CARD_A_MEM') and not drives.get('carda', None):
drives['carda'] = self.windows_get_drive_prefix(drive) drives['carda'] = self.windows_get_drive_prefix(drive)
elif self.windows_match_device(drive, 'WINDOWS_CARD_B_MEM'): elif self.windows_match_device(drive, 'WINDOWS_CARD_B_MEM') and not drives.get('cardb', None):
drives['cardb'] = self.windows_get_drive_prefix(drive) drives['cardb'] = self.windows_get_drive_prefix(drive)
elif self.windows_match_device(drive, 'WINDOWS_MAIN_MEM'): elif self.windows_match_device(drive, 'WINDOWS_MAIN_MEM') and not drives.get('main', None):
drives['main'] = self.windows_get_drive_prefix(drive) drives['main'] = self.windows_get_drive_prefix(drive)
if 'main' in drives.keys() and 'carda' in drives.keys() and \ if 'main' in drives.keys() and 'carda' in drives.keys() and \
'cardb' in drives.keys(): 'cardb' in drives.keys():
break break
@ -265,6 +266,8 @@ class Device(DeviceConfig, DevicePlugin):
return subprocess.Popen((ioreg+' -w 0 -S -c IOMedia').split(), return subprocess.Popen((ioreg+' -w 0 -S -c IOMedia').split(),
stdout=subprocess.PIPE).communicate()[0] stdout=subprocess.PIPE).communicate()[0]
def osx_sort_names(self, names):
return names
def get_osx_mountpoints(self, raw=None): def get_osx_mountpoints(self, raw=None):
raw = self.run_ioreg(raw) raw = self.run_ioreg(raw)
@ -290,7 +293,7 @@ class Device(DeviceConfig, DevicePlugin):
get_dev_node(lines[i+1:], 'cardb') get_dev_node(lines[i+1:], 'cardb')
if len(names.keys()) == 3: if len(names.keys()) == 3:
break break
return names return self.osx_sort_names(names)
def open_osx(self): def open_osx(self):
mount = subprocess.Popen('mount', shell=True, stdout=subprocess.PIPE).stdout.read() mount = subprocess.Popen('mount', shell=True, stdout=subprocess.PIPE).stdout.read()

View File

@ -21,7 +21,7 @@ _span_pat = re.compile('<span.*?</span>', re.DOTALL|re.IGNORECASE)
def sanitize_head(match): def sanitize_head(match):
x = match.group(1) x = match.group(1)
x = _span_pat.sub('', x) x = _span_pat.sub('', x)
return '<head>\n'+x+'\n</head>' return '<head>\n%s\n</head>' % x
def chap_head(match): def chap_head(match):
chap = match.group('chap') chap = match.group('chap')
@ -84,7 +84,7 @@ class HTMLPreProcessor(object):
PREPROCESS = [ PREPROCESS = [
# Some idiotic HTML generators (Frontpage I'm looking at you) # Some idiotic HTML generators (Frontpage I'm looking at you)
# Put all sorts of crap into <head>. This messes up lxml # Put all sorts of crap into <head>. This messes up lxml
(re.compile(r'<head[^>]*>(.*?)</head>', re.IGNORECASE|re.DOTALL), (re.compile(r'<head[^>]*>\n*(.*?)\n*</head>', re.IGNORECASE|re.DOTALL),
sanitize_head), sanitize_head),
# Convert all entities, since lxml doesn't handle them well # Convert all entities, since lxml doesn't handle them well
(re.compile(r'&(\S+?);'), convert_entities), (re.compile(r'&(\S+?);'), convert_entities),
@ -130,7 +130,11 @@ class HTMLPreProcessor(object):
# Have paragraphs show better # Have paragraphs show better
(re.compile(r'<br.*?>'), lambda match : '<p>'), (re.compile(r'<br.*?>'), lambda match : '<p>'),
# Clean up spaces # Clean up spaces
(re.compile(u'(?<=[\.,:;\?!”"\'])[\s^ ]*(?=<)'), lambda match: ' '), (re.compile(u'(?<=[\.,;\?!”"\'])[\s^ ]*(?=<)'), lambda match: ' '),
# Connect paragraphs split by -
(re.compile(u'(?<=[^\s][-])[\s]*(</p>)*[\s]*(<p>)*\s*(?=[^\s])'), lambda match: ''),
# Remove - that splits words
(re.compile(u'(?<=[^\s])[-]+(?=[^\s])'), lambda match: ''),
# Add space before and after italics # Add space before and after italics
(re.compile(u'(?<!“)<i>'), lambda match: ' <i>'), (re.compile(u'(?<!“)<i>'), lambda match: ' <i>'),
(re.compile(r'</i>(?=\w)'), lambda match: '</i> '), (re.compile(r'</i>(?=\w)'), lambda match: '</i> '),

View File

@ -29,11 +29,7 @@ class MOBIOutput(OutputFormatPlugin):
), ),
OptionRecommendation(name='mobi_periodical', OptionRecommendation(name='mobi_periodical',
recommended_value=False, level=OptionRecommendation.LOW, recommended_value=False, level=OptionRecommendation.LOW,
help=_('When present, generate a periodical rather than a book.') help=_('Generate a periodical rather than a book.')
),
OptionRecommendation(name='no_mobi_index',
recommended_value=False, level=OptionRecommendation.LOW,
help=_('Disable generation of MOBI index.')
), ),
OptionRecommendation(name='dont_compress', OptionRecommendation(name='dont_compress',
recommended_value=False, level=OptionRecommendation.LOW, recommended_value=False, level=OptionRecommendation.LOW,

View File

@ -639,7 +639,6 @@ class MobiWriter(object):
self._text_nrecords = nrecords self._text_nrecords = nrecords
def _generate_indxt(self, ctoc): def _generate_indxt(self, ctoc):
if self.opts.mobi_periodical: if self.opts.mobi_periodical:
raise NotImplementedError('Indexing for periodicals not implemented') raise NotImplementedError('Indexing for periodicals not implemented')
toc = self._oeb.toc toc = self._oeb.toc

View File

@ -30,7 +30,7 @@ class PdbHeaderReader(object):
def name(self): def name(self):
self.stream.seek(0) self.stream.seek(0)
return self.stream.read(32).replace('\x00', '') return re.sub('[^-A-Za-z0-9]+', '', self.stream.read(32).replace('\x00', ''))
def full_section_info(self, number): def full_section_info(self, number):
if number not in range(0, self.num_sections): if number not in range(0, self.num_sections):
@ -66,7 +66,7 @@ class PdbHeaderBuilder(object):
def __init__(self, identity, title): def __init__(self, identity, title):
self.identity = identity.ljust(3, '\x00')[:8] self.identity = identity.ljust(3, '\x00')[:8]
self.title = re.sub('[^-A-Za-z0-9]+', '_', title).ljust(32, '\x00')[:32] self.title = re.sub('[^-A-Za-z0-9]+', '_', title).ljust(32, '\x00')[:32].encode('ascii', 'replace')
def build_header(self, section_lengths, out_stream): def build_header(self, section_lengths, out_stream):
''' '''

View File

@ -95,14 +95,13 @@ class BulkConfig(Config):
self.stack.setCurrentIndex(idx) self.stack.setCurrentIndex(idx)
def setup_output_formats(self, db, preferred_output_format): def setup_output_formats(self, db, preferred_output_format):
available_formats = '' if preferred_output_format:
available_formats = set([x.lower() for x in preferred_output_format = preferred_output_format.lower()
available_formats.split(',')])
output_formats = sorted(available_output_formats()) output_formats = sorted(available_output_formats())
output_formats.remove('oeb') output_formats.remove('oeb')
preferred_output_format = preferred_output_format if \ preferred_output_format = preferred_output_format if \
preferred_output_format in output_formats else \ preferred_output_format and preferred_output_format \
sort_formats_by_preference(output_formats, in output_formats else sort_formats_by_preference(output_formats,
OUTPUT_FORMAT_PREFERENCES)[0] OUTPUT_FORMAT_PREFERENCES)[0]
self.output_formats.addItems(list(map(QString, [x.upper() for x in self.output_formats.addItems(list(map(QString, [x.upper() for x in
output_formats]))) output_formats])))

View File

@ -18,7 +18,8 @@ class PluginWidget(Widget, Ui_Form):
def __init__(self, parent, get_option, get_help, db=None, book_id=None): def __init__(self, parent, get_option, get_help, db=None, book_id=None):
Widget.__init__(self, parent, 'mobi_output', Widget.__init__(self, parent, 'mobi_output',
['prefer_author_sort', 'rescale_images', 'toc_title'] ['prefer_author_sort', 'rescale_images', 'toc_title',
'dont_compress', 'mobi_periodical']
) )
self.db, self.book_id = db, book_id self.db, self.book_id = db, book_id
self.initialize_options(get_option, get_help, db, book_id) self.initialize_options(get_option, get_help, db, book_id)

View File

@ -41,7 +41,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="0"> <item row="5" column="0">
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
@ -54,6 +54,20 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="3" column="0">
<widget class="QCheckBox" name="opt_dont_compress">
<property name="text">
<string>Disable compression of the file contents</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QCheckBox" name="opt_mobi_periodical">
<property name="text">
<string>Generate a periodical rather than a book</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<resources/> <resources/>

View File

@ -153,7 +153,7 @@ class Config(ResizableDialog, Ui_Dialog):
except ImportError: except ImportError:
pass pass
input_widget = None input_widget = None
name = 'calibre.gui2.convert.%s' % self.plumber.input_plugin.name.lower().replace(' ', '_') name = self.plumber.input_plugin.name.lower().replace(' ', '_')
try: try:
input_widget = __import__('calibre.gui2.convert.'+name, input_widget = __import__('calibre.gui2.convert.'+name,
fromlist=[1]) fromlist=[1])

View File

@ -1,16 +1,19 @@
from __future__ import with_statement
__license__ = 'GPL v3' __license__ = 'GPL v3'
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>' __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
''' '''
The dialog used to edit meta information for a book as well as The dialog used to edit meta information for a book as well as
add/remove formats add/remove formats
''' '''
import os, time, traceback
import os
import re
import time
import traceback
from PyQt4.QtCore import SIGNAL, QObject, QCoreApplication, Qt, QTimer, QThread from PyQt4.QtCore import SIGNAL, QObject, QCoreApplication, Qt, QTimer, QThread
from PyQt4.QtGui import QPixmap, QListWidgetItem, QErrorMessage, QDialog, QCompleter from PyQt4.QtGui import QPixmap, QListWidgetItem, QErrorMessage, QDialog, QCompleter
from calibre.gui2 import qstring_to_unicode, error_dialog, file_icon_provider, \ from calibre.gui2 import qstring_to_unicode, error_dialog, file_icon_provider, \
choose_files, pixmap_to_data, choose_images, ResizableDialog choose_files, pixmap_to_data, choose_images, ResizableDialog
from calibre.gui2.dialogs.metadata_single_ui import Ui_MetadataSingleDialog from calibre.gui2.dialogs.metadata_single_ui import Ui_MetadataSingleDialog
@ -422,7 +425,7 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog):
def fetch_metadata(self): def fetch_metadata(self):
isbn = qstring_to_unicode(self.isbn.text()) isbn = re.sub(r'[^0-9a-zA-Z]', '', unicode(self.isbn.text()))
title = qstring_to_unicode(self.title.text()) title = qstring_to_unicode(self.title.text())
author = string_to_authors(unicode(self.authors.text()))[0] author = string_to_authors(unicode(self.authors.text()))[0]
publisher = qstring_to_unicode(self.publisher.currentText()) publisher = qstring_to_unicode(self.publisher.currentText())

View File

@ -344,8 +344,6 @@ class DetailView(QDialog, Ui_Dialog):
self.next_pos = f.tell() self.next_pos = f.tell()
if more: if more:
self.log.appendPlainText(more.decode('utf-8', 'replace')) self.log.appendPlainText(more.decode('utf-8', 'replace'))
vbar = self.log.verticalScrollBar()
vbar.setValue(vbar.maximum())
class JobsView(TableView): class JobsView(TableView):