http://www.mediawiki.org/wiki/Special:Code/pywikipedia/9909
Revision: 9909 Author: drtrigon Date: 2012-02-17 23:09:15 +0000 (Fri, 17 Feb 2012) Log Message: ----------- follow-up to r9905 '-debug' replaced with new '-simulate' that allows switching off write access
Modified Paths: -------------- trunk/pywikipedia/clean_sandbox.py trunk/pywikipedia/config.py trunk/pywikipedia/query.py trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/clean_sandbox.py =================================================================== --- trunk/pywikipedia/clean_sandbox.py 2012-02-17 20:13:21 UTC (rev 9908) +++ trunk/pywikipedia/clean_sandbox.py 2012-02-17 23:09:15 UTC (rev 9909) @@ -187,12 +187,10 @@ if (pos < 0) or (endpos == len(text)): pywikibot.output(u'The user sandbox is still clean or not set up, no change necessary.') else: - if not pywikibot.debug: - sandboxPage.put(text[:endpos], translatedMsg) + sandboxPage.put(text[:endpos], translatedMsg) pywikibot.output(u'Standard content was changed, user sandbox cleaned.') else: - if not pywikibot.debug: - sandboxPage.put(translatedContent, translatedMsg) + sandboxPage.put(translatedContent, translatedMsg) pywikibot.output(u'Standard content was changed, sandbox cleaned.') else: diff = minutesDiff(sandboxPage.editTime(), time.strftime("%Y%m%d%H%M%S", time.gmtime())) @@ -200,8 +198,7 @@ print sandboxPage.editTime(), time.strftime("%Y%m%d%H%M%S", time.gmtime()) #Is the last edit more than 5 minutes ago? if diff >= self.delay: - if not pywikibot.debug: - sandboxPage.put(translatedContent, translatedMsg) + sandboxPage.put(translatedContent, translatedMsg) else: #wait for the rest pywikibot.output(u'Sleeping for %d minutes.' % (self.delay-diff)) time.sleep((self.delay-diff)*60) @@ -238,9 +235,6 @@ pywikibot.showHelp('clean_sandbox') return
- if pywikibot.debug: - pywikibot.output(u'\03{lightyellow}DEBUG: write actions blocked.\03{default}') - bot = SandboxBot(hours, no_repeat, delay, user) try: bot.run()
Modified: trunk/pywikipedia/config.py =================================================================== --- trunk/pywikipedia/config.py 2012-02-17 20:13:21 UTC (rev 9908) +++ trunk/pywikipedia/config.py 2012-02-17 23:09:15 UTC (rev 9909) @@ -464,6 +464,13 @@ # up to 30 minutes) retry_on_fail = True
+# Defines what actions the bots are NOT allowed to do (e.g. 'edit') on wikipedia +# servers. Setting this to: +# actions_to_block = ['edit', 'watch', 'move', 'delete', 'undelete', 'protect'] +# allows simulation runs of bots to be carried out without changing any page on +# the server side. +actions_to_block = [] + # How many pages should be put to a queue in asynchroneous mode. # If maxsize is <= 0, the queue size is infinite. # Increasing this value will increase memory space but could speed up
Modified: trunk/pywikipedia/query.py =================================================================== --- trunk/pywikipedia/query.py 2012-02-17 20:13:21 UTC (rev 9908) +++ trunk/pywikipedia/query.py 2012-02-17 23:09:15 UTC (rev 9909) @@ -42,6 +42,18 @@ sysop=False, back_response=False): """Get data from the query api, and convert it into a data object """ + if ('action' in params) and (params['action'] in pywikibot.config.actions_to_block): + pywikibot.output(u'\03{lightyellow}SIMULATION: %s action blocked.\03{default}'%\ + params['action']) + jsontext_dummy = {params['action']: {u'result':u''}} + if back_response: + import StringIO + res_dummy = StringIO.StringIO() + res_dummy.__dict__.update({u'code': 0, u'msg': u''}) + return res_dummy, jsontext_dummy + else: + return jsontext_dummy + if not site: site = pywikibot.getSite() data = {}
Modified: trunk/pywikipedia/wikipedia.py =================================================================== --- trunk/pywikipedia/wikipedia.py 2012-02-17 20:13:21 UTC (rev 9908) +++ trunk/pywikipedia/wikipedia.py 2012-02-17 23:09:15 UTC (rev 9909) @@ -7762,6 +7762,9 @@ elif arg == '-debug': debug = True config.special_page_limit = 500 + elif arg == '-simulate': + config.actions_to_block = ['edit', 'watch', 'move', 'delete', + 'undelete', 'protect'] else: # the argument is not global. Let the specific bot script care # about it. @@ -7827,10 +7830,14 @@
-verbose Have the bot provide additional output that may be -v useful in debugging. +-debug
-cosmeticchanges Toggles the cosmetic_changes setting made in config.py or -cc user_config.py to its inverse and overrules it. All other settings and restrictions are untouched. + +-simulate Toggles writing to the wikipedia server. Useful for testing + and debugging of new code. '''# % moduleName output(globalHelp, toStdout=True) try:
pywikipedia-svn@lists.wikimedia.org