Revision: 4128 Author: btongminh Date: 2007-08-29 13:06:56 +0000 (Wed, 29 Aug 2007)
Log Message: ----------- Handle EditConflicts; Don't report if the target page is the image itself; Link images.
Modified Paths: -------------- trunk/pywikipedia/image_replacer.py
Modified: trunk/pywikipedia/image_replacer.py =================================================================== --- trunk/pywikipedia/image_replacer.py 2007-08-29 07:33:28 UTC (rev 4127) +++ trunk/pywikipedia/image_replacer.py 2007-08-29 13:06:56 UTC (rev 4128) @@ -96,19 +96,28 @@ else: username = None + remove_from_list = [] for replacement in replacements: res = self.examine_revision_history( revisions, replacement, username) if res and self.allowed_replacement(replacement) and \ replacement.group(1) != replacement.group(2): self.cursor.execute(insert, res) - text = text.replace(replacement.group(0), '') + remove_from_list.append(replacement.group(0)) output('Replacing %s by %s: %s' % replacement.groups()) self.database.commit() - if text != old_text and self.config.get('clean_list', False): - page.put(text.strip(), comment = 'Removing images being processed') + if remove_from_list and self.config.get('clean_list', False): + while True: + try: + for remove in remove_from_list: + text = text.replace(remove, u'') + page.put(text.strip(), comment = 'Removing images being processed') + return + except wikipedia.EditConflict: + text = page.get() + def examine_revision_history(self, revisions, replacement, username): if replacement.group(0) in revisions[0][2]: return (db_timestamp(revisions[0][0]), @@ -194,9 +203,10 @@ # Threadsafety? site = wikipedia.getSite(family(wiki)) if unicode(site) == unicode(self.site): - title = u'%s:%s' % (site.namespace(namespace), page_title) + if (namespace, page_title) != (6, old_image): + title = u'[[:%s:%s]]' % (site.namespace(namespace), page_title) else: - title = u'%s:%s:%s' % (site_prefix(site), + title = u'[[:%s:%s:%s]]' % (site_prefix(site), site.namespace(namespace), page_title) not_ok_items.append(title)