[Pywikipedia-l] SVN: [6609] trunk/pywikipedia

multichill at svn.wikimedia.org multichill at svn.wikimedia.org
Thu Apr 16 08:30:47 UTC 2009


Revision: 6609
Author:   multichill
Date:     2009-04-16 08:30:47 +0000 (Thu, 16 Apr 2009)

Log Message:
-----------
Remove wikipedia.setAction in replace.py and programs using this bot.

Modified Paths:
--------------
    trunk/pywikipedia/image.py
    trunk/pywikipedia/replace.py
    trunk/pywikipedia/standardize_notes.py
    trunk/pywikipedia/template.py

Modified: trunk/pywikipedia/image.py
===================================================================
--- trunk/pywikipedia/image.py	2009-04-15 17:53:59 UTC (rev 6608)
+++ trunk/pywikipedia/image.py	2009-04-16 08:30:47 UTC (rev 6609)
@@ -94,6 +94,7 @@
         self.generator = generator
         self.oldImage = oldImage
         self.newImage = newImage
+        self.editSummary = summary
         self.summary = summary
         self.always = always
         self.loose = loose
@@ -101,11 +102,11 @@
         # get edit summary message
         mysite = wikipedia.getSite()
         if summary:
-            wikipedia.setAction(summary)
+            self.editSummary = summary
         elif self.newImage:
-            wikipedia.setAction(wikipedia.translate(mysite, self.msg_replace) % (self.oldImage, self.newImage))
+            self.editSummary = wikipedia.translate(mysite, self.msg_replace) % (self.oldImage, self.newImage)
         else:
-            wikipedia.setAction(wikipedia.translate(mysite, self.msg_remove) % self.oldImage)
+            self.editSummary = wikipedia.translate(mysite, self.msg_remove) % self.oldImage
 
     def run(self):
         """
@@ -141,7 +142,7 @@
         else:
             replacements.append((ImageRegex, ''))
 
-        replaceBot = replace.ReplaceRobot(self.generator, replacements, acceptall = self.always)
+        replaceBot = replace.ReplaceRobot(self.generator, replacements, acceptall = self.always, editSummary = self.editSummary)
         replaceBot.run()
 
 def main():

Modified: trunk/pywikipedia/replace.py
===================================================================
--- trunk/pywikipedia/replace.py	2009-04-15 17:53:59 UTC (rev 6608)
+++ trunk/pywikipedia/replace.py	2009-04-16 08:30:47 UTC (rev 6609)
@@ -251,7 +251,7 @@
     """
     def __init__(self, generator, replacements, exceptions={},
                  acceptall=False, allowoverlap=False, recursive=False,
-                 addedCat=None, sleep=None):
+                 addedCat=None, sleep=None, editSummary=''):
         """
         Arguments:
             * generator    - A generator that yields Page objects.
@@ -292,6 +292,8 @@
         self.acceptall = acceptall
         self.allowoverlap = allowoverlap
         self.recursive = recursive
+        # Some function to set default editSummary should probably be added
+        self.editSummary = editSummary
         if addedCat:
             site = wikipedia.getSite()
             cat_ns = site.category_namespaces()[0]
@@ -419,12 +421,12 @@
                 if choice == 'a':
                     self.acceptall = True
                 if choice == 'y':
-                    page.put_async(new_text)
+                    page.put_async(new_text, self.editSummary)
                 # choice must be 'N'
                 break
             if self.acceptall and new_text != original_text:
                 try:
-                    page.put(new_text)
+                    page.put(new_text, self.editSummary)
                 except wikipedia.EditConflict:
                     wikipedia.output(u'Skipping %s because of edit conflict'
                                      % (page.title(),))
@@ -455,7 +457,7 @@
     add_cat = None
     gen = None
     # summary message
-    summary_commandline = None
+    summary_commandline = False
     # Array which will collect commandline parameters.
     # First element is original text, second element is replacement text.
     commandline_replacements = []
@@ -499,7 +501,7 @@
     genFactory = pagegenerators.GeneratorFactory()
     # Load default summary message.
     # BUG WARNING: This is probably incompatible with the -lang parameter.
-    wikipedia.setAction(wikipedia.translate(wikipedia.getSite(), msg))
+    editSummary = wikipedia.translate(wikipedia.getSite(), msg)
     # Between a regex and another (using -fix) sleep some time (not to waste
     # too much CPU
     sleep = None
@@ -555,7 +557,7 @@
         elif arg.startswith('-addcat:'):
             add_cat = arg[len('addcat:'):]
         elif arg.startswith('-summary:'):
-            wikipedia.setAction(arg[len('-summary:'):])
+            editSummary = arg[len('-summary:'):]
             summary_commandline = True
         elif arg.startswith('-allowoverlap'):
             allowoverlap = True
@@ -568,24 +570,21 @@
     elif (len(commandline_replacements) == 2 and fix == None):
         replacements.append((commandline_replacements[0],
                              commandline_replacements[1]))
-        if summary_commandline == None:
-            wikipedia.setAction(wikipedia.translate(wikipedia.getSite(), msg )
-                                % (' (-' + commandline_replacements[0] + ' +'
-                                   + commandline_replacements[1] + ')'))
+        if summary_commandline == False:
+            editSummary = wikipedia.translate(wikipedia.getSite(), msg ) % (' (-' + commandline_replacements[0] + ' +'
+                                   + commandline_replacements[1] + ')')
     elif (len(commandline_replacements) > 1):
         if (fix == None):
             for i in xrange (0, len(commandline_replacements), 2):
                 replacements.append((commandline_replacements[i],
                                      commandline_replacements[i + 1]))
-            if summary_commandline == None:
+            if summary_commandline == False:
                 pairs = [( commandline_replacements[i],
                            commandline_replacements[i + 1] )
                          for i in range(0, len(commandline_replacements), 2)]
                 replacementsDescription = '(%s)' % ', '.join(
                     [('-' + pair[0] + ' +' + pair[1]) for pair in pairs])
-                wikipedia.setAction(
-                    wikipedia.translate(wikipedia.getSite(), msg )
-                    % replacementsDescription)
+                editSummary = wikipedia.translate(wikipedia.getSite(), msg ) % replacementsDescription
         else:
            raise wikipedia.Error(
                'Specifying -fix with replacements is undefined')
@@ -611,7 +610,7 @@
 u'Press Enter to use this default message, or enter a description of the\nchanges your bot will make:')
             if summary_message == '':
                 summary_message = default_summary_message
-            wikipedia.setAction(summary_message)
+            editSummary = summary_message
 
     else:
         # Perform one of the predefined actions.
@@ -624,8 +623,7 @@
         if fix.has_key('regex'):
             regex = fix['regex']
         if fix.has_key('msg'):
-            wikipedia.setAction(
-                wikipedia.translate(wikipedia.getSite(), fix['msg']))
+            editSummary = wikipedia.translate(wikipedia.getSite(), fix['msg'])
         if fix.has_key('exceptions'):
             exceptions = fix['exceptions']
         if fix.has_key('nocase'):
@@ -699,7 +697,7 @@
                                             pageNumber=20, lookahead=100)
     else:
         preloadingGen = pagegenerators.PreloadingGenerator(gen, pageNumber=60)
-    bot = ReplaceRobot(preloadingGen, replacements, exceptions, acceptall, allowoverlap, recursive, add_cat, sleep)
+    bot = ReplaceRobot(preloadingGen, replacements, exceptions, acceptall, allowoverlap, recursive, add_cat, sleep, editSummary)
     bot.run()
 
 if __name__ == "__main__":

Modified: trunk/pywikipedia/standardize_notes.py
===================================================================
--- trunk/pywikipedia/standardize_notes.py	2009-04-15 17:53:59 UTC (rev 6608)
+++ trunk/pywikipedia/standardize_notes.py	2009-04-16 08:30:47 UTC (rev 6609)
@@ -1029,7 +1029,7 @@
     # default to -1 which means all namespaces will be processed
     namespace = -1
     # Load default summary message.
-    wikipedia.setAction(wikipedia.translate(wikipedia.getSite(), msg))
+    editSummary = wikipedia.translate(wikipedia.getSite(), msg)
     # List of references in Notes section
     references = []
     # Notes sequence number
@@ -1083,7 +1083,7 @@
         return
     if (len(commandline_replacements) == 2):
         replacements[commandline_replacements[0]] = commandline_replacements[1]
-        wikipedia.setAction(wikipedia.translate(wikipedia.getSite(), msg ) % ' (-' + commandline_replacements[0] + ' +' + commandline_replacements[1] + ')')
+        editSummary = wikipedia.translate(wikipedia.getSite(), msg ) % ' (-' + commandline_replacements[0] + ' +' + commandline_replacements[1] + ')'
     else:
         change = ''
         default_summary_message =  wikipedia.translate(wikipedia.getSite(), msg) % change
@@ -1091,7 +1091,7 @@
         summary_message = wikipedia.input(u'Press Enter to use this default message, or enter a description of the changes your bot will make:')
         if summary_message == '':
             summary_message = default_summary_message
-        wikipedia.setAction(summary_message)
+        editSummary = summary_message
 
         # Perform the predefined actions.
         try:
@@ -1102,14 +1102,14 @@
         if fix.has_key('regex'):
             regex = fix['regex']
         if fix.has_key('msg'):
-            wikipedia.setAction(wikipedia.translate(wikipedia.getSite(), fix['msg']))
+            editSummary = wikipedia.translate(wikipedia.getSite(), fix['msg'])
         if fix.has_key('exceptions'):
             exceptions = fix['exceptions']
         replacements = fix['replacements']
 
     gen = ReplacePageGenerator(source, replacements, exceptions, regex, namespace,  textfilename, sqlfilename, categoryname, pagenames)
     preloadingGen = pagegenerators.PreloadingGenerator(gen, pageNumber = 20)
-    bot = ReplaceRobot(preloadingGen, replacements, refsequence, references, refusage, exceptions, regex, acceptall)
+    bot = ReplaceRobot(preloadingGen, replacements, refsequence, references, refusage, exceptions, regex, acceptall, editSummary)
     bot.run()
 
 

Modified: trunk/pywikipedia/template.py
===================================================================
--- trunk/pywikipedia/template.py	2009-04-15 17:53:59 UTC (rev 6608)
+++ trunk/pywikipedia/template.py	2009-04-16 08:30:47 UTC (rev 6609)
@@ -294,27 +294,25 @@
         if self.addedCat:
             self.addedCat = catlib.Category(wikipedia.getSite(), 'Category:' + self.addedCat)
 
-        # get edit summary message
-        if self.editSummary:
-            wikipedia.setAction(self.editSummary)
-        else:
+        # get edit summary message if it's empty
+        if (self.editSummary==''):
             oldTemplateNames = (', ').join(self.templates.keys())
             mysite = wikipedia.getSite()
             if self.remove:
                 if len(self.templates) > 1:
-                    wikipedia.setAction(wikipedia.translate(mysite, self.msgs_remove) % oldTemplateNames)
+                    self.editSummary = wikipedia.translate(mysite, self.msgs_remove) % oldTemplateNames
                 else:
-                    wikipedia.setAction(wikipedia.translate(mysite, self.msg_remove) % oldTemplateNames)
+                    self.editSummary = wikipedia.translate(mysite, self.msg_remove) % oldTemplateNames
             elif self.subst:
                 if len(self.templates) > 1:
-                    wikipedia.setAction(wikipedia.translate(mysite, self.msgs_subst) % oldTemplateNames)
+                    self.editSummary = wikipedia.translate(mysite, self.msgs_subst) % oldTemplateNames
                 else:
-                    wikipedia.setAction(wikipedia.translate(mysite, self.msg_subst) % oldTemplateNames)
+                    self.editSummary = wikipedia.translate(mysite, self.msg_subst) % oldTemplateNames
             else:
                 if len(self.templates) > 1:
-                    wikipedia.setAction(wikipedia.translate(mysite, self.msgs_change) % oldTemplateNames)
+                    self.editSummary = wikipedia.translate(mysite, self.msgs_change) % oldTemplateNames
                 else:
-                    wikipedia.setAction(wikipedia.translate(mysite, self.msg_change) % oldTemplateNames)
+                    self.editSummary = wikipedia.translate(mysite, self.msg_change) % oldTemplateNames
 
     def run(self):
         """
@@ -343,7 +341,7 @@
             else:
                 replacements.append((templateRegex, '{{' + new + '\g<parameters>}}'))
 
-        replaceBot = replace.ReplaceRobot(self.generator, replacements, exceptions = {}, acceptall = self.acceptAll, addedCat=self.addedCat)
+        replaceBot = replace.ReplaceRobot(self.generator, replacements, exceptions = {}, acceptall = self.acceptAll, addedCat=self.addedCat, editSummary=self.editSummary)
         replaceBot.run()
 
 def main():





More information about the Pywikipedia-l mailing list