Added network communication exception handling

git-svn-id: http://comictagger.googlecode.com/svn/trunk@114 6c5673fe-1810-88d6-992b-cd32ca31540c
This commit is contained in:
beville@gmail.com 2012-11-28 20:15:20 +00:00
parent 43cf24c429
commit 7838710ed4
9 changed files with 112 additions and 79 deletions

View File

@ -42,7 +42,7 @@ from options import Options, MetaDataStyle
from comicarchive import ComicArchive
from issueidentifier import IssueIdentifier
from genericmetadata import GenericMetadata
from comicvinetalker import ComicVineTalker
from comicvinetalker import ComicVineTalker, ComicVineTalkerException
import utils
import codecs
@ -218,7 +218,11 @@ def process_file_cli( filename, opts, settings ):
# we got here, so we have a single match
# now get the particular issue data
cv_md = ComicVineTalker().fetchIssueData( matches[0]['volume_id'], matches[0]['issue_number'] )
try:
cv_md = ComicVineTalker().fetchIssueData( matches[0]['volume_id'], matches[0]['issue_number'] )
except ComicVineTalkerException:
print "Network error while getting issue details. Save aborted"
return
md.overlay( cv_md )
# ok, done building our metadata. time to save

View File

@ -44,6 +44,8 @@ from settings import ComicTaggerSettings
from comicvinecacher import ComicVineCacher
from genericmetadata import GenericMetadata
class ComicVineTalkerException(Exception):
pass
class ComicVineTalker(QObject):
@ -65,6 +67,13 @@ class ComicVineTalker(QObject):
# Bogus request, but if the key is wrong, you get error 100: "Invalid API Key"
return cv_response[ 'status_code' ] != 100
def getUrlContent( self, url ):
try:
resp = urllib2.urlopen( url )
return resp.read()
except Exception as e:
print e
raise ComicVineTalkerException("Network Error!")
def searchForSeries( self, series_name , callback=None, refresh_cache=False ):
@ -85,8 +94,7 @@ class ComicVineTalker(QObject):
series_name = urllib.quote_plus(str(series_name))
search_url = "http://api.comicvine.com/search/?api_key=" + self.api_key + "&format=json&resources=volume&query=" + series_name + "&field_list=name,id,start_year,publisher,image,description,count_of_issues&sort=start_year"
resp = urllib2.urlopen(search_url)
content = resp.read()
content = self.getUrlContent(search_url)
cv_response = json.loads(content)
@ -115,8 +123,7 @@ class ComicVineTalker(QObject):
if callback is None:
print ("getting another page of results {0} of {1}...".format( current_result_count, total_result_count))
offset += limit
resp = urllib2.urlopen( search_url + "&offset="+str(offset) )
content = resp.read()
content = self.getUrlContent(search_url + "&offset="+str(offset))
cv_response = json.loads(content)
@ -154,9 +161,7 @@ class ComicVineTalker(QObject):
volume_url = "http://api.comicvine.com/volume/" + str(series_id) + "/?api_key=" + self.api_key + "&format=json"
resp = urllib2.urlopen(volume_url)
content = resp.read()
content = self.getUrlContent(volume_url)
cv_response = json.loads(content)
if cv_response[ 'status_code' ] != 1:
@ -182,8 +187,8 @@ class ComicVineTalker(QObject):
if (found):
issue_url = "http://api.comicvine.com/issue/" + str(record['id']) + "/?api_key=" + self.api_key + "&format=json"
resp = urllib2.urlopen(issue_url)
content = resp.read()
content = self.getUrlContent(issue_url)
cv_response = json.loads(content)
if cv_response[ 'status_code' ] != 1:
print ( "Comic Vine query failed with error: [{0}]. ".format( cv_response[ 'error' ] ))
@ -288,8 +293,9 @@ class ComicVineTalker(QObject):
return cached_image_url,cached_thumb_url, cached_month, cached_year
issue_url = "http://api.comicvine.com/issue/" + str(issue_id) + "/?api_key=" + self.api_key + "&format=json&field_list=image,publish_month,publish_year"
resp = urllib2.urlopen(issue_url)
content = resp.read()
content = self.getUrlContent(issue_url)
cv_response = json.loads(content)
if cv_response[ 'status_code' ] != 1:
print ( "Comic Vine query failed with error: [{0}]. ".format( cv_response[ 'error' ] ))

View File

@ -44,6 +44,9 @@ except ImportError:
from settings import ComicTaggerSettings
class ImageFetcherException(Exception):
pass
class ImageFetcher(QObject):
fetchComplete = pyqtSignal( QByteArray , int)
@ -82,11 +85,15 @@ class ImageFetcher(QObject):
if blocking:
if image_data is None:
image_data = urllib.urlopen(url).read()
try:
image_data = urllib.urlopen(url).read()
except Exception as e:
print e
raise ImageFetcherException("Network Error!")
# save the image to the cache
self.add_image_to_cache( self.fetched_url, image_data )
return image_data
return image_data
else:
# if we found it, just emit the signal asap

View File

@ -31,9 +31,9 @@ except ImportError:
from settings import ComicTaggerSettings
from comicvinecacher import ComicVineCacher
from genericmetadata import GenericMetadata
from comicvinetalker import ComicVineTalker
from comicvinetalker import ComicVineTalker, ComicVineTalkerException
from imagehasher import ImageHasher
from imagefetcher import ImageFetcher
from imagefetcher import ImageFetcher, ImageFetcherException
import utils
@ -254,8 +254,11 @@ class IssueIdentifier:
#self.log_msg( ( "Searching for " + keys['series'] + "...")
self.log_msg( "Searching for {0} #{1} ...".format( keys['series'], keys['issue_number']) )
cv_search_results = comicVine.searchForSeries( keys['series'] )
try:
cv_search_results = comicVine.searchForSeries( keys['series'] )
except ComicVineTalkerException:
self.log_msg( "Network issue while searching for series. Aborting...")
return []
#self.log_msg( "Found " + str(len(cv_search_results)) + " initial results" )
if self.cancel == True:
@ -316,8 +319,13 @@ class IssueIdentifier:
series['id'],
series['name'],
series['start_year']), newline=False )
try:
cv_series_results = comicVine.fetchVolumeData( series['id'] )
except ComicVineTalkerException:
self.log_msg( "Network issue while searching for series details. Aborting...")
return []
cv_series_results = comicVine.fetchVolumeData( series['id'] )
issue_list = cv_series_results['issues']
for issue in issue_list:
@ -341,9 +349,12 @@ class IssueIdentifier:
if keys['year'] is not None:
if keys['year'] != year:
break
try:
url_image_data = ImageFetcher().fetch(thumb_url, blocking=True)
except ImageFetcherException:
self.log_msg( "Network issue while fetching cover image from ComicVine. Aborting...")
return []
url_image_data = ImageFetcher().fetch(thumb_url, blocking=True)
if self.cancel == True:
self.match_list = []
return self.match_list

View File

@ -25,7 +25,7 @@ from PyQt4 import QtCore, QtGui, uic
from PyQt4.QtCore import QUrl, pyqtSignal, QByteArray
from PyQt4.QtNetwork import QNetworkAccessManager, QNetworkRequest
from comicvinetalker import ComicVineTalker
from comicvinetalker import ComicVineTalker, ComicVineTalkerException
from imagefetcher import ImageFetcher
from settings import ComicTaggerSettings
@ -68,11 +68,17 @@ class IssueSelectionWindow(QtGui.QDialog):
QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor))
try:
comicVine = ComicVineTalker( )
volume_data = comicVine.fetchVolumeData( self.series_id )
except ComicVineTalkerException:
QtGui.QApplication.restoreOverrideCursor()
QtGui.QMessageBox.critical(self, self.tr("Network Issue"), self.tr("Could not connect to ComicVine to list issues!"))
return
while self.twList.rowCount() > 0:
self.twList.removeRow(0)
comicVine = ComicVineTalker( )
volume_data = comicVine.fetchVolumeData( self.series_id )
self.issue_list = volume_data['issues']
self.twList.setSortingEnabled(False)

View File

@ -24,7 +24,6 @@ from PyQt4 import QtCore, QtGui, uic
from PyQt4.QtCore import QUrl, pyqtSignal, QByteArray
from comicvinetalker import ComicVineTalker
from imagefetcher import ImageFetcher
from settings import ComicTaggerSettings

View File

@ -33,7 +33,7 @@ from volumeselectionwindow import VolumeSelectionWindow
from options import MetaDataStyle
from comicinfoxml import ComicInfoXml
from genericmetadata import GenericMetadata
from comicvinetalker import ComicVineTalker
from comicvinetalker import ComicVineTalker, ComicVineTalkerException
from comicarchive import ComicArchive
from crediteditorwindow import CreditEditorWindow
from settingswindow import SettingsWindow
@ -784,16 +784,18 @@ class TaggerWindow( QtGui.QMainWindow):
#copy the form onto metadata object
self.formToMetadata()
comicVine = ComicVineTalker( )
new_metadata = comicVine.fetchIssueData( selector.volume_id, selector.issue_number )
self.metadata.overlay( new_metadata )
# Now push the new combined data into the edit controls
self.metadataToForm()
#!!!ATB should I clear the form???
QtGui.QApplication.restoreOverrideCursor()
try:
comicVine = ComicVineTalker( )
new_metadata = comicVine.fetchIssueData( selector.volume_id, selector.issue_number )
except ComicVineTalkerException:
QtGui.QApplication.restoreOverrideCursor()
QtGui.QMessageBox.critical(self, self.tr("Network Issue"), self.tr("Could not connect to ComicVine to get issue details!"))
else:
self.metadata.overlay( new_metadata )
# Now push the new combined data into the edit controls
self.metadataToForm()
finally:
QtGui.QApplication.restoreOverrideCursor()
def commitMetadata(self):

View File

@ -1,47 +1,23 @@
-----------------------------------------------------
Features
-----------------------------------------------------
CLI
explicit metadata settings option format
-- figure out how to add tags
-- delete tags
Overlay credits,tags, myabe more on online search
Fix about graphics
Release notes
Style sheets for windows/mac/linux
WIki for CLI
Wiki for basic usage
Add license file to OSX package/Win Package
Config Dialog layout -- help stuff?
-----------------------------------------------------
Bugs
-----------------------------------------------------
Mac Build needs Quartz??
Preserve Primary flags in credits
Comma in Credits in CIX
Windows zip and rar: set proper path for writing to archive
set working dir for sys calls
SERIOUS BUG: rebuilding zips!
http://stackoverflow.com/questions/11578443/trigger-io-errno-18-cross-device-link
Execption handling for save operations
Frozen apps: better finding of resource files
OSX
weird unrar complaints
Page browser sizing
command-line args don't work with pyinstaller pkg
Filename parsing:
Rework how series name is separated from issue
Form type validation Ints vs strings for month, year. etc
Check all HTTP responses for errors
Size/Position memory Win vs Lin vs Mac
Lots of error checking
-----------------------------------------------------
@ -49,14 +25,23 @@ Future
-----------------------------------------------------
Add CoMet Support
Support marvel's "AU" issues...
Style sheets for windows/mac/linux
File rename
-Dialog??
formatting with missing pieces.
Deal with creating dupes
TaggerWindow entry fields
Special tabbed Dialog needed for:
Pages Info - maybe a custom painted widget
CLI
explicit metadata settings option format
-- figure out how to add tags
-- delete tags
write a log for multiple file processing
override abort on low confidence flag
interactive for choices option?
@ -66,6 +51,8 @@ Scrape alternate Covers from ComicVine issue pages
GCD scraper or DB reader
Overlay tags, maybe more, on online search
GUI to handle mutliple files or folders
Auto search:
@ -83,10 +70,13 @@ Settings
Add setting to dis-allow writing CBI to RAR
Overwrite or overlay
Google App engine to store hashes
Content Hashes??
Content Hashes, Image hashes, who knows?
Support primary credit flag editing
Filename parsing:
Rework how series name is separated from issue
----------------------------------------------

View File

@ -26,7 +26,7 @@ from PyQt4.QtCore import QObject
from PyQt4.QtCore import QUrl,pyqtSignal
from PyQt4.QtNetwork import QNetworkAccessManager, QNetworkRequest
from comicvinetalker import ComicVineTalker
from comicvinetalker import ComicVineTalker, ComicVineTalkerException
from issueselectionwindow import IssueSelectionWindow
from issueidentifier import IssueIdentifier
from genericmetadata import GenericMetadata
@ -47,9 +47,14 @@ class SearchThread( QtCore.QThread):
def run(self):
comicVine = ComicVineTalker( )
matches = self.cv_search_results = comicVine.searchForSeries( self.series_name, callback=self.prog_callback, refresh_cache=self.refresh )
self.searchComplete.emit()
try:
self.cv_error = False
self.cv_search_results = comicVine.searchForSeries( self.series_name, callback=self.prog_callback, refresh_cache=self.refresh )
except ComicVineTalkerException:
self.cv_search_results = []
self.cv_error = True
finally:
self.searchComplete.emit()
def prog_callback(self, current, total):
self.progressUpdate.emit(current, total)
@ -265,7 +270,10 @@ class VolumeSelectionWindow(QtGui.QDialog):
def searchComplete( self ):
self.progdialog.accept()
if self.search_thread.cv_error:
QtGui.QMessageBox.critical(self, self.tr("Network Issue"), self.tr("Could not connect to ComicVine to search for series!"))
return
self.cv_search_results = self.search_thread.cv_search_results
self.twList.setSortingEnabled(False)