From aa286a9d0df6cbb95d71a1a413bd40c0dac04f2b Mon Sep 17 00:00:00 2001 From: Jim Miller Date: Thu, 10 Oct 2013 21:34:46 -0500 Subject: [PATCH] Change prints to logger calls and clean up some of them. --- calibre-plugin/__init__.py | 10 +++ calibre-plugin/config.py | 7 +- calibre-plugin/dialogs.py | 12 ++- calibre-plugin/ffdl_plugin.py | 83 +++++++++---------- calibre-plugin/jobs.py | 36 ++++---- downloader.py | 3 +- fanficdownloader/__init__.py | 21 +++-- .../adapters/adapter_restrictedsectionorg.py | 1 - fanficdownloader/epubutils.py | 17 ++-- fanficdownloader/htmlcleanup.py | 5 +- fanficdownloader/story.py | 2 +- fanficdownloader/writers/base_writer.py | 2 +- 12 files changed, 111 insertions(+), 88 deletions(-) diff --git a/calibre-plugin/__init__.py b/calibre-plugin/__init__.py index d3072444..8c38894e 100644 --- a/calibre-plugin/__init__.py +++ b/calibre-plugin/__init__.py @@ -7,6 +7,16 @@ __license__ = 'GPL v3' __copyright__ = '2013, Jim Miller' __docformat__ = 'restructuredtext en' +import sys +if sys.version_info >= (2, 7): + import logging + logger = logging.getLogger(__name__) + loghandler=logging.StreamHandler() + loghandler.setFormatter(logging.Formatter("FFDL:%(levelname)s:%(filename)s(%(lineno)d):%(message)s")) + logger.addHandler(loghandler) + loghandler.setLevel(logging.DEBUG) + logger.setLevel(logging.DEBUG) + # The class that all Interface Action plugin wrappers must inherit from from calibre.customize import InterfaceActionBase diff --git a/calibre-plugin/config.py b/calibre-plugin/config.py index 5e773e36..98c307ba 100644 --- a/calibre-plugin/config.py +++ b/calibre-plugin/config.py @@ -7,6 +7,9 @@ __license__ = 'GPL v3' __copyright__ = '2012, Jim Miller' __docformat__ = 'restructuredtext en' +import logging +logger = logging.getLogger(__name__) + import traceback, copy, threading from collections import OrderedDict @@ -523,7 +526,7 @@ class PersonalIniTab(QWidget): self.ini.setFont(QFont("Courier", self.plugin_action.gui.font().pointSize()+1)) except Exception as e: - print("Couldn't get font: %s"%e) + logger.error("Couldn't get font: %s"%e) self.ini.setLineWrapMode(QTextEdit.NoWrap) self.ini.setText(prefs['personal.ini']) self.l.addWidget(self.ini) @@ -559,7 +562,7 @@ class ShowDefaultsIniDialog(QDialog): self.ini.setFont(QFont("Courier", get_gui().font().pointSize()+1)) except Exception as e: - print("Couldn't get font: %s"%e) + logger.error("Couldn't get font: %s"%e) self.ini.setLineWrapMode(QTextEdit.NoWrap) self.ini.setText(text) self.ini.setReadOnly(True) diff --git a/calibre-plugin/dialogs.py b/calibre-plugin/dialogs.py index fee62951..bd05698f 100644 --- a/calibre-plugin/dialogs.py +++ b/calibre-plugin/dialogs.py @@ -7,9 +7,15 @@ __license__ = 'GPL v3' __copyright__ = '2011, Jim Miller' __docformat__ = 'restructuredtext en' +import logging +logger = logging.getLogger(__name__) + import traceback, re from functools import partial +import logging +logger = logging.getLogger(__name__) + import urllib import email @@ -207,7 +213,7 @@ class AddNewDialog(SizePersistedDialog): self.groupbox.setCheckable(True) self.groupbox.setChecked(False) self.groupbox.setFlat(True) - print("style:%s"%self.groupbox.styleSheet()) + #print("style:%s"%self.groupbox.styleSheet()) self.groupbox.setStyleSheet(gpstyle) self.gbf = QFrame() @@ -537,7 +543,7 @@ class LoopProgressDialog(QProgressDialog): def updateStatus(self): self.setLabelText("%s %d of %d"%(self.status_prefix,self.i+1,len(self.book_list))) self.setValue(self.i+1) - print(self.labelText()) + #print(self.labelText()) def do_loop(self): @@ -558,7 +564,7 @@ class LoopProgressDialog(QProgressDialog): except Exception as e: book['good']=False book['comment']=unicode(e) - print("Exception: %s:%s"%(book,unicode(e))) + logger.error("Exception: %s:%s"%(book,unicode(e))) traceback.print_exc() self.updateStatus() diff --git a/calibre-plugin/ffdl_plugin.py b/calibre-plugin/ffdl_plugin.py index 83cf0fea..f591f44d 100644 --- a/calibre-plugin/ffdl_plugin.py +++ b/calibre-plugin/ffdl_plugin.py @@ -7,6 +7,9 @@ __license__ = 'GPL v3' __copyright__ = '2012, Jim Miller' __docformat__ = 'restructuredtext en' +import logging +logger = logging.getLogger(__name__) + import time, os, copy, threading, re, platform, sys from StringIO import StringIO from functools import partial @@ -143,7 +146,7 @@ class FanFictionDownLoaderPlugin(InterfaceAction): file_path = os.path.join(calibre_config_dir, *("plugins/fanfictiondownloader_macmenuhack.txt".split('/'))) file_path = os.path.abspath(file_path) - print("Plugin %s macmenuhack file_path:%s"%(self.name,file_path)) + logger.debug("Plugin %s macmenuhack file_path:%s"%(self.name,file_path)) self.macmenuhack = os.access(file_path, os.F_OK) return self.macmenuhack @@ -387,7 +390,7 @@ class FanFictionDownLoaderPlugin(InterfaceAction): show_copy_button=False) def get_urls_from_page(self,url): - print("get_urls_from_page URL:%s"%url) + logger.debug("get_urls_from_page URL:%s"%url) if 'archiveofourown.org' in url: configuration = get_ffdl_config(url) else: @@ -541,7 +544,7 @@ class FanFictionDownLoaderPlugin(InterfaceAction): return tdir = PersistentTemporaryDirectory(prefix='ffdl_anthology_') - print("tdir:\n%s"%tdir) + logger.debug("tdir:\n%s"%tdir) bookepubio = StringIO(db.format(book_id,'EPUB',index_is_id=True)) @@ -617,7 +620,7 @@ class FanFictionDownLoaderPlugin(InterfaceAction): '''%(len(urlmapfile),"
  • ".join(urlmapfile.keys())) if not question_dialog(self.gui, 'Stories Removed', text, show_copy_button=False): - print("Canceling anthology update due to removed stories.") + logger.debug("Canceling anthology update due to removed stories.") return # Now that we've @@ -696,7 +699,7 @@ class FanFictionDownLoaderPlugin(InterfaceAction): books = self.convert_urls_to_books(url_list) options['version'] = self.version - print(self.version) + logger.debug(self.version) #print("prep_downloads:%s"%books) @@ -731,7 +734,7 @@ class FanFictionDownLoaderPlugin(InterfaceAction): ''' url = book['url'] - print("url:%s"%url) + logger.debug("url:%s"%url) mi = None if not merge: # skip reject list when merging. @@ -787,7 +790,7 @@ class FanFictionDownLoaderPlugin(InterfaceAction): try: adapter.getStoryMetadataOnly() except exceptions.FailedToLogin, f: - print("Login Failed, Need Username/Password.") + logger.warn("Login Failed, Need Username/Password.") userpass = UserPassDialog(self.gui,url,f) userpass.exec_() # exec_ will make it act modal if userpass.status: @@ -869,14 +872,14 @@ class FanFictionDownLoaderPlugin(InterfaceAction): if book['calibre_id'] != None: # updating an existing book. Update mode applies. - print("update existing id:%s"%book['calibre_id']) + logger.debug("update existing id:%s"%book['calibre_id']) book_id = book['calibre_id'] # No handling needed: OVERWRITEALWAYS,CALIBREONLY # only care about collisions when not ADDNEW elif collision != ADDNEW: # 'new' book from URL. collision handling applies. - print("from URL(%s)"%url) + logger.debug("from URL(%s)"%url) # try to find by identifier url or uri first. searchstr = 'identifiers:"~ur(i|l):=%s"'%url.replace(":","|") @@ -889,16 +892,16 @@ class FanFictionDownLoaderPlugin(InterfaceAction): ## meantime, if it matches the title *and* first ## 100 authors, I'm prepared to assume it's a ## match. - print("reduce author list to 100 only when calibre < 0.8.61") + logger.debug("reduce author list to 100 only when calibre < 0.8.61") authlist = authlist[:100] mi = MetaInformation(story.getMetadata("title", removeallentities=True), authlist) identicalbooks = db.find_identical_books(mi) if len(identicalbooks) > 0: - print("existing found by title/author(s)") + logger.debug("existing found by title/author(s)") else: - print("existing found by identifier URL") + logger.debug("existing found by identifier URL") if collision == SKIP and identicalbooks: raise NotGoingToDownload("Skipping duplicate story.","list_remove.png") @@ -997,7 +1000,7 @@ class FanFictionDownLoaderPlugin(InterfaceAction): suffix='.epub', dir=options['tdir']) db.copy_format_to(book_id,fileform,tmp,index_is_id=True) - print("existing epub tmp:"+tmp.name) + logger.debug("existing epub tmp:"+tmp.name) book['epub_for_update'] = tmp.name if book_id != None and prefs['injectseries']: @@ -1014,8 +1017,8 @@ class FanFictionDownLoaderPlugin(InterfaceAction): tmp = PersistentTemporaryFile(prefix=story.formatFileName("${title}-${author}-",allowunsafefilename=False)[:100], suffix='.'+options['fileform'], dir=options['tdir']) - print("title:"+book['title']) - print("outfile:"+tmp.name) + logger.debug("title:"+book['title']) + logger.debug("outfile:"+tmp.name) book['outfile'] = tmp.name return @@ -1093,7 +1096,7 @@ class FanFictionDownLoaderPlugin(InterfaceAction): if book['calibre_id'] and prefs['errorcol'] != '' and prefs['errorcol'] in custom_columns: label = custom_columns[prefs['errorcol']]['label'] if not book['good']: - print("record/update error message column %s %s"%(book['title'],book['url'])) + logger.debug("record/update error message column %s %s"%(book['title'],book['url'])) db.set_custom(book['calibre_id'], book['comment'], label=label, commit=True) # book['comment'] else: db.set_custom(book['calibre_id'], '', label=label, commit=True) # book['comment'] @@ -1101,7 +1104,7 @@ class FanFictionDownLoaderPlugin(InterfaceAction): if not book['good']: return # only update errorcol on error. - print("add/update %s %s"%(book['title'],book['url'])) + logger.debug("add/update %s %s"%(book['title'],book['url'])) mi = self.make_mi_from_book(book) if options['collision'] != CALIBREONLY: @@ -1113,7 +1116,7 @@ class FanFictionDownLoaderPlugin(InterfaceAction): self.update_metadata(db, book['calibre_id'], book, mi, options) except: det_msg = "".join(traceback.format_exception(*sys.exc_info()))+"\nStory Details:\n%s"%pretty_book(book) - print("Error Updating Metadata:\n%s"%det_msg) + logger.error("Error Updating Metadata:\n%s"%det_msg) error_dialog(self.gui, "Error Updating Metadata", "

    An error has occurred while FFDL was updating calibre's metadata for %s.

    "%(book['url'],book['title'])+ @@ -1170,19 +1173,7 @@ class FanFictionDownLoaderPlugin(InterfaceAction): self.gui.library_view.sort_by_named_field('marked', True) self.gui.status_bar.show_message(_('Finished Adding/Updating %d books.'%(len(update_list) + len(add_list))), 3000) - - 1+1 - - print("all done, remove temp dir.") - - 1+1 - remove_dir(options['tdir']) - - 1+1 - - print("removed temp dir.") - if 'Count Pages' in self.gui.iactions and len(prefs['countpagesstats']) and len(all_ids): cp_plugin = self.gui.iactions['Count Pages'] @@ -1277,7 +1268,7 @@ class FanFictionDownLoaderPlugin(InterfaceAction): (good_list,bad_list,options) = payload total_good = len(good_list) - print("merge titles:\n%s"%"\n".join([ "%s %s"%(x['title'],x['listorder']) for x in good_list ])) + logger.debug("merge titles:\n%s"%"\n".join([ "%s %s"%(x['title'],x['listorder']) for x in good_list ])) good_list = sorted(good_list,key=lambda x : x['listorder']) bad_list = sorted(bad_list,key=lambda x : x['listorder']) @@ -1303,8 +1294,8 @@ class FanFictionDownLoaderPlugin(InterfaceAction): # if still 'good', make a temp file to write the output to. tmp = PersistentTemporaryFile(suffix='.'+options['fileform'], dir=options['tdir']) - print("title:"+mergebook['title']) - print("outfile:"+tmp.name) + logger.debug("title:"+mergebook['title']) + logger.debug("outfile:"+tmp.name) mergebook['outfile'] = tmp.name self.get_epubmerge_plugin().do_merge(tmp.name, @@ -1352,7 +1343,7 @@ class FanFictionDownLoaderPlugin(InterfaceAction): def update_error_column_loop(self,book,db=None,label='errorcol'): if book['calibre_id']: - print("add/update bad %s %s %s"%(book['title'],book['url'],book['comment'])) + logger.debug("add/update bad %s %s %s"%(book['title'],book['url'],book['comment'])) db.set_custom(book['calibre_id'], book['comment'], label=label, commit=True) def add_book_or_update_format(self,book,options,prefs,mi=None): @@ -1382,7 +1373,7 @@ class FanFictionDownLoaderPlugin(InterfaceAction): fmts = db.formats(book['calibre_id'], index_is_id=True).split(',') for fmt in fmts: if fmt != formmapping[options['fileform']]: - print("remove f:"+fmt) + logger.debug("remove f:"+fmt) db.remove_format(book['calibre_id'], fmt, index_is_id=True)#, notify=False return book_id @@ -1423,7 +1414,7 @@ class FanFictionDownLoaderPlugin(InterfaceAction): try: db.set_cover(book_id, epubmi.cover_data[1]) except: - print("Failed to set_cover, skipping") + logger.info("Failed to set_cover, skipping") # implement 'newonly' flags here by setting to the current # value again. @@ -1436,7 +1427,7 @@ class FanFictionDownLoaderPlugin(InterfaceAction): try: mi.__setattr__(col,oldmi.__getattribute__(col)) except AttributeError: - print("AttributeError? %s"%col) + logger.warn("AttributeError? %s"%col) pass db.set_metadata(book_id,mi) @@ -1451,18 +1442,18 @@ class FanFictionDownLoaderPlugin(InterfaceAction): for col, meta in prefs['custom_cols'].iteritems(): #print("setting %s to %s"%(col,meta)) if col not in custom_columns: - print("%s not an existing column, skipping."%col) + logger.debug("%s not an existing column, skipping."%col) continue coldef = custom_columns[col] if col in prefs['custom_cols_newonly'] and prefs['custom_cols_newonly'][col] and not book['added']: - print("Skipping custom column(%s) update, set to New Books Only"%coldef['name']) + logger.debug("Skipping custom column(%s) update, set to New Books Only"%coldef['name']) continue if not meta.startswith('status-') and meta not in book['all_metadata'] or \ meta.startswith('status-') and 'status' not in book['all_metadata']: - print("No value for %s, skipping custom column(%s) update."%(meta,coldef['name'])) + logger.debug("No value for %s, skipping custom column(%s) update."%(meta,coldef['name'])) continue if meta not in permitted_values[coldef['datatype']]: - print("%s not a valid column type for %s, skipping."%(col,meta)) + logger.debug("%s not a valid column type for %s, skipping."%(col,meta)) continue label = coldef['label'] if coldef['datatype'] in ('enumeration','text','comments','datetime','series'): @@ -1491,7 +1482,7 @@ class FanFictionDownLoaderPlugin(InterfaceAction): (custcol,flag) = map( lambda x: x.strip(), custcol.split(",") ) if meta not in book['all_metadata']: - print("No value for %s, skipping custom column(%s) update."%(meta,custcol)) + logger.debug("No value for %s, skipping custom column(%s) update."%(meta,custcol)) continue if custcol not in custom_columns: @@ -1579,9 +1570,9 @@ class FanFictionDownLoaderPlugin(InterfaceAction): break if setting_name: - print("Generate Cover Setting from generate_cover_settings(%s)"%line) + logger.debug("Generate Cover Setting from generate_cover_settings(%s)"%line) if setting_name not in gc_plugin.get_saved_setting_names(): - print("GC Name %s not found, discarding! (check personal.ini for typos)"%setting_name) + logger.info("GC Name %s not found, discarding! (check personal.ini for typos)"%setting_name) setting_name = None if not setting_name and book['all_metadata']['site'] in prefs['gc_site_settings']: @@ -1591,7 +1582,7 @@ class FanFictionDownLoaderPlugin(InterfaceAction): setting_name = prefs['gc_site_settings']['Default'] if setting_name: - print("Running Generate Cover with settings %s."%setting_name) + logger.debug("Running Generate Cover with settings %s."%setting_name) realmi = db.get_metadata(book_id, index_is_id=True) gc_plugin.generate_cover_for_book(realmi,saved_setting_name=setting_name) @@ -1909,7 +1900,7 @@ class FanFictionDownLoaderPlugin(InterfaceAction): break configuration = get_ffdl_config(book['url'],fileform) - print("anthology_title_pattern:%s"%configuration.getConfig('anthology_title_pattern')) + logger.debug("anthology_title_pattern:%s"%configuration.getConfig('anthology_title_pattern')) if configuration.getConfig('anthology_title_pattern'): tmplt = Template(configuration.getConfig('anthology_title_pattern')) book['title'] = tmplt.safe_substitute({'title':book['title']}).encode('utf8') diff --git a/calibre-plugin/jobs.py b/calibre-plugin/jobs.py index a9879ff0..ca2ab21a 100644 --- a/calibre-plugin/jobs.py +++ b/calibre-plugin/jobs.py @@ -8,6 +8,9 @@ __copyright__ = '2012, Jim Miller' __copyright__ = '2011, Grant Drake ' __docformat__ = 'restructuredtext en' +import logging +logger = logging.getLogger(__name__) + import time, os, traceback from StringIO import StringIO @@ -38,13 +41,13 @@ def do_download_worker(book_list, options, ''' server = Server(pool_size=cpus) - print(options['version']) + logger.info(options['version']) total = 0 alreadybad = [] # Queue all the jobs - print("Adding jobs for URLs:") + logger.info("Adding jobs for URLs:") for book in book_list: - print("%s"%book['url']) + logger.info("%s"%book['url']) if book['good']: total += 1 args = ['calibre_plugins.fanfictiondownloader_plugin.jobs', @@ -87,19 +90,19 @@ def do_download_worker(book_list, options, count = count + 1 notification(float(count)/total, '%d of %d stories finished downloading'%(count,total)) # Add this job's output to the current log - print('Logfile for book ID %s (%s)'%(book_id, job._book['title'])) - print(job.details) + logger.info('Logfile for book ID %s (%s)'%(book_id, job._book['title'])) + logger.info(job.details) if count >= total: # All done! Output some lists for convenience of some users. - print("Successfully downloaded:") + logger.info("Successfully downloaded:") for book in book_list: if book['good']: - print("%s %s"%(book['title'],book['url'])) - print("\nUnsuccessful:") + logger.info("%s %s"%(book['title'],book['url'])) + logger.info("\nUnsuccessful:") for book in book_list: if not book['good']: - print("%s %s"%(book['title'],book['url'])) + logger.info("%s %s"%(book['title'],book['url'])) break server.close() @@ -147,7 +150,7 @@ def do_download_for_worker(book,options,notification=lambda x,y:x): ## No need to download at all. Shouldn't ever get down here. if options['collision'] in (CALIBREONLY): - print("Skipping CALIBREONLY 'update' down inside worker--this shouldn't be happening...") + logger.info("Skipping CALIBREONLY 'update' down inside worker--this shouldn't be happening...") book['comment'] = 'Metadata collected.' ## checks were done earlier, it's new or not dup or newer--just write it. @@ -170,7 +173,7 @@ def do_download_for_worker(book,options,notification=lambda x,y:x): if adapter.logfile: adapter.logfile = adapter.logfile.replace("span id","span notid") - print("write to %s"%outfile) + logger.info("write to %s"%outfile) writer.writeStory(outfilename=outfile, forceOverwrite=True) book['comment'] = 'Download %s completed, %s chapters.'%(options['fileform'],story.getMetadata("numChapters")) @@ -199,11 +202,12 @@ def do_download_for_worker(book,options,notification=lambda x,y:x): if chaptercount > urlchaptercount: raise NotGoingToDownload("Existing epub contains %d chapters, web site only has %d. Use Overwrite to force update." % (chaptercount,urlchaptercount),'dialog_error.png') - if adapter.getConfig("do_update_hook"): + if not (options['collision'] == UPDATEALWAYS and chaptercount == urlchaptercount) \ + and adapter.getConfig("do_update_hook"): chaptercount = adapter.hookForUpdates(chaptercount) - print("Do update - epub(%d) vs url(%d)" % (chaptercount, urlchaptercount)) - print("write to %s"%outfile) + logger.info("Do update - epub(%d) vs url(%d)" % (chaptercount, urlchaptercount)) + logger.info("write to %s"%outfile) writer.writeStory(outfilename=outfile, forceOverwrite=True) @@ -225,7 +229,7 @@ def do_download_for_worker(book,options,notification=lambda x,y:x): log = Log(level=Log.DEBUG) # report = [] - polish({outfile:outfile}, opts, log, print) # report.append + polish({outfile:outfile}, opts, log, logger.info) # report.append except NotGoingToDownload as d: book['good']=False @@ -237,7 +241,7 @@ def do_download_for_worker(book,options,notification=lambda x,y:x): book['comment']=unicode(e) book['icon']='dialog_error.png' book['status'] = 'Error' - print("Exception: %s:%s"%(book,unicode(e))) + logger.info("Exception: %s:%s"%(book,unicode(e))) traceback.print_exc() #time.sleep(10) diff --git a/downloader.py b/downloader.py index b7907772..1b0ac677 100644 --- a/downloader.py +++ b/downloader.py @@ -285,7 +285,8 @@ def main(argv, print "Do update - epub(%d) vs url(%d)" % (chaptercount, urlchaptercount) - if adapter.getConfig("do_update_hook"): + if not (options.update and chaptercount == urlchaptercount) \ + and adapter.getConfig("do_update_hook"): chaptercount = adapter.hookForUpdates(chaptercount) writeStory(configuration,adapter,"epub") diff --git a/fanficdownloader/__init__.py b/fanficdownloader/__init__.py index 93a4d070..17816cac 100644 --- a/fanficdownloader/__init__.py +++ b/fanficdownloader/__init__.py @@ -4,13 +4,16 @@ try: # just a way to switch between web service and CLI/PI import google.appengine.api except: - import sys - if sys.version_info >= (2, 7): - import logging - logger = logging.getLogger(__name__) - loghandler=logging.StreamHandler() - loghandler.setFormatter(logging.Formatter("FFDL:%(levelname)s:%(filename)s(%(lineno)d):%(message)s")) - logger.addHandler(loghandler) - loghandler.setLevel(logging.DEBUG) - logger.setLevel(logging.DEBUG) + try: # just a way to switch between CLI and PI + import calibre.constants + except: + import sys + if sys.version_info >= (2, 7): + import logging + logger = logging.getLogger(__name__) + loghandler=logging.StreamHandler() + loghandler.setFormatter(logging.Formatter("FFDL:%(levelname)s:%(filename)s(%(lineno)d):%(message)s")) + logger.addHandler(loghandler) + loghandler.setLevel(logging.DEBUG) + logger.setLevel(logging.DEBUG) diff --git a/fanficdownloader/adapters/adapter_restrictedsectionorg.py b/fanficdownloader/adapters/adapter_restrictedsectionorg.py index 686e053c..967dfd38 100644 --- a/fanficdownloader/adapters/adapter_restrictedsectionorg.py +++ b/fanficdownloader/adapters/adapter_restrictedsectionorg.py @@ -22,7 +22,6 @@ import re import urllib2 import cookielib as cl from datetime import datetime -import json from .. import BeautifulSoup as bs from ..htmlcleanup import stripHTML diff --git a/fanficdownloader/epubutils.py b/fanficdownloader/epubutils.py index f75f8531..9b2ca39b 100644 --- a/fanficdownloader/epubutils.py +++ b/fanficdownloader/epubutils.py @@ -7,6 +7,9 @@ __license__ = 'GPL v3' __copyright__ = '2012, Jim Miller' __docformat__ = 'restructuredtext en' +import logging +logger = logging.getLogger(__name__) + import re, os, traceback from zipfile import ZipFile from xml.dom.minidom import parseString @@ -72,7 +75,7 @@ def get_update_data(inputio, # remove all .. and the path part above it, if present. # Mostly for epubs edited by Sigil. src = re.sub(r"([^/]+/\.\./)","",src) - print("epubutils: found pre-existing cover image:%s"%src) + #print("epubutils: found pre-existing cover image:%s"%src) oldcoverimghref = src oldcoverimgdata = epub.read(src) for item in contentdom.getElementsByTagName("item"): @@ -81,8 +84,8 @@ def get_update_data(inputio, break oldcover = (oldcoverhtmlhref,oldcoverhtmltype,oldcoverhtmldata,oldcoverimghref,oldcoverimgtype,oldcoverimgdata) except Exception as e: - print("Cover Image %s not found"%src) - print("Exception: %s"%(unicode(e))) + logger.warn("Cover Image %s not found"%src) + logger.warn("Exception: %s"%(unicode(e))) traceback.print_exc() filecount = 0 @@ -118,8 +121,8 @@ def get_update_data(inputio, images[longdesc] = data img['src'] = img['longdesc'] except Exception as e: - print("Image %s not found!\n(originally:%s)"%(newsrc,longdesc)) - print("Exception: %s"%(unicode(e))) + logger.warn("Image %s not found!\n(originally:%s)"%(newsrc,longdesc)) + logger.warn("Exception: %s"%(unicode(e))) traceback.print_exc() soup = soup.find('body') # ffdl epubs have chapter title h3 @@ -143,8 +146,8 @@ def get_update_data(inputio, except: pass - for k in images.keys(): - print("\tlongdesc:%s\n\tData len:%s\n"%(k,len(images[k]))) + #for k in images.keys(): + #print("\tlongdesc:%s\n\tData len:%s\n"%(k,len(images[k]))) return (source,filecount,soups,images,oldcover,calibrebookmark,logfile) def get_path_part(n): diff --git a/fanficdownloader/htmlcleanup.py b/fanficdownloader/htmlcleanup.py index fc56ca89..09d29855 100644 --- a/fanficdownloader/htmlcleanup.py +++ b/fanficdownloader/htmlcleanup.py @@ -15,6 +15,9 @@ # limitations under the License. # +import logging +logger = logging.getLogger(__name__) + import re def _unirepl(match): @@ -31,7 +34,7 @@ def _unirepl(match): except: # This way, at least if there's more of entities out there # that fail, it doesn't blow the entire download. - print "Numeric entity translation failed, skipping: &#x%s%s"%(match.group(1),match.group(2)) + logger.warn("Numeric entity translation failed, skipping: &#x%s%s"%(match.group(1),match.group(2))) retval = "" return retval diff --git a/fanficdownloader/story.py b/fanficdownloader/story.py index 7def636a..a63d1e4c 100644 --- a/fanficdownloader/story.py +++ b/fanficdownloader/story.py @@ -631,7 +631,7 @@ class Story(Configurable): ext) self.imgtuples.append({'newsrc':newsrc,'mime':mime,'data':data}) - logger.debug("\nimgurl:%s\nnewsrc:%s\nimage size:%d\n"%(imgurl,newsrc,len(data))) + #logger.debug("\nimgurl:%s\nnewsrc:%s\nimage size:%d\n"%(imgurl,newsrc,len(data))) else: newsrc = self.imgtuples[self.imgurls.index(imgurl)]['newsrc'] diff --git a/fanficdownloader/writers/base_writer.py b/fanficdownloader/writers/base_writer.py index 4211de28..c26d4095 100644 --- a/fanficdownloader/writers/base_writer.py +++ b/fanficdownloader/writers/base_writer.py @@ -221,7 +221,7 @@ class BaseStoryWriter(Configurable): lastupdated=self.story.getMetadataRaw('dateUpdated').date() fileupdated=datetime.datetime.fromtimestamp(os.stat(outfilename)[8]).date() if fileupdated > lastupdated: - print "File(%s) Updated(%s) more recently than Story(%s) - Skipping" % (outfilename,fileupdated,lastupdated) + logger.warn("File(%s) Updated(%s) more recently than Story(%s) - Skipping" % (outfilename,fileupdated,lastupdated)) return if not metaonly: self.story = self.adapter.getStory() # get full story