Revision: 5611
Author: leogregianin
Date: 2008-06-23 02:44:29 +0000 (Mon, 23 Jun 2008)
Log Message:
-----------
Fixes: 1988532 fixing_redirects.py needs a batch option,
1880563 upgrade parameters in fixing_redirects.py
Modified Paths:
--------------
trunk/pywikipedia/fixing_redirects.py
Modified: trunk/pywikipedia/fixing_redirects.py
===================================================================
--- trunk/pywikipedia/fixing_redirects.py 2008-06-23 02:13:25 UTC (rev 5610)
+++ trunk/pywikipedia/fixing_redirects.py 2008-06-23 02:44:29 UTC (rev 5611)
@@ -8,6 +8,9 @@
-featured Run over featured pages
-page:XXX Run over only one page
+Run fixing_redirects.py -help to see all the command-line
+options -file, -ref, -links, ...
+
"""
#
# This script based on disambredir.py and solve_disambiguation.py
@@ -20,6 +23,12 @@
import pagegenerators
import re, sys
+# This is required for the text that is shown when you run this script
+# with the parameter -help.
+docuReplacements = {
+ '¶ms;': pagegenerators.parameterHelp,
+}
+
msg = {
'ar': u'بوت: إصلاح التحويلات',
'en': u'Bot: Fixing redirects',
@@ -122,6 +131,7 @@
return text
def workon(page):
+ mysite = wikipedia.getSite()
try:
text = page.get()
except wikipedia.IsRedirectPage:
@@ -139,12 +149,18 @@
comment = wikipedia.translate(mysite, msg)
page.put(text, comment)
-try:
+def main():
start = '!'
featured = False
title = None
namespace = None
+ gen = None
+ # This factory is responsible for processing command line arguments
+ # that are also used by other scripts and that determine on which pages
+ # to work on.
+ genFactory = pagegenerators.GeneratorFactory()
+
for arg in wikipedia.handleArgs():
if arg.startswith('-start'):
if len(arg) == 6:
@@ -163,6 +179,10 @@
namespace = int(wikipedia.input(u'Which namespace should be processed?'))
else:
namespace = int(arg[11:])
+ else:
+ generator = genFactory.handleArg(arg)
+ if generator:
+ gen = generator
mysite = wikipedia.getSite()
if mysite.sitename() == 'wikipedia:nl':
@@ -183,9 +203,14 @@
elif namespace is not None:
for page in pagegenerators.AllpagesPageGenerator(start=start, namespace=namespace, includeredirects=False):
workon(page)
+ elif gen:
+ for page in pagegenerators.PreloadingGenerator(gen):
+ workon(page)
else:
wikipedia.showHelp('fixing_redirects')
- sys.exit()
-finally:
- wikipedia.stopme()
+if __name__ == "__main__":
+ try:
+ main()
+ finally:
+ wikipedia.stopme()