Revision: 4578 Author: btongminh Date: 2007-11-21 09:45:28 +0000 (Wed, 21 Nov 2007)
Log Message: ----------- Better error handling
Modified Paths: -------------- trunk/pywikipedia/commonsdelinker/delinker.py trunk/pywikipedia/commonsdelinker/image_replacer.py
Modified: trunk/pywikipedia/commonsdelinker/delinker.py =================================================================== --- trunk/pywikipedia/commonsdelinker/delinker.py 2007-11-21 09:39:07 UTC (rev 4577) +++ trunk/pywikipedia/commonsdelinker/delinker.py 2007-11-21 09:45:28 UTC (rev 4578) @@ -275,26 +275,30 @@ # Code for checking user page existance has been moved # to summary() code, to avoid checking the user page # for each removal. - try: - new_text = ImmutableByReference(new_text) - m_summary = ImmutableByReference(summary) - if False is self.CommonsDelinker.exec_hook('before_save', - (page, text, new_text, m_summary)): - return 'skipped' - - if self.CommonsDelinker.config.get('edit', True) and not \ - ((self.CommonsDelinker.site.lang == 'commons') ^ \ - (config.usernames.get('commons', {}).get( - 'commons') == 'CommonsDelinker')): - page.put(new_text.get(), m_summary.get()) - return 'ok' - except wikipedia.EditConflict: - # Try again - output(u'Got EditConflict trying to remove %s from %s:%s.' % \ - (image, site, page_title)) - return self.replace_image(image, site, page_title, summary, replacement = None) - except (wikipedia.LockedPage, wikipedia.PageNotSaved): - return 'failed' + new_text = ImmutableByReference(new_text) + m_summary = ImmutableByReference(summary) + if False is self.CommonsDelinker.exec_hook('before_save', + (page, text, new_text, m_summary)): + return 'skipped' + + while True: + try: + if self.CommonsDelinker.config.get('edit', True) and not \ + ((self.CommonsDelinker.site.lang == 'commons') ^ \ + (config.usernames.get('commons', {}).get( + 'commons') == 'CommonsDelinker')): + page.put(new_text.get(), m_summary.get()) + return 'ok' + except wikipedia.ServerError, e: + output(u'Warning! ServerError: %s' % str(e)) + except wikipedia.EditConflict: + # Try again + output(u'Got EditConflict trying to remove %s from %s:%s.' % \ + (image, site, page_title)) + return self.replace_image(image, site, page_title, summary, replacement = None) + except (wikipedia.LockedPage, wikipedia.PageNotSaved): + return 'failed' + output(u'Retrying...') else: return 'skipped' return 'skipped'
Modified: trunk/pywikipedia/commonsdelinker/image_replacer.py =================================================================== --- trunk/pywikipedia/commonsdelinker/image_replacer.py 2007-11-21 09:39:07 UTC (rev 4577) +++ trunk/pywikipedia/commonsdelinker/image_replacer.py 2007-11-21 09:45:28 UTC (rev 4578) @@ -84,7 +84,9 @@ revisions = self.get_history(page.title(), since, username) # Fetch the page any way, to prevent editconflicts old_text = text = page.get() - except StandardError, e: + except (SystemExit, KeyboardInterrupt): + raise + except Exception, e: # Network error, not critical output(u'Warning! Unable to read replacement log.', False) output('%s: %s' % (e.__class__.__name__, str(e)), False)