Make a lot of print statements go to stderr

git-svn-id: http://comictagger.googlecode.com/svn/trunk@427 6c5673fe-1810-88d6-992b-cd32ca31540c
This commit is contained in:
beville@gmail.com 2013-02-05 22:27:35 +00:00
parent b8893b853f
commit 4f3e63db07
13 changed files with 149 additions and 91 deletions

View File

@ -68,12 +68,12 @@ class ZipArchiver:
try:
data = zf.read( archive_file )
except zipfile.BadZipfile as e:
print "bad zipfile [{0}]: {1} :: {2}".format(e, self.path, archive_file)
print >> sys.stderr, "bad zipfile [{0}]: {1} :: {2}".format(e, self.path, archive_file)
zf.close()
raise IOError
except Exception as e:
zf.close()
print "bad zipfile [{0}]: {1} :: {2}".format(e, self.path, archive_file)
print >> sys.stderr, "bad zipfile [{0}]: {1} :: {2}".format(e, self.path, archive_file)
raise IOError
finally:
zf.close()
@ -112,7 +112,7 @@ class ZipArchiver:
def rebuildZipFile( self, exclude_list ):
# this recompresses the zip archive, without the files in the exclude_list
#print "Rebuilding zip {0} without {1}".format( self.path, exclude_list )
#print ">> sys.stderr, Rebuilding zip {0} without {1}".format( self.path, exclude_list )
# generate temp file
tmp_fd, tmp_name = tempfile.mkstemp( dir=os.path.dirname(self.path) )
@ -215,7 +215,7 @@ class ZipArchiver:
if not self.writeZipComment( self.path, comment ):
return False
except Exception as e:
print "Error while copying to {0}: {1}".format(self.path, e)
print >> sys.stderr, "Error while copying to {0}: {1}".format(self.path, e)
return False
else:
return True
@ -294,22 +294,22 @@ class RarArchiver:
entries = rarc.read_files( archive_file )
if entries[0][0].size != len(entries[0][1]):
print "readArchiveFile(): [file is not expected size: {0} vs {1}] {2}:{3} [attempt # {4}]".format(
print >> sys.stderr, "readArchiveFile(): [file is not expected size: {0} vs {1}] {2}:{3} [attempt # {4}]".format(
entries[0][0].size,len(entries[0][1]), self.path, archive_file, tries)
continue
except (OSError, IOError) as e:
print "readArchiveFile(): [{0}] {1}:{2} attempt#{3}".format(str(e), self.path, archive_file, tries)
print >> sys.stderr, "readArchiveFile(): [{0}] {1}:{2} attempt#{3}".format(str(e), self.path, archive_file, tries)
time.sleep(1)
except Exception as e:
print "Unexpected exception in readArchiveFile(): [{0}] for {1}:{2} attempt#{3}".format(str(e), self.path, archive_file, tries)
print >> sys.stderr, "Unexpected exception in readArchiveFile(): [{0}] for {1}:{2} attempt#{3}".format(str(e), self.path, archive_file, tries)
break
else:
#Success"
#entries is a list of of tuples: ( rarinfo, filedata)
if tries > 1:
print "Attempted read_files() {0} times".format(tries)
print >> sys.stderr, "Attempted read_files() {0} times".format(tries)
if (len(entries) == 1):
return entries[0][1]
else:
@ -385,7 +385,7 @@ class RarArchiver:
namelist.append( item.filename )
except (OSError, IOError) as e:
print "getArchiveFilenameList(): [{0}] {1} attempt#{2}".format(str(e), self.path, tries)
print >> sys.stderr, "getArchiveFilenameList(): [{0}] {1} attempt#{2}".format(str(e), self.path, tries)
time.sleep(1)
else:
@ -403,7 +403,7 @@ class RarArchiver:
rarc = UnRAR2.RarFile( self.path )
except (OSError, IOError) as e:
print "getRARObj(): [{0}] {1} attempt#{2}".format(str(e), self.path, tries)
print >> sys.stderr, "getRARObj(): [{0}] {1} attempt#{2}".format(str(e), self.path, tries)
time.sleep(1)
else:
@ -666,7 +666,7 @@ class ComicArchive:
try:
image_data = self.archiver.readArchiveFile( filename )
except IOError:
print "Error reading in page. Substituting logo page."
print >> sys.stderr, "Error reading in page. Substituting logo page."
image_data = ComicArchive.logo_data
return image_data
@ -851,13 +851,13 @@ class ComicArchive:
def readRawCoMet( self ):
if not self.hasCoMet():
print self.path, "doesn't have CoMet data!"
print >> sys.stderr, self.path, "doesn't have CoMet data!"
return None
try:
raw_comet = self.archiver.readArchiveFile( self.comet_filename )
except IOError:
print "Error reading in raw CoMet!"
print >> sys.stderr, "Error reading in raw CoMet!"
raw_comet = ""
return raw_comet
@ -908,7 +908,7 @@ class ComicArchive:
data = self.archiver.readArchiveFile( n )
except:
data = ""
print "Error reading in Comet XML for validation!"
print >> sys.stderr, "Error reading in Comet XML for validation!"
if CoMet().validateString( data ):
# since we found it, save it!
self.comet_filename = n

View File

@ -62,8 +62,10 @@ class OnlineMatchResults():
self.goodMatches = []
self.noMatches = []
self.multipleMatches = []
self.writeFailures = []
self.lowConfidenceMatches = []
self.writeFailures = []
self.fetchDataFailures = []
#-----------------------------
def actual_issue_data_fetch( match, settings ):
@ -72,7 +74,7 @@ def actual_issue_data_fetch( match, settings ):
try:
cv_md = ComicVineTalker().fetchIssueData( match['volume_id'], match['issue_number'], settings )
except ComicVineTalkerException:
print "Network error while getting issue details. Save aborted"
print >> sys.stderr, "Network error while getting issue details. Save aborted"
return None
if settings.apply_cbl_transform_on_cv_import:
@ -85,18 +87,50 @@ def actual_metadata_save( ca, opts, md ):
if not opts.dryrun:
# write out the new data
if not ca.writeMetadata( md, opts.data_style ):
print "The tag save seemed to fail!"
print >> sys.stderr,"The tag save seemed to fail!"
return False
else:
print "Save complete."
print >> sys.stderr,"Save complete."
else:
if opts.terse:
print "dry-run option was set, so nothing was written"
print >> sys.stderr,"dry-run option was set, so nothing was written"
else:
print "dry-run option was set, so nothing was written, but here is the final set of tags:"
print >> sys.stderr,"dry-run option was set, so nothing was written, but here is the final set of tags:"
print u"{0}".format(md)
return True
def display_match_set_for_choice( label, match_set, opts, settings ):
print "{0} -- {1}:".format(match_set.filename, label )
# sort match list by year
match_set.matches.sort(key=lambda k: k['year'])
for (counter,m) in enumerate(match_set.matches):
counter += 1
print u" {0}. {1} #{2} [{3}] ({4}/{5}) - {6}".format(counter,
m['series'],
m['issue_number'],
m['publisher'],
m['month'],
m['year'],
m['issue_title'])
if opts.interactive:
while True:
i = raw_input("Choose a match #, or 's' to skip: ")
if (i.isdigit() and int(i) in range(1,len(match_set.matches)+1)) or i == 's':
break
if i != 's':
i = int(i) - 1
# save the data!
# we know at this point, that the file is all good to go
ca = ComicArchive( match_set.filename )
if settings.rar_exe_path != "":
ca.setExternalRarProgram( settings.rar_exe_path )
md = create_local_metadata( opts, ca, ca.hasMetadata(opts.data_style) )
cv_md = actual_issue_data_fetch(match_set.matches[int(i)], settings)
md.overlay( cv_md )
actual_metadata_save( ca, opts, md )
def post_process_matches( match_results, opts, settings ):
# now go through the match results
@ -119,44 +153,37 @@ def post_process_matches( match_results, opts, settings ):
for f in match_results.writeFailures:
print f
if len( match_results.fetchDataFailures ) > 0:
print "\nNetwork Data Fetch Failures:"
print "------------------"
for f in match_results.fetchDataFailures:
print f
if not opts.show_save_summary and not opts.interactive:
#jusr quit if we're not interactive or showing the summary
#just quit if we're not interactive or showing the summary
return
if len( match_results.multipleMatches ) > 0:
print "\nMultiple matches:"
print "\nArchives with multiple high-confidence matches:"
print "------------------"
for mm in match_results.multipleMatches:
print mm.filename
for (counter,m) in enumerate(mm.matches):
print u" {0}. {1} #{2} [{3}] ({4}/{5}) - {6}".format(counter,
m['series'],
m['issue_number'],
m['publisher'],
m['month'],
m['year'],
m['issue_title'])
if opts.interactive:
while True:
i = raw_input("Choose a match #, or 's' to skip: ")
if (i.isdigit() and int(i) in range(len(mm.matches))) or i == 's':
break
if i != 's':
# save the data!
# we know at this point, that the file is all good to go
ca = ComicArchive( mm.filename )
md = create_local_metadata( opts, ca, ca.hasMetadata(opts.data_style) )
cv_md = actual_issue_data_fetch(mm.matches[int(i)], settings)
md.overlay( cv_md )
actual_metadata_save( ca, opts, md )
print
for match_set in match_results.multipleMatches:
display_match_set_for_choice( "Multiple high-confidence matches", match_set, opts, settings )
if len( match_results.lowConfidenceMatches ) > 0:
print "\nArchives with low-confidence matches:"
print "------------------"
for match_set in match_results.lowConfidenceMatches:
if len( match_set.matches) == 1:
label = "Single low-confidence match"
else:
label = "Multiple low-confidence matches"
display_match_set_for_choice( label, match_set, opts, settings )
def cli_mode( opts, settings ):
if len( opts.file_list ) < 1:
print "You must specify at least one filename. Use the -h option for more info"
print >> sys.stderr,"You must specify at least one filename. Use the -h option for more info"
return
match_results = OnlineMatchResults()
@ -196,12 +223,12 @@ def process_file_cli( filename, opts, settings, match_results ):
ca.setExternalRarProgram( settings.rar_exe_path )
if not ca.seemsToBeAComicArchive():
print "Sorry, but "+ filename + " is not a comic archive!"
print >> sys.stderr,"Sorry, but "+ filename + " is not a comic archive!"
return
#if not ca.isWritableForStyle( opts.data_style ) and ( opts.delete_tags or opts.save_tags or opts.rename_file ):
if not ca.isWritable( ) and ( opts.delete_tags or opts.copy_tags or opts.save_tags or opts.rename_file ):
print "This archive is not writable for that tag type"
print >> sys.stderr,"This archive is not writable for that tag type"
return
has = [ False, False, False ]
@ -314,7 +341,7 @@ def process_file_cli( filename, opts, settings, match_results ):
return
if batch_mode:
print u"Processing {0}: ".format(filename)
print u"Processing {0}...".format(filename)
md = create_local_metadata( opts, ca, has[ opts.data_style ] )
@ -325,12 +352,14 @@ def process_file_cli( filename, opts, settings, match_results ):
try:
cv_md = ComicVineTalker().fetchIssueDataByIssueID( opts.issue_id, settings )
except ComicVineTalkerException:
print "Network error while getting issue details. Save aborted"
return None
print >> sys.stderr,"Network error while getting issue details. Save aborted"
match_results.fetchDataFailures.append(filename)
return
if cv_md is None:
print "No match for ID {0} was found.".format(opts.issue_id)
return None
print >> sys.stderr,"No match for ID {0} was found.".format(opts.issue_id)
match_results.noMatches.append(filename)
return
if settings.apply_cbl_transform_on_cv_import:
cv_md = CBLTransformer( cv_md, settings ).apply()
@ -338,7 +367,8 @@ def process_file_cli( filename, opts, settings, match_results ):
ii = IssueIdentifier( ca, settings )
if md is None or md.isEmpty:
print "No metadata given to search online with!"
print >> sys.stderr,"No metadata given to search online with!"
match_results.noMatches.append(filename)
return
def myoutput( text ):
@ -374,15 +404,20 @@ def process_file_cli( filename, opts, settings, match_results ):
choices = True
if choices:
print "Online search: Multiple matches. Save aborted"
match_results.multipleMatches.append(MultipleMatch(filename,matches))
return
if low_confidence:
print >> sys.stderr,"Online search: Multiple low confidence matches. Save aborted"
match_results.lowConfidenceMatches.append(MultipleMatch(filename,matches))
return
else:
print >> sys.stderr,"Online search: Multiple good matches. Save aborted"
match_results.multipleMatches.append(MultipleMatch(filename,matches))
return
if low_confidence and opts.abortOnLowConfidence:
print "Online search: Low confidence match. Save aborted"
match_results.noMatches.append(filename)
print >> sys.stderr,"Online search: Low confidence match. Save aborted"
match_results.lowConfidenceMatches.append(MultipleMatch(filename,matches))
return
if not found_match:
print "Online search: No match found. Save aborted"
print >> sys.stderr,"Online search: No match found. Save aborted"
match_results.noMatches.append(filename)
return
@ -392,6 +427,7 @@ def process_file_cli( filename, opts, settings, match_results ):
# now get the particular issue data
cv_md = actual_issue_data_fetch(matches[0], settings)
if cv_md is None:
match_results.fetchDataFailures.append(filename)
return
md.overlay( cv_md )
@ -416,7 +452,7 @@ def process_file_cli( filename, opts, settings, match_results ):
md = create_local_metadata( opts, ca, use_tags )
if md.series is None:
print msg_hdr + "Can't rename without series name"
print >> sys.stderr, msg_hdr + "Can't rename without series name"
return
new_ext = None # default
@ -434,7 +470,7 @@ def process_file_cli( filename, opts, settings, match_results ):
new_name = renamer.determineName( filename, ext=new_ext )
if new_name == os.path.basename(filename):
print msg_hdr + "Filename is already good!"
print >> sys.stderr, msg_hdr + "Filename is already good!"
return
folder = os.path.dirname( os.path.abspath( filename ) )
@ -471,7 +507,7 @@ def main():
if not qt_available and not opts.no_gui:
opts.no_gui = True
print "QT is not available."
print >> sys.stderr, "QT is not available."
if opts.no_gui:
cli_mode( opts, settings )

View File

@ -68,8 +68,9 @@ class ComicVineTalker(QObject):
def writeLog( self , text ):
if self.log_func is None:
sys.stdout.write(text.encode( errors='replace') )
sys.stdout.flush()
#sys.stdout.write(text.encode( errors='replace') )
#sys.stdout.flush()
print >> sys.stderr, text
else:
self.log_func( text )
@ -183,7 +184,7 @@ class ComicVineTalker(QObject):
cv_response = json.loads(content)
if cv_response[ 'status_code' ] != 1:
print ( "Comic Vine query failed with error: [{0}]. ".format( cv_response[ 'error' ] ))
print >> sys.stderr, "Comic Vine query failed with error: [{0}]. ".format( cv_response[ 'error' ] )
return None
volume_results = cv_response['results']
@ -211,7 +212,7 @@ class ComicVineTalker(QObject):
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' ] ))
print >> sys.stderr, "Comic Vine query failed with error: [{0}]. ".format( cv_response[ 'error' ] )
return None
issue_results = cv_response['results']
@ -227,7 +228,7 @@ class ComicVineTalker(QObject):
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' ] ))
print >> sys.stderr, "Comic Vine query failed with error: [{0}]. ".format( cv_response[ 'error' ] )
return None
issue_results = cv_response['results']
@ -355,7 +356,7 @@ class ComicVineTalker(QObject):
cv_response = json.loads(content)
if cv_response[ 'status_code' ] != 1:
print ( "Comic Vine query failed with error: [{0}]. ".format( cv_response[ 'error' ] ))
print >> sys.stderr, "Comic Vine query failed with error: [{0}]. ".format( cv_response[ 'error' ] )
return details
details['image_url'] = cv_response['results']['image']['super_url']
@ -456,7 +457,7 @@ class ComicVineTalker(QObject):
data = reply.readAll()
cv_response = json.loads(str(data))
if cv_response[ 'status_code' ] != 1:
print ( "Comic Vine query failed with error: [{0}]. ".format( cv_response[ 'error' ] ))
print >> sys.stderr, "Comic Vine query failed with error: [{0}]. ".format( cv_response[ 'error' ] )
return
image_url = cv_response['results']['image']['super_url']

View File

@ -178,7 +178,8 @@ class FileSelectionList(QWidget):
progdialog = QProgressDialog("", "Cancel", 0, len(filelist), self)
progdialog.setWindowTitle( "Adding Files" )
progdialog.setWindowModality(Qt.WindowModal)
#progdialog.setWindowModality(Qt.WindowModal)
progdialog.setWindowModality(Qt.ApplicationModal)
progdialog.show()
firstAdded = None
@ -189,7 +190,7 @@ class FileSelectionList(QWidget):
break
progdialog.setValue(idx)
progdialog.setLabelText(f)
utils.centerWindowOnScreen( progdialog )
utils.centerWindowOnParent( progdialog )
QCoreApplication.processEvents()
row = self.addPathItem( f )
if firstAdded is None and row is not None:

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 46 KiB

View File

@ -618,7 +618,6 @@ class IssueIdentifier:
self.log_msg( u"--------------------------------------------------")
self.search_result = self.ResultNoMatches
else:
print
self.log_msg( "More than one likley candiate." )
self.search_result = self.ResultMultipleGoodMatches
self.log_msg( u"--------------------------------------------------")

View File

@ -52,7 +52,6 @@ class IssueSelectionWindow(QtGui.QDialog):
QtCore.Qt.WindowSystemMenuHint |
QtCore.Qt.WindowMaximizeButtonHint)
self.setWindowModality(QtCore.Qt.WindowModal)
self.series_id = series_id
self.settings = settings
self.url_fetch_thread = None
@ -68,7 +67,6 @@ class IssueSelectionWindow(QtGui.QDialog):
self.twList.resizeColumnsToContents()
self.twList.currentItemChanged.connect(self.currentItemChanged)
self.twList.cellDoubleClicked.connect(self.cellDoubleClicked)
self.show()
#now that the list has been sorted, find the initial record, and select it
if self.initial_id is None:

View File

@ -4,9 +4,10 @@
---------------------------------
Changes:
* Enhanced identification process to use alternate covers from ComicVine
* Post auto-tag manual matching now includes single low-confidence matches (CLI & GUI)
* Page and cover view mini-browser available throughout app. Most images can be
double-clicked for embiggened view
* Misc GUI Tweaks
* Misc GUI & CLI Tweaks
---------------------------------
1.0.3-beta - 31-Jan-2013

View File

@ -374,7 +374,7 @@ class TaggerWindow( QtGui.QMainWindow):
progdialog = QtGui.QProgressDialog("", "Cancel", 0, rar_count, self)
progdialog.setWindowTitle( "Exporting as ZIP" )
progdialog.setWindowModality(QtCore.Qt.WindowModal)
progdialog.setWindowModality(QtCore.Qt.ApplicationModal)
progdialog.show()
prog_idx = 0
@ -392,7 +392,7 @@ class TaggerWindow( QtGui.QMainWindow):
progdialog.setValue(prog_idx)
prog_idx += 1
progdialog.setLabelText( ca.path )
utils.centerWindowOnScreen( progdialog )
utils.centerWindowOnParent( progdialog )
QtCore.QCoreApplication.processEvents()
original_path = os.path.abspath( ca.path )
@ -1379,7 +1379,7 @@ class TaggerWindow( QtGui.QMainWindow):
if reply == QtGui.QMessageBox.Yes:
progdialog = QtGui.QProgressDialog("", "Cancel", 0, has_md_count, self)
progdialog.setWindowTitle( "Removing Tags" )
progdialog.setWindowModality(QtCore.Qt.WindowModal)
progdialog.setWindowModality(QtCore.Qt.ApplicationModal)
progdialog.show()
prog_idx = 0
@ -1393,7 +1393,7 @@ class TaggerWindow( QtGui.QMainWindow):
progdialog.setValue(prog_idx)
prog_idx += 1
progdialog.setLabelText( ca.path )
utils.centerWindowOnScreen( progdialog )
utils.centerWindowOnParent( progdialog )
QtCore.QCoreApplication.processEvents()
if ca.hasMetadata( style ) and ca.isWritable():
@ -1456,7 +1456,7 @@ class TaggerWindow( QtGui.QMainWindow):
if reply == QtGui.QMessageBox.Yes:
progdialog = QtGui.QProgressDialog("", "Cancel", 0, has_src_count, self)
progdialog.setWindowTitle( "Copying Tags" )
progdialog.setWindowModality(QtCore.Qt.WindowModal)
progdialog.setWindowModality(QtCore.Qt.ApplicationModal)
progdialog.show()
prog_idx = 0
@ -1470,7 +1470,7 @@ class TaggerWindow( QtGui.QMainWindow):
progdialog.setValue(prog_idx)
prog_idx += 1
progdialog.setLabelText( ca.path )
utils.centerWindowOnScreen( progdialog )
utils.centerWindowOnParent( progdialog )
QtCore.QCoreApplication.processEvents()
if ca.hasMetadata( src_style ) and ca.isWritable():
@ -1670,7 +1670,7 @@ class TaggerWindow( QtGui.QMainWindow):
self.atprogdialog.progressBar.setValue( prog_idx )
prog_idx += 1
self.atprogdialog.label.setText( ca.path )
utils.centerWindowOnScreen( self.atprogdialog )
utils.centerWindowOnParent( self.atprogdialog )
QtCore.QCoreApplication.processEvents()
if ca.isWritable():

View File

@ -10,6 +10,13 @@ Docs:
Auto-Tagging Tips:
Multiple Passes with different options
CLI export:
-z, --export-to-zip export RAR archive to Zip format
--delete-rar-after-export delete original RAR archive after successful export to Zip
--delete-rar-after-export delete original RAR archive after successful export to Zip
--no-export-if-name-conflict about export to Zip if intended filename exists
Add beautiful soup (python-bs4) to wiki requirements
-----------------------------------------------------
Bugs
-----------------------------------------------------

View File

@ -550,3 +550,19 @@ if qt_available:
# And the move call repositions the window
window.move(hpos, vpos)
def centerWindowOnParent( window ):
top_level = window
while top_level.parent() is not None:
top_level = top_level.parent()
# Get the current screens' dimensions...
main_window_size = top_level.geometry()
# ... and get this windows' dimensions
mysize = window.geometry()
# The horizontal position is calulated as screenwidth - windowwidth /2
hpos = ( main_window_size.width() - window.width() ) / 2
# And vertical position the same, but with the height dimensions
vpos = ( main_window_size.height() - window.height() ) / 2
# And the move call repositions the window
window.move(hpos + main_window_size.left(), vpos + main_window_size.top())

View File

@ -231,8 +231,6 @@ class VolumeSelectionWindow(QtGui.QDialog):
def showIssues( self ):
selector = IssueSelectionWindow( self, self.settings, self.volume_id, self.issue_number )
selector.setModal(True)
title = ""
for record in self.cv_search_results:
if record['id'] == self.volume_id:
@ -242,6 +240,7 @@ class VolumeSelectionWindow(QtGui.QDialog):
break
selector.setWindowTitle( title + "Select Issue")
selector.setModal( True )
selector.exec_()
if selector.result():
#we should now have a volume ID

View File

@ -127,7 +127,7 @@
<item>
<widget class="QPushButton" name="btnAutoSelect">
<property name="text">
<string>Auto-Select</string>
<string>Auto-Identify</string>
</property>
</widget>
</item>