http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10403
Revision: 10403 Author: xqt Date: 2012-06-21 13:03:17 +0000 (Thu, 21 Jun 2012) Log Message: ----------- -simulate option for rewrite branch
Modified Paths: -------------- branches/rewrite/pywikibot/bot.py branches/rewrite/pywikibot/config2.py branches/rewrite/pywikibot/data/api.py
Modified: branches/rewrite/pywikibot/bot.py =================================================================== --- branches/rewrite/pywikibot/bot.py 2012-06-21 10:37:49 UTC (rev 10402) +++ branches/rewrite/pywikibot/bot.py 2012-06-21 13:03:17 UTC (rev 10403) @@ -252,6 +252,7 @@ text = unicode(text, 'iso8859-1')
logger.log(_level, text, extra=context, **kwargs) + def output(text, decoder=None, newline=True, toStdout=False, **kwargs): """Output a message to the user via the userinterface.
@@ -431,6 +432,8 @@ elif arg == '-nolog': if moduleName in config.log: config.log.remove(moduleName) + elif arg == '-simulate': + config.simulate = True # # DEBUG control: #
Modified: branches/rewrite/pywikibot/config2.py =================================================================== --- branches/rewrite/pywikibot/config2.py 2012-06-21 10:37:49 UTC (rev 10402) +++ branches/rewrite/pywikibot/config2.py 2012-06-21 13:03:17 UTC (rev 10403) @@ -516,6 +516,16 @@ # Configuration variable 'socks' is defined but unknown. Misspelled?proxy = None proxy = None
+### Simulate settings ### +# Defines what actions the bots are NOT allowed to do (e.g. 'edit') on wikipedia +# servers. Allows simulation runs of bots to be carried out without changing any +# page on the server side. This setting may be overridden in user_config.py. +actions_to_block = ['edit', 'watch', 'move', 'delete', 'undelete', 'protect', + 'emailuser'] + +# Set simulate to True or use -simulate option to block all actions given above. +simulate = False + # 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: branches/rewrite/pywikibot/data/api.py =================================================================== --- branches/rewrite/pywikibot/data/api.py 2012-06-21 10:37:49 UTC (rev 10402) +++ branches/rewrite/pywikibot/data/api.py 2012-06-21 13:03:17 UTC (rev 10403) @@ -200,6 +200,13 @@ + self.http_params() )
+ def _simulate(self, action): + if action and config.simulate and action in config.actions_to_block: + pywikibot.output( + u'\03{lightyellow}SIMULATION: %s action blocked.\03{default}' + % action) + return {action: {'result': 'Success', 'nochange': ''}} + def submit(self): """Submit a query and parse the response.
@@ -213,6 +220,9 @@ paramstring = self.http_params() while True: action = self.params.get("action", "") + simulate = self._simulate(action) + if simulate: + return simulate self.site.throttle(write=self.write) uri = self.site.scriptpath() + "/api.php" try: