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.')
# Screen size is a best guess
screen_size = (1200, 824)
screen_size = (824, 1200)
dpi = 150.0
comic_screen_size = (1180, 800)
comic_screen_size = (775, 1128)
@classmethod
def tags_to_string(cls, tags):

View File

@ -1,9 +1,12 @@
__license__ = 'GPL v3'
__copyright__ = '2009, Tijmen Ruizendaal <tijmen at mybebook.com>'
'''
Device driver for BeBook
'''
import re
from calibre.devices.usbms.driver import USBMS
class BEBOOK(USBMS):
@ -24,8 +27,8 @@ class BEBOOK(USBMS):
WINDOWS_MAIN_MEM = 'FILE-STOR_GADGET'
WINDOWS_CARD_A_MEM = 'FILE-STOR_GADGET'
OSX_MAIN_MEM = 'BeBook Internal Memory'
OSX_CARD_A_MEM = 'BeBook Storage Card'
OSX_MAIN_MEM = 'Linux File-Stor Gadget Media'
OSX_CARD_A_MEM = 'Linux File-Stor Gadget Media'
MAIN_MEMORY_VOLUME_LABEL = 'BeBook Internal Memory'
STORAGE_CARD_VOLUME_LABEL = 'BeBook Storage Card'
@ -41,8 +44,35 @@ class BEBOOK(USBMS):
drives['main'] = card
drives['carda'] = main
if card and not main:
drives['main'] = card
drives['carda'] = None
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):
if len(drives) < 2: return drives
drives = list(drives)

View File

@ -235,12 +235,13 @@ class Device(DeviceConfig, DevicePlugin):
wmi = __import__('wmi', globals(), locals(), [], -1)
c = wmi.WMI(find_classes=False)
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)
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)
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)
if 'main' in drives.keys() and 'carda' in drives.keys() and \
'cardb' in drives.keys():
break
@ -265,6 +266,8 @@ class Device(DeviceConfig, DevicePlugin):
return subprocess.Popen((ioreg+' -w 0 -S -c IOMedia').split(),
stdout=subprocess.PIPE).communicate()[0]
def osx_sort_names(self, names):
return names
def get_osx_mountpoints(self, raw=None):
raw = self.run_ioreg(raw)
@ -290,7 +293,7 @@ class Device(DeviceConfig, DevicePlugin):
get_dev_node(lines[i+1:], 'cardb')
if len(names.keys()) == 3:
break
return names
return self.osx_sort_names(names)
def open_osx(self):
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):
x = match.group(1)
x = _span_pat.sub('', x)
return '<head>\n'+x+'\n</head>'
return '<head>\n%s\n</head>' % x
def chap_head(match):
chap = match.group('chap')
@ -84,7 +84,7 @@ class HTMLPreProcessor(object):
PREPROCESS = [
# Some idiotic HTML generators (Frontpage I'm looking at you)
# 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),
# Convert all entities, since lxml doesn't handle them well
(re.compile(r'&(\S+?);'), convert_entities),
@ -130,7 +130,11 @@ class HTMLPreProcessor(object):
# Have paragraphs show better
(re.compile(r'<br.*?>'), lambda match : '<p>'),
# 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
(re.compile(u'(?<!“)<i>'), lambda match: ' <i>'),
(re.compile(r'</i>(?=\w)'), lambda match: '</i> '),

View File

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

View File

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

View File

@ -30,7 +30,7 @@ class PdbHeaderReader(object):
def name(self):
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):
if number not in range(0, self.num_sections):
@ -66,7 +66,7 @@ class PdbHeaderBuilder(object):
def __init__(self, identity, title):
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):
'''

View File

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

View File

@ -41,7 +41,7 @@
</property>
</widget>
</item>
<item row="3" column="0">
<item row="5" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
@ -54,6 +54,20 @@
</property>
</spacer>
</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>
</widget>
<resources/>

View File

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

View File

@ -1,16 +1,19 @@
from __future__ import with_statement
__license__ = 'GPL v3'
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
'''
The dialog used to edit meta information for a book as well as
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.QtGui import QPixmap, QListWidgetItem, QErrorMessage, QDialog, QCompleter
from calibre.gui2 import qstring_to_unicode, error_dialog, file_icon_provider, \
choose_files, pixmap_to_data, choose_images, ResizableDialog
from calibre.gui2.dialogs.metadata_single_ui import Ui_MetadataSingleDialog
@ -422,7 +425,7 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog):
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())
author = string_to_authors(unicode(self.authors.text()))[0]
publisher = qstring_to_unicode(self.publisher.currentText())

View File

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