r9909 pywikipedia - Code Review archive

Repository:pywikipedia
Revision:r9908‎ | r9909 | r9910 >
Date:23:09, 17 February 2012
Author:drtrigon
Status:resolved (Comments)
Tags:
Comment:
follow-up to r9905 '-debug' replaced with new '-simulate' that allows switching off write access
Modified paths:
  • /trunk/pywikipedia/clean_sandbox.py (modified) (history)
  • /trunk/pywikipedia/config.py (modified) (history)
  • /trunk/pywikipedia/query.py (modified) (history)
  • /trunk/pywikipedia/wikipedia.py (modified) (history)

Diff [purge]

Index: trunk/pywikipedia/clean_sandbox.py
@@ -187,12 +187,10 @@
188188 if (pos < 0) or (endpos == len(text)):
189189 pywikibot.output(u'The user sandbox is still clean or not set up, no change necessary.')
190190 else:
191 - if not pywikibot.debug:
192 - sandboxPage.put(text[:endpos], translatedMsg)
 191+ sandboxPage.put(text[:endpos], translatedMsg)
193192 pywikibot.output(u'Standard content was changed, user sandbox cleaned.')
194193 else:
195 - if not pywikibot.debug:
196 - sandboxPage.put(translatedContent, translatedMsg)
 194+ sandboxPage.put(translatedContent, translatedMsg)
197195 pywikibot.output(u'Standard content was changed, sandbox cleaned.')
198196 else:
199197 diff = minutesDiff(sandboxPage.editTime(), time.strftime("%Y%m%d%H%M%S", time.gmtime()))
@@ -200,8 +198,7 @@
201199 print sandboxPage.editTime(), time.strftime("%Y%m%d%H%M%S", time.gmtime())
202200 #Is the last edit more than 5 minutes ago?
203201 if diff >= self.delay:
204 - if not pywikibot.debug:
205 - sandboxPage.put(translatedContent, translatedMsg)
 202+ sandboxPage.put(translatedContent, translatedMsg)
206203 else: #wait for the rest
207204 pywikibot.output(u'Sleeping for %d minutes.' % (self.delay-diff))
208205 time.sleep((self.delay-diff)*60)
@@ -238,9 +235,6 @@
239236 pywikibot.showHelp('clean_sandbox')
240237 return
241238
242 - if pywikibot.debug:
243 - pywikibot.output(u'\03{lightyellow}DEBUG: write actions blocked.\03{default}')
244 -
245239 bot = SandboxBot(hours, no_repeat, delay, user)
246240 try:
247241 bot.run()
Index: trunk/pywikipedia/config.py
@@ -464,6 +464,13 @@
465465 # up to 30 minutes)
466466 retry_on_fail = True
467467
 468+# Defines what actions the bots are NOT allowed to do (e.g. 'edit') on wikipedia
 469+# servers. Setting this to:
 470+# actions_to_block = ['edit', 'watch', 'move', 'delete', 'undelete', 'protect']
 471+# allows simulation runs of bots to be carried out without changing any page on
 472+# the server side.
 473+actions_to_block = []
 474+
468475 # How many pages should be put to a queue in asynchroneous mode.
469476 # If maxsize is <= 0, the queue size is infinite.
470477 # Increasing this value will increase memory space but could speed up
Index: trunk/pywikipedia/wikipedia.py
@@ -7762,6 +7762,9 @@
77637763 elif arg == '-debug':
77647764 debug = True
77657765 config.special_page_limit = 500
 7766+ elif arg == '-simulate':
 7767+ config.actions_to_block = ['edit', 'watch', 'move', 'delete',
 7768+ 'undelete', 'protect']
77667769 else:
77677770 # the argument is not global. Let the specific bot script care
77687771 # about it.
@@ -7827,10 +7830,14 @@
78287831
78297832 -verbose Have the bot provide additional output that may be
78307833 -v useful in debugging.
 7834+-debug
78317835
78327836 -cosmeticchanges Toggles the cosmetic_changes setting made in config.py or
78337837 -cc user_config.py to its inverse and overrules it. All other
78347838 settings and restrictions are untouched.
 7839+
 7840+-simulate Toggles writing to the wikipedia server. Useful for testing
 7841+ and debugging of new code.
78357842 '''# % moduleName
78367843 output(globalHelp, toStdout=True)
78377844 try:
Index: trunk/pywikipedia/query.py
@@ -42,6 +42,18 @@
4343 sysop=False, back_response=False):
4444 """Get data from the query api, and convert it into a data object
4545 """
 46+ if ('action' in params) and (params['action'] in pywikibot.config.actions_to_block):
 47+ pywikibot.output(u'\03{lightyellow}SIMULATION: %s action blocked.\03{default}'%\
 48+ params['action'])
 49+ jsontext_dummy = {params['action']: {u'result':u''}}
 50+ if back_response:
 51+ import StringIO
 52+ res_dummy = StringIO.StringIO()
 53+ res_dummy.__dict__.update({u'code': 0, u'msg': u''})
 54+ return res_dummy, jsontext_dummy
 55+ else:
 56+ return jsontext_dummy
 57+
4658 if not site:
4759 site = pywikibot.getSite()
4860 data = {}

Follow-up revisions

RevisionCommit summaryAuthorDate
r9924Modified help. Don't say Wikipedia, Pywiki works for every MediaWiki installa...binbot17:00, 24 February 2012
r10072raise NotImplementedError if -simulate option is given without API, follow-up...xqt19:42, 31 March 2012
r10353follow-up; enhance r9909 and r10174 to non-API callsdrtrigon09:10, 13 June 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r9905debugging '-debug' enabled for clean_sandboxdrtrigon13:47, 17 February 2012

Comments

#Comment by Xqt (talk | contribs)   17:38, 31 March 2012

What about any actions not done via api call but the old request?

Status & tagging log