Skip to content

Commit

Permalink
Update to version 1.13.0
Browse files Browse the repository at this point in the history
Update: Changes for Python 3 support in calibre.
Update: Internal changes to how dialogs are handled.
  • Loading branch information
davidfor committed Oct 18, 2020
1 parent 36cf7d2 commit 2617b2e
Show file tree
Hide file tree
Showing 19 changed files with 312 additions and 166 deletions.
4 changes: 2 additions & 2 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
print_function)

__license__ = 'GPL v3'
__copyright__ = '2013-2019, David Forrester <[email protected]>'
__copyright__ = '2013-2020, David Forrester <[email protected]>'
__docformat__ = 'restructuredtext en'

from calibre.customize import InterfaceActionBase
Expand All @@ -13,7 +13,7 @@ class AnnotationsPlugin(InterfaceActionBase):
description = 'Import annotations'
supported_platforms = ['linux', 'osx', 'windows']
author = 'David Forrester'
version = (1, 12, 0)
version = (1, 13, 0)
minimum_calibre_version = (1, 0, 0)

actual_plugin = 'calibre_plugins.annotations.action:AnnotationsAction'
Expand Down
4 changes: 4 additions & 0 deletions about.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
Version history:
1.13.0 - 18 October 2020
• Update: Changes for Python 3 support in calibre.
• Update: Internal changes to how dialogs are handled.

1.12.0 - 08 January 2020
• Fix: Errors fetching from Kobo devices if the dates in the database were null.

Expand Down
32 changes: 21 additions & 11 deletions action.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@
print_function)

__license__ = 'GPL v3'
__copyright__ = '2013, Greg Riker <[email protected]>, 2014-2019 additions by David Forrester <[email protected]>'
__copyright__ = '2013, Greg Riker <[email protected]>, 2014-2020 additions by David Forrester <[email protected]>'
__docformat__ = 'restructuredtext en'

import imp, inspect, os, re, sys, tempfile, threading, types, urlparse
import imp, inspect, os, re, sys, tempfile, threading, types

# calibre Python 3 compatibility.
try:
from urllib.parse import urlparse
except ImportError as e:
from urlparse import urlparse
import six
from six import text_type as unicode

from functools import partial
from zipfile import ZipFile
Expand Down Expand Up @@ -153,12 +161,14 @@ def add_annotations_to_calibre(self, book_mi, annotations_db, cid):
# Any older annotations?
um = mi.metadata_for_field(update_field)
if mi.get_user_metadata(update_field, False)['#value#'] is None:
um['#value#'] = unicode(new_soup)
um['#value#'] = new_soup
# um['#value#'] = unicode(new_soup)
else:
# Merge new hashes into old
old_soup = BeautifulSoup(mi.get_user_metadata(update_field, False)['#value#'])
merged_soup = merge_annotations(self, cid, old_soup, new_soup)
um['#value#'] = unicode(merged_soup)
# um['#value#'] = unicode(merged_soup)
um['#value#'] = merged_soup
mi.set_user_metadata(update_field, um)
db.set_metadata(cid, mi, set_title=False, set_authors=False)
db.commit()
Expand Down Expand Up @@ -254,8 +264,8 @@ def do_drop_event(self):
self._log("waiting for library_scanner()")
self.library_scanner.wait()

path = urlparse.urlparse(self.dropped_url).path.strip()
scheme = urlparse.urlparse(self.dropped_url).scheme
path = urlparse(self.dropped_url).path.strip()
scheme = urlparse(self.dropped_url).scheme
path = re.sub('%20', ' ', path)
self._log_location(path)

Expand Down Expand Up @@ -534,7 +544,7 @@ def get_annotated_books_in_ios_reader_app(self, reader_app):
this_book_list = []
for book in books:
book_mi = {}
for key in book.keys():
for key in list(book.keys()):
book_mi[key] = book[key]
if not book_mi['active']:
continue
Expand Down Expand Up @@ -596,7 +606,7 @@ def get_annotated_books_on_usb_device(self, reader_app):
this_book_list = []
for book in books:
book_mi = {}
for key in book.keys():
for key in list(book.keys()):
book_mi[key] = book[key]
if not book_mi['active']:
continue
Expand Down Expand Up @@ -844,7 +854,7 @@ def load_dynamic_reader_classes(self):
tmp_file = os.path.join(tempfile.gettempdir(), plugin_tmpdir, basename)
if not os.path.exists(os.path.dirname(tmp_file)):
os.makedirs(os.path.dirname(tmp_file))
with open(tmp_file, 'w') as tf:
with open(tmp_file, 'wb') as tf:
tf.write(get_resources(rac))
self._log(" loading built-in class '%s'" % name)
imp.load_source(name, tmp_file)
Expand Down Expand Up @@ -1196,7 +1206,7 @@ def rebuild_menus(self):
ac.triggered.connect(self.show_supported_ios_reader_apps)

else:
usb_reader_classes = USBReader.get_usb_reader_classes().keys()
usb_reader_classes = list(USBReader.get_usb_reader_classes().keys())
primary_name = self.connected_device.name.split()[0]
if primary_name in usb_reader_classes:
haveDevice = True
Expand Down Expand Up @@ -1304,7 +1314,7 @@ def show_help(self):
def show_supported_ios_reader_apps(self):
'''
'''
supported_reader_apps = sorted(iOSReaderApp.get_reader_app_classes().keys(),
supported_reader_apps = sorted(list(iOSReaderApp.get_reader_app_classes().keys()),
key=lambda s: s.lower())

title = _("Supported iOS reader apps")
Expand Down
8 changes: 6 additions & 2 deletions annotated_books.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
# coding: utf-8

__license__ = 'GPL v3'
__copyright__ = '2013, Greg Riker <[email protected]>, 2014-2017 additions by David Forrester <[email protected]>'
__copyright__ = '2013, Greg Riker <[email protected]>, 2014-2020 additions by David Forrester <[email protected]>'
__docformat__ = 'restructuredtext en'

import operator
from time import localtime, strftime

# calibre Python 3 compatibility.
import six
from six import text_type as unicode

from calibre.devices.usbms.driver import debug_print
try:
from PyQt5 import QtCore
Expand Down Expand Up @@ -306,7 +310,7 @@ def __init__(self, parent, book_list, get_annotations_as_HTML, source):
# Set row height
fm = QFontMetrics(self.FONT)
nrows = len(self.tabledata)
for row in xrange(nrows):
for row in range(nrows):
self.tv.setRowHeight(row, fm.height() + 4)

self.tv.setSortingEnabled(True)
Expand Down
19 changes: 12 additions & 7 deletions annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
print_function)

__license__ = 'GPL v3'
__copyright__ = '2013, Greg Riker <[email protected]>, 2014-2019 additions by David Forrester <[email protected]>'
__copyright__ = '2013, Greg Riker <[email protected]>, 2014-2020 additions by David Forrester <[email protected]>'
__docformat__ = 'restructuredtext en'

import hashlib, re

# calibre Python 3 compatibility.
import six
from six import text_type as unicode

from datetime import datetime
from xml.sax.saxutils import escape

Expand Down Expand Up @@ -117,6 +121,7 @@ def to_HTML(self, header=''):
'''
Generate HTML with user-specified CSS, element order
'''
from calibre.ebooks.BeautifulSoup import prettify
# Retrieve CSS prefs
from calibre_plugins.annotations.appearance import default_elements
stored_css = plugin_prefs.get('appearance_css', default_elements)
Expand Down Expand Up @@ -187,12 +192,12 @@ def to_HTML(self, header=''):

if agroup.hash is not None:
# Use existing hash when re-rendering
hash = agroup.hash
annotation_hash = agroup.hash
else:
m = hashlib.md5()
m.update(text)
m.update(note)
hash = m.hexdigest()
m.update(text.encode('utf-8'))
m.update(note.encode('utf-8'))
annotation_hash = m.hexdigest()

try:
ka_soup = BeautifulSoup()
Expand All @@ -214,7 +219,7 @@ def to_HTML(self, header=''):
divTag['genre'] = ''
if agroup.genre:
divTag['genre'] = escape(agroup.genre)
divTag['hash'] = hash
divTag['hash'] = annotation_hash
divTag['location_sort'] = agroup.location_sort
divTag['reader'] = agroup.reader_app
divTag['style'] = ANNOTATION_DIV_STYLE
Expand All @@ -227,7 +232,7 @@ def to_HTML(self, header=''):

else:
soup = BeautifulSoup(ANNOTATIONS_HEADER)
return unicode(soup.renderContents())
return prettify(soup)


def merge_annotations(parent, cid, old_soup, new_soup):
Expand Down
6 changes: 3 additions & 3 deletions annotations_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# coding: utf-8

__license__ = 'GPL v3'
__copyright__ = '2013, Greg Riker <[email protected]>, 2014-2019 additions by David Forrester <[email protected]>'
__copyright__ = '2013, Greg Riker <[email protected]>, 2014-2020 additions by David Forrester <[email protected]>'
__docformat__ = 'restructuredtext en'

import os, sqlite3, sys
Expand Down Expand Up @@ -169,7 +169,7 @@ def _row_to_dict(ann):

# Create an Annotations object to hold annotations
stored_annotations = Annotations(self.opts, title=book_mi['title'])
annotations = self.get_annotations(annotations_db, book_mi[b'book_id'])
annotations = self.get_annotations(annotations_db, book_mi['book_id'])
for ann in annotations:
ann = _row_to_dict(ann)
ann['reader_app'] = book_mi['reader_app']
Expand Down Expand Up @@ -211,7 +211,7 @@ def _row_to_dict(ann):

# Create an Annotations object to hold annotations
stored_annotations = Annotations(self.opts, title=book_mi['title'])
annotations = self.get_annotations(annotations_db, book_mi[b'book_id'])
annotations = self.get_annotations(annotations_db, book_mi['book_id'])
for ann in annotations:
ann = _row_to_dict(ann)
ann['reader_app'] = book_mi['reader_app']
Expand Down
6 changes: 5 additions & 1 deletion appearance.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
print_function)

__license__ = 'GPL v3'
__copyright__ = '2013, Greg Riker <[email protected]>, 2014-2017 additions by David Forrester <[email protected]>'
__copyright__ = '2013, Greg Riker <[email protected]>, 2014-2020 additions by David Forrester <[email protected]>'
__docformat__ = 'restructuredtext en'

import re, time

# calibre Python 3 compatibility.
import six
from six import text_type as unicode

from functools import partial

from calibre.devices.usbms.driver import debug_print
Expand Down
Loading

0 comments on commit 2617b2e

Please sign in to comment.