| |
From: Cyde Weys <cydeweys@us...> - 2006-04-21 20:38
|
Update of /cvsroot/pywikipediabot/pywikipedia
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8480
Modified Files:
template.py
Log Message:
Added custom edit summary and automatically accept all changes parameters.
Index: template.py
===================================================================
RCS file: /cvsroot/pywikipediabot/pywikipedia/template.py,v
retrieving revision 1.38
retrieving revision 1.39
diff -C2 -d -r1.38 -r1.39
*** template.py 21 Apr 2006 16:20:54 -0000 1.38
--- template.py 21 Apr 2006 20:38:30 -0000 1.39
***************
*** 19,23 ****
argument can also be given as "-xml:filename.xml".
! -namespace -Only process templates in the given template number (may be used multiple times)
other: First argument is the old template name, second one is the new
--- 19,29 ----
argument can also be given as "-xml:filename.xml".
! -namespace - Only process templates in the given template number (may be used
! multiple times).
!
! -summary - Lets you pick a custom edit summary. Use quotes if edit summary contains
! spaces.
!
! -always - Don't bother asking to confirm any of the changes, Just Do It.
other: First argument is the old template name, second one is the new
***************
*** 29,33 ****
marks around it.
! Example:
If you have a template called [[Template:Cities in Washington]] and want to
--- 35,39 ----
marks around it.
! Examples:
If you have a template called [[Template:Cities in Washington]] and want to
***************
*** 47,50 ****
--- 53,64 ----
This may differ on other projects so make sure to find out the appropriate namespace numbers.
+
+ This next example substitutes the template lived with a supplied edit summary. It only
+ performs substitutions in main article namespace and doesn't prompt to start replacing.
+ Note that -putthrottle: is a global pywikipedia parameter.
+
+ python template.py -putthrottle:30 -namespace:0 lived -always
+ -summary:"ROBOT: Substituting {{lived}}, see [[WP:SUBST]]."
+
"""
#
***************
*** 125,129 ****
}
! def __init__(self, generator, old, new = None, remove = False):
"""
Arguments:
--- 139,143 ----
}
! def __init__(self, generator, old, new = None, remove = False, customSummary = False, editSummary = '', acceptAll = False):
"""
Arguments:
***************
*** 139,152 ****
self.new = new
self.remove = remove
# if only one argument is given, don't replace the template with another
# one, but resolve the template by putting its text directly into the
# article.
self.resolve = (new == None)
# get edit summary message
! mysite = wikipedia.getSite()
! if self.remove:
! wikipedia.setAction(wikipedia.translate(mysite, self.msg_remove) % old)
! else:
! wikipedia.setAction(wikipedia.translate(mysite, self.msg_change) % old)
def run(self):
--- 153,173 ----
self.new = new
self.remove = remove
+ self.customSummary = customSummary
+ self.editSummary = editSummary
+ self.acceptAll = acceptAll
# if only one argument is given, don't replace the template with another
# one, but resolve the template by putting its text directly into the
# article.
self.resolve = (new == None)
+
# get edit summary message
! if self.customSummary:
! wikipedia.setAction(editSummary)
! else:
! mysite = wikipedia.getSite()
! if self.remove:
! wikipedia.setAction(wikipedia.translate(mysite, self.msg_remove) % old)
! else:
! wikipedia.setAction(wikipedia.translate(mysite, self.msg_change) % old)
def run(self):
***************
*** 172,176 ****
else:
replacements.append((templateRegex, '{{' + self.new + '\g<parameters>}}'))
! replaceBot = replace.ReplaceRobot(self.generator, replacements)
replaceBot.run()
--- 193,199 ----
else:
replacements.append((templateRegex, '{{' + self.new + '\g<parameters>}}'))
!
! #Note that the [] parameter here is for exceptions (see replace.py). For now we don't use it.
! replaceBot = replace.ReplaceRobot(self.generator, replacements, [], self.acceptAll)
replaceBot.run()
***************
*** 180,183 ****
--- 203,209 ----
remove = False
namespaces = []
+ customSummary = False
+ editSummary = ''
+ acceptAll = False
# If xmlfilename is None, references will be loaded from the live wiki.
xmlfilename = None
***************
*** 194,197 ****
--- 220,228 ----
elif arg.startswith('-namespace:'):
namespaces.append(int(arg[len('-namespace:'):]))
+ elif arg.startswith('-summary:'):
+ customSummary = True
+ editSummary = arg[len('-summary:'):]
+ elif arg.startswith('-always'):
+ acceptAll = True
else:
template_names.append(arg)
***************
*** 217,221 ****
loadingGen = pagegenerators.PreloadingGenerator(gen)
! bot = TemplateRobot(loadingGen, old, new, remove)
bot.run()
--- 248,252 ----
loadingGen = pagegenerators.PreloadingGenerator(gen)
! bot = TemplateRobot(loadingGen, old, new, remove, customSummary, editSummary, acceptAll)
bot.run()
|
|