From d0918c92e4f5ab1ae779e3d598c0aa2218b4d431 Mon Sep 17 00:00:00 2001 From: davide-romanini Date: Thu, 21 Dec 2017 15:19:45 +0100 Subject: [PATCH] #87 Update comic vine url and ssl config (#93) * #87 fix ssl comicvine communication * handle missing libunrar. update macos makefile. remove version check window. bump version. * update release notes * #87 fix ssl context in several places. update comicvine api url. * fix drag and drop issues on macOS * bump version to 1.1.16-beta-rc2 * use PNG conversion for Windows build --- comicapi/comicarchive.py | 12 +++++----- comictagger.py | 14 ++++++++++++ comictaggerlib/comicvinetalker.py | 12 ++++++---- comictaggerlib/ctversion.py | 2 +- comictaggerlib/imagefetcher.py | 6 ++++- comictaggerlib/options.py | 8 ------- comictaggerlib/taggerwindow.py | 37 ++++++++++++++++++++++++++++--- comictaggerlib/ui/qtutils.py | 5 ++--- current_version.txt | 2 +- mac/Makefile | 5 +++-- release_notes.txt | 5 +++++ 11 files changed, 80 insertions(+), 28 deletions(-) diff --git a/comicapi/comicarchive.py b/comicapi/comicarchive.py index d53522b..b411714 100644 --- a/comicapi/comicarchive.py +++ b/comicapi/comicarchive.py @@ -30,11 +30,13 @@ import StringIO from natsort import natsorted from PyPDF2 import PdfFileReader -from unrar import rarfile -from unrar import unrarlib -from unrar import constants -#import UnRAR2 -#from UnRAR2.rar_exceptions import * +try: + from unrar import rarfile + from unrar import unrarlib + from unrar import constants +except: + print "WARNING: cannot find libunrar, rar support is disabled" + pass if platform.system() == "Windows": import _subprocess diff --git a/comictagger.py b/comictagger.py index 4a36a8c..53af473 100755 --- a/comictagger.py +++ b/comictagger.py @@ -1,4 +1,18 @@ #!/usr/bin/env python +import os +import sys + +if getattr(sys, 'frozen', False): + # we are running in a bundle + frozen = 'ever so' + bundle_dir = sys._MEIPASS +else: + # we are running in a normal Python environment + bundle_dir = os.path.dirname(os.path.abspath(__file__)) + +# setup libunrar +if not os.environ.get("UNRAR_LIB_PATH", None): + os.environ["UNRAR_LIB_PATH"] = bundle_dir + "/libunrar.so" from comictaggerlib.main import ctmain diff --git a/comictaggerlib/comicvinetalker.py b/comictaggerlib/comicvinetalker.py index db8c299..021d27a 100644 --- a/comictaggerlib/comicvinetalker.py +++ b/comictaggerlib/comicvinetalker.py @@ -21,6 +21,7 @@ import re import time import datetime import sys +import ssl #from pprint import pprint #import math @@ -90,7 +91,7 @@ class ComicVineTalker(QObject): def __init__(self): QObject.__init__(self) - self.api_base_url = "http://www.comicvine.com/api" + self.api_base_url = "https://comicvine.gamespot.com/api" self.wait_for_rate_limit = False # key that is registered to comictagger @@ -103,6 +104,9 @@ class ComicVineTalker(QObject): self.log_func = None + # always use a tls context for urlopen + self.ssl = ssl.SSLContext(ssl.PROTOCOL_TLSv1) + def setLogFunc(self, log_func): self.log_func = log_func @@ -131,7 +135,7 @@ class ComicVineTalker(QObject): test_url = self.api_base_url + "/issue/1/?api_key=" + \ key + "&format=json&field_list=name" - resp = urllib2.urlopen(test_url) + resp = urllib2.urlopen(test_url, context=self.ssl) content = resp.read() cv_response = json.loads(content) @@ -184,7 +188,7 @@ class ComicVineTalker(QObject): # print "ATB---", url for tries in range(3): try: - resp = urllib2.urlopen(url) + resp = urllib2.urlopen(url, context=self.ssl) return resp.read() except urllib2.HTTPError as e: if e.getcode() == 500: @@ -674,7 +678,7 @@ class ComicVineTalker(QObject): return url_list # scrape the CV issue page URL to get the alternate cover URLs - resp = urllib2.urlopen(issue_page_url) + resp = urllib2.urlopen(issue_page_url, context=self.ssl) content = resp.read() alt_cover_url_list = self.parseOutAltCoverUrls(content) diff --git a/comictaggerlib/ctversion.py b/comictaggerlib/ctversion.py index 2f7ab41..e63ebc7 100644 --- a/comictaggerlib/ctversion.py +++ b/comictaggerlib/ctversion.py @@ -1,3 +1,3 @@ # This file should contain only these comments, and the line below. # Used by packaging makefiles and app -version = "1.1.15-beta" +version = "1.1.16-beta-rc2" diff --git a/comictaggerlib/imagefetcher.py b/comictaggerlib/imagefetcher.py index cde24ca..26903e2 100644 --- a/comictaggerlib/imagefetcher.py +++ b/comictaggerlib/imagefetcher.py @@ -20,6 +20,7 @@ import datetime import shutil import tempfile import urllib +import ssl #import urllib2 try: @@ -65,6 +66,9 @@ class ImageFetcher(QObject): if not os.path.exists(self.db_file): self.create_image_db() + # always use a tls context for urlopen + self.ssl = ssl.SSLContext(ssl.PROTOCOL_TLSv1) + def clearCache(self): os.unlink(self.db_file) if os.path.isdir(self.cache_folder): @@ -87,7 +91,7 @@ class ImageFetcher(QObject): if blocking: if image_data is None: try: - image_data = urllib.urlopen(url).read() + image_data = urllib.urlopen(url, context=self.ssl).read() except Exception as e: print(e) raise ImageFetcherException("Network Error!") diff --git a/comictaggerlib/options.py b/comictaggerlib/options.py index 96d0468..fca3f86 100644 --- a/comictaggerlib/options.py +++ b/comictaggerlib/options.py @@ -344,14 +344,6 @@ For more help visit the wiki at: http://code.google.com/p/comictagger/ "ComicTagger {0}: Copyright (c) 2012-2014 Anthony Beville".format(ctversion.version)) print( "Distributed under Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)") - new_version = VersionChecker().getLatestVersion("", False) - if new_version is not None and new_version != ctversion.version: - print( - "--------------------------------------------------------------------------") - print( - "New version available online: {0}".format(new_version)) - print( - "--------------------------------------------------------------------------") sys.exit(0) if o in ("-t", "--type"): if a.lower() == "cr": diff --git a/comictaggerlib/taggerwindow.py b/comictaggerlib/taggerwindow.py index 7c53a33..764bc4f 100644 --- a/comictaggerlib/taggerwindow.py +++ b/comictaggerlib/taggerwindow.py @@ -28,7 +28,7 @@ import pickle from PyQt4 import QtCore, QtGui, uic from PyQt4 import QtNetwork -#from PyQt4.QtCore import QUrl, pyqtSignal +from PyQt4.QtCore import QString, QUrl #from comicarchive import ComicArchive #from pageloader import PageLoader @@ -279,7 +279,8 @@ class TaggerWindow(QtGui.QMainWindow): self.settings.ask_about_usage_stats = False if self.settings.check_for_new_version: - self.checkLatestVersionOnline() + #self.checkLatestVersionOnline() + pass def sigint_handler(self, *args): # defer the actual close in the app loop thread @@ -584,11 +585,41 @@ class TaggerWindow(QtGui.QMainWindow): if url.isValid() and url.scheme() == "file": if self.droppedFiles is None: self.droppedFiles = [] - self.droppedFiles.append(url.toLocalFile()) + self.droppedFiles.append(self.getUrlFromLocalFileID(url)) if self.droppedFiles is not None: event.accept() + # http://stackoverflow.com/questions/34689562/pyqt-mimedata-filename + def getUrlFromLocalFileID(self, localFileID): + import sys + if not sys.platform == 'darwin': + return localFileID.toLocalFile() + + import objc + import CoreFoundation as CF + localFileQString = QString(localFileID.toLocalFile()) + relCFStringRef = CF.CFStringCreateWithCString( + CF.kCFAllocatorDefault, + localFileQString.toUtf8(), + CF.kCFStringEncodingUTF8 + ) + relCFURL = CF.CFURLCreateWithFileSystemPath( + CF.kCFAllocatorDefault, + relCFStringRef, + CF.kCFURLPOSIXPathStyle, + False # is directory + ) + absCFURL = CF.CFURLCreateFilePathURL( + CF.kCFAllocatorDefault, + relCFURL, + objc.NULL + ) + + local = QUrl(str(absCFURL[0])).toLocalFile() + + return local + def dropEvent(self, event): # if self.dirtyFlagVerification("Open Archive", # "If you open a new archive now, data in the form will be lost. Are you sure?"): diff --git a/comictaggerlib/ui/qtutils.py b/comictaggerlib/ui/qtutils.py index 7d82d6d..ccdab02 100644 --- a/comictaggerlib/ui/qtutils.py +++ b/comictaggerlib/ui/qtutils.py @@ -80,9 +80,8 @@ if qt_available: # format im = Image.open(StringIO.StringIO(image_data)) output = StringIO.StringIO() - im.save(output, format="TIFF") - img.loadFromData(output.getvalue()) - success = True + im.save(output, format="PNG") + success = img.loadFromData(output.getvalue()) except Exception as e: pass # if still nothing, go with default image diff --git a/current_version.txt b/current_version.txt index c71e013..04cdfd2 100644 --- a/current_version.txt +++ b/current_version.txt @@ -1 +1 @@ -1.1.15-beta +1.1.16-beta-rc diff --git a/mac/Makefile b/mac/Makefile index ac53b08..8e13fb2 100644 --- a/mac/Makefile +++ b/mac/Makefile @@ -1,7 +1,7 @@ #PYINSTALLER_CMD := VERSIONER_PYTHON_PREFER_32_BIT=yes arch -i386 python $(HOME)/pyinstaller-2.0/pyinstaller.py #PYINSTALLER_CMD := python $(HOME)/pyinstaller-2.0/pyinstaller.py PYINSTALLER_CMD := pyinstaller -TAGGER_BASE ?= $(HOME)/Dropbox/tagger/comictagger +TAGGER_BASE ?= ../ TAGGER_SRC := $(TAGGER_BASE)/comictaggerlib APP_NAME := ComicTagger @@ -11,7 +11,7 @@ MAC_BASE := $(TAGGER_BASE)/mac DIST_DIR := $(MAC_BASE)/dist STAGING := $(MAC_BASE)/$(APP_NAME) APP_BUNDLE := $(DIST_DIR)/$(APP_NAME).app -VOLUME_NAME := $(APP_NAME)-$(VERSION_STR) +VOLUME_NAME := "$(APP_NAME)-$(VERSION_STR)" DMG_FILE := $(VOLUME_NAME).dmg all: clean dist diskimage @@ -21,6 +21,7 @@ dist: $(PYINSTALLER_CMD) $(TAGGER_BASE)/comictagger.py -w -n $(APP_NAME) -s cp -a $(TAGGER_SRC)/ui $(APP_BUNDLE)/Contents/MacOS cp -a $(TAGGER_SRC)/graphics $(APP_BUNDLE)/Contents/MacOS + cp $(MAC_BASE)/libunrar.so $(APP_BUNDLE)/Contents/MacOS cp $(MAC_BASE)/app.icns $(APP_BUNDLE)/Contents/Resources/icon-windowed.icns # fix the version string in the Info.plist sed -i -e 's/0\.0\.0/$(VERSION_STR)/' $(MAC_BASE)/dist/ComicTagger.app/Contents/Info.plist diff --git a/release_notes.txt b/release_notes.txt index ca2f6f9..fff1b42 100644 --- a/release_notes.txt +++ b/release_notes.txt @@ -1,3 +1,8 @@ +--------------------------------- +1.1.16-beta-rc - 07-Apr-2017 +--------------------------------- + * Fix ComicVine SSL problems (issue #87) + --------------------------------- 1.1.15-beta - 13-Jun-2014 ---------------------------------