[Dev] Calibre contacts its own servers to check for version updates (patch available)

nospam at curso.re nospam at curso.re
Wed Apr 12 16:45:02 GMT 2017


nospam at curso.re writes:

> Luke Shumaker <lukeshu at lukeshu.com> writes:
>
>> On Wed, 12 Apr 2017 10:19:40 -0400,
>> nospam at curso.re wrote:
>> [...]
>>> Are you interested in reviewing and possibly integrating them?
>>
>> I'm definitely interested in reviewing them.  Though, I'd be a little
>> surprised if there isn't already a ./configure flag to turn the
>> behavior off.
>
> Cool, thanks!
>
> Calibre uses a very complicated setup.py and I could not figure out at a
> glance whether such features can be turned off.
>
> I will send over another message obtained with git-format-patch then. It
> will have to patch files and the required changes to the calibre
> PKGBUILD.
>
> As a note, I had to modify the patch once (and once only so far) because
> of minor code changes one patched file.
>
> Best,
>
> -- S.

Here it is.

Calibre automatically checks for updates by contacting its own
servers. Although there is a user option to turn this off, we don't need to do
that since calibre is maintained within Parabola.

This commit adds patches that remove the code about updating calibre. The UI
will also not show the option about turning the version check on or off.
---
 ...-that-contacts-calibre-servers-to-check-u.patch | 101 +++++++++++++++++++++
 .../0001-Remove-new_version_notification.patch     |  90 ++++++++++++++++++
 libre/calibre/PKGBUILD                             |  12 ++-
 3 files changed, 201 insertions(+), 2 deletions(-)
 create mode 100644 libre/calibre/0001-Remove-code-that-contacts-calibre-servers-to-check-u.patch
 create mode 100644 libre/calibre/0001-Remove-new_version_notification.patch

diff --git a/libre/calibre/0001-Remove-code-that-contacts-calibre-servers-to-check-u.patch b/libre/calibre/0001-Remove-code-that-contacts-calibre-servers-to-check-u.patch
new file mode 100644
index 000000000..8993d06a6
--- /dev/null
+++ b/libre/calibre/0001-Remove-code-that-contacts-calibre-servers-to-check-u.patch
@@ -0,0 +1,101 @@
+---
+ src/calibre/gui2/update.py | 56 ++++++----------------------------------------
+ 1 file changed, 7 insertions(+), 49 deletions(-)
+
+diff --git a/src/calibre/gui2/update.py b/src/calibre/gui2/update.py
+index d1ba091373..097312300a 100644
+--- a/src/calibre/gui2/update.py
++++ b/src/calibre/gui2/update.py
+@@ -1,19 +1,17 @@
+ __license__   = 'GPL v3'
+ __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
+ 
+-import re, binascii, cPickle, ssl, json
++import binascii, cPickle
+ from future_builtins import map
+ from threading import Thread, Event
+ 
+ from PyQt5.Qt import (QObject, pyqtSignal, Qt, QUrl, QDialog, QGridLayout,
+-        QLabel, QCheckBox, QDialogButtonBox, QIcon)
++        QLabel, QDialogButtonBox, QIcon)
+ 
+-from calibre.constants import (__appname__, __version__, iswindows, isosx,
+-        isportable, is64bit, numeric_version)
++from calibre.constants import (__appname__, iswindows, isosx,
++        isportable, is64bit)
+ from calibre import prints, as_unicode
+-from calibre.utils.config import prefs
+-from calibre.utils.https import get_https_resource_securely
+-from calibre.gui2 import config, dynamic, open_url
++from calibre.gui2 import dynamic, open_url
+ from calibre.gui2.dialogs.plugin_updater import get_plugin_updates_available
+ 
+ URL = 'https://code.calibre-ebook.com/latest'
+@@ -30,35 +28,7 @@ def get_download_url():
+ 
+ 
+ def get_newest_version():
+-    try:
+-        icon_theme_name = json.loads(I('icon-theme.json', data=True))['name']
+-    except Exception:
+-        icon_theme_name = ''
+-    headers={
+-        'CALIBRE-VERSION':__version__,
+-        'CALIBRE-OS': ('win' if iswindows else 'osx' if isosx else 'oth'),
+-        'CALIBRE-INSTALL-UUID': prefs['installation_uuid'],
+-        'CALIBRE-ICON-THEME': icon_theme_name,
+-    }
+-    try:
+-        version = get_https_resource_securely(URL, headers=headers)
+-    except ssl.SSLError as err:
+-        if getattr(err, 'reason', None) != 'CERTIFICATE_VERIFY_FAILED':
+-            raise
+-        # certificate verification failed, since the version check contains no
+-        # critical information, ignore and proceed
+-        # We have to do this as if the calibre CA certificate ever
+-        # needs to be revoked, then we wont be able to do version checks
+-        version = get_https_resource_securely(URL, headers=headers, cacerts=None)
+-    try:
+-        version = version.decode('utf-8').strip()
+-    except UnicodeDecodeError:
+-        version = u''
+-    ans = NO_CALIBRE_UPDATE
+-    m = re.match(ur'(\d+)\.(\d+).(\d+)$', version)
+-    if m is not None:
+-        ans = tuple(map(int, (m.group(1), m.group(2), m.group(3))))
+-    return ans
++    return NO_CALIBRE_UPDATE
+ 
+ 
+ class Signal(QObject):
+@@ -81,12 +51,6 @@ class CheckForUpdates(Thread):
+             calibre_update_version = NO_CALIBRE_UPDATE
+             plugins_update_found = 0
+             try:
+-                version = get_newest_version()
+-                if version[:2] > numeric_version[:2]:
+-                    calibre_update_version = version
+-            except Exception as e:
+-                prints('Failed to check for calibre update:', as_unicode(e))
+-            try:
+                 update_plugins = get_plugin_updates_available(raise_error=True)
+                 if update_plugins is not None:
+                     plugins_update_found = len(update_plugins)
+@@ -193,13 +157,7 @@ class UpdateMixin(object):
+         self.status_bar.update_label.setText(msg)
+         self.status_bar.update_label.setVisible(True)
+ 
+-        if has_calibre_update:
+-            if force:
+-                if not no_show_popup:
+-                    self._update_notification__ = UpdateNotification(calibre_version,
+-                            number_of_plugin_updates, parent=self)
+-                    self._update_notification__.show()
+-        elif has_plugin_updates:
++        if has_plugin_updates:
+             if force:
+                 from calibre.gui2.dialogs.plugin_updater import (PluginUpdaterDialog,
+                     FILTER_UPDATE_AVAILABLE)
+-- 
+2.12.2
+
diff --git a/libre/calibre/0001-Remove-new_version_notification.patch b/libre/calibre/0001-Remove-new_version_notification.patch
new file mode 100644
index 000000000..e47545167
--- /dev/null
+++ b/libre/calibre/0001-Remove-new_version_notification.patch
@@ -0,0 +1,90 @@
+---
+ src/calibre/gui2/__init__.py             |  2 --
+ src/calibre/gui2/preferences/behavior.py |  1 -
+ src/calibre/gui2/preferences/behavior.ui |  7 -------
+ src/calibre/gui2/update.py               | 12 ++----------
+ 4 files changed, 2 insertions(+), 20 deletions(-)
+
+diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py
+index a1cf1849d3..6daa2e7050 100644
+--- a/src/calibre/gui2/__init__.py
++++ b/src/calibre/gui2/__init__.py
+@@ -169,8 +169,6 @@ def _config():  # {{{
+               help=_('Confirm before deleting'))
+     c.add_opt('main_window_geometry', default=None,
+               help=_('Main window geometry'))
+-    c.add_opt('new_version_notification', default=True,
+-              help=_('Notify when a new version is available'))
+     c.add_opt('use_roman_numerals_for_series_number', default=True,
+               help=_('Use Roman numerals for series number'))
+     c.add_opt('sort_tags_by', default='name',
+diff --git a/src/calibre/gui2/preferences/behavior.py b/src/calibre/gui2/preferences/behavior.py
+index 6db4cb1f3a..51b7ed0a82 100644
+--- a/src/calibre/gui2/preferences/behavior.py
++++ b/src/calibre/gui2/preferences/behavior.py
+@@ -40,7 +40,6 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
+ 
+         r('network_timeout', prefs)
+ 
+-        r('new_version_notification', config)
+         r('upload_news_to_device', config)
+         r('delete_news_from_library_on_upload', config)
+ 
+diff --git a/src/calibre/gui2/preferences/behavior.ui b/src/calibre/gui2/preferences/behavior.ui
+index 2926f767b9..0ad9988845 100644
+--- a/src/calibre/gui2/preferences/behavior.ui
++++ b/src/calibre/gui2/preferences/behavior.ui
+@@ -14,13 +14,6 @@
+    <string>Form</string>
+   </property>
+   <layout class="QGridLayout" name="gridLayout">
+-   <item row="1" column="0">
+-    <widget class="QCheckBox" name="opt_new_version_notification">
+-     <property name="text">
+-      <string>Show notification when &new version is available</string>
+-     </property>
+-    </widget>
+-   </item>
+    <item row="1" column="1">
+     <widget class="QCheckBox" name="opt_bools_are_tristate">
+      <property name="toolTip">
+diff --git a/src/calibre/gui2/update.py b/src/calibre/gui2/update.py
+index 3e294cac31..d1ba091373 100644
+--- a/src/calibre/gui2/update.py
++++ b/src/calibre/gui2/update.py
+@@ -125,11 +125,7 @@ class UpdateNotification(QDialog):
+         self.setWindowIcon(QIcon(I('lt.png')))
+         self.l.addWidget(self.logo, 0, 0)
+         self.l.addWidget(self.label, 0, 1)
+-        self.cb = QCheckBox(
+-            _('Show this notification for future updates'), self)
+-        self.l.addWidget(self.cb, 1, 0, 1, -1)
+-        self.cb.setChecked(config.get('new_version_notification'))
+-        self.cb.stateChanged.connect(self.show_future)
++
+         self.bb = QDialogButtonBox(self)
+         b = self.bb.addButton(_('&Get update'), self.bb.AcceptRole)
+         b.setDefault(True)
+@@ -151,9 +147,6 @@ class UpdateNotification(QDialog):
+                 initial_filter=FILTER_UPDATE_AVAILABLE)
+         d.exec_()
+ 
+-    def show_future(self, *args):
+-        config.set('new_version_notification', bool(self.cb.isChecked()))
+-
+     def accept(self):
+         open_url(QUrl(get_download_url()))
+ 
+@@ -201,8 +194,7 @@ class UpdateMixin(object):
+         self.status_bar.update_label.setVisible(True)
+ 
+         if has_calibre_update:
+-            if (force or (config.get('new_version_notification') and
+-                    dynamic.get('update to version %s'%calibre_version, True))):
++            if force:
+                 if not no_show_popup:
+                     self._update_notification__ = UpdateNotification(calibre_version,
+                             number_of_plugin_updates, parent=self)
+-- 
+2.12.2
+
diff --git a/libre/calibre/PKGBUILD b/libre/calibre/PKGBUILD
index e869aabc3..78feccce4 100644
--- a/libre/calibre/PKGBUILD
+++ b/libre/calibre/PKGBUILD
@@ -33,11 +33,17 @@ conflicts=($pkgname-libre)
 mksource=("http://download.$pkgname-ebook.com/${pkgver}/$pkgname-${pkgver}.tar.xz"
           "https://calibre-ebook.com/signatures/${pkgname}-${pkgver}.tar.xz.sig")
 source=("https://repo.parabola.nu/other/${pkgname}-libre/${pkgname}-libre-${pkgver}.tar.xz"
-        'libre.patch')
+        'libre.patch'
+        '0001-Remove-new_version_notification.patch'
+        '0001-Remove-code-that-contacts-calibre-servers-to-check-u.patch')
 mksha256sums=('137995abe467fcb951c1d42583305ebec7b8ca403c44895e70f82a2d6156711c'
+              'SKIP'
+              'SKIP'
               'SKIP')
 sha256sums=('4da07053bddca0c49c3bf315397f3f1dff319f74e63e8a961c3906e0eca4eb7d'
-            '9d57abfff30e0b02128aa32ee41e095ab9f16b52c358fda68b3cae3ab8b485b9')
+            '9d57abfff30e0b02128aa32ee41e095ab9f16b52c358fda68b3cae3ab8b485b9'
+            'fb0394227e0dc67c612634ac31e164aa05fe0b8dc158a63c4cc41e9182d0d357'
+            '82c54f58751279e8d631af2f7638828ed98f276a9fd9baff596d97d0cd135b7a')
 validpgpkeys=('3CE1780F78DD88DF45194FD706BC317B515ACE7C')
 
 mksource(){
@@ -55,6 +61,8 @@ prepare(){
   rm -v resources/images/mimetypes/{cbr,rar}.png
   rm -v imgsrc/mimetypes/rar.svg
   patch -Np1 -i "${srcdir}/libre.patch"
+  patch -Np1 -i "${srcdir}/0001-Remove-new_version_notification.patch"
+  patch -Np1 -i "${srcdir}/0001-Remove-code-that-contacts-calibre-servers-to-check-u.patch"
 
   # Remove unneeded files and libs
   # FIXME: remove html5lib too, but the latest html5lib breaks calibre. And calibre
-- 
2.12.2




More information about the Dev mailing list