Index: trunk/pywikipedia/clean_sandbox.py |
— | — | @@ -187,12 +187,10 @@ |
188 | 188 | if (pos < 0) or (endpos == len(text)): |
189 | 189 | pywikibot.output(u'The user sandbox is still clean or not set up, no change necessary.') |
190 | 190 | else: |
191 | | - if not pywikibot.debug: |
192 | | - sandboxPage.put(text[:endpos], translatedMsg) |
| 191 | + sandboxPage.put(text[:endpos], translatedMsg) |
193 | 192 | pywikibot.output(u'Standard content was changed, user sandbox cleaned.') |
194 | 193 | else: |
195 | | - if not pywikibot.debug: |
196 | | - sandboxPage.put(translatedContent, translatedMsg) |
| 194 | + sandboxPage.put(translatedContent, translatedMsg) |
197 | 195 | pywikibot.output(u'Standard content was changed, sandbox cleaned.') |
198 | 196 | else: |
199 | 197 | diff = minutesDiff(sandboxPage.editTime(), time.strftime("%Y%m%d%H%M%S", time.gmtime())) |
— | — | @@ -200,8 +198,7 @@ |
201 | 199 | print sandboxPage.editTime(), time.strftime("%Y%m%d%H%M%S", time.gmtime()) |
202 | 200 | #Is the last edit more than 5 minutes ago? |
203 | 201 | if diff >= self.delay: |
204 | | - if not pywikibot.debug: |
205 | | - sandboxPage.put(translatedContent, translatedMsg) |
| 202 | + sandboxPage.put(translatedContent, translatedMsg) |
206 | 203 | else: #wait for the rest |
207 | 204 | pywikibot.output(u'Sleeping for %d minutes.' % (self.delay-diff)) |
208 | 205 | time.sleep((self.delay-diff)*60) |
— | — | @@ -238,9 +235,6 @@ |
239 | 236 | pywikibot.showHelp('clean_sandbox') |
240 | 237 | return |
241 | 238 | |
242 | | - if pywikibot.debug: |
243 | | - pywikibot.output(u'\03{lightyellow}DEBUG: write actions blocked.\03{default}') |
244 | | - |
245 | 239 | bot = SandboxBot(hours, no_repeat, delay, user) |
246 | 240 | try: |
247 | 241 | bot.run() |
Index: trunk/pywikipedia/config.py |
— | — | @@ -464,6 +464,13 @@ |
465 | 465 | # up to 30 minutes) |
466 | 466 | retry_on_fail = True |
467 | 467 | |
| 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 | + |
468 | 475 | # How many pages should be put to a queue in asynchroneous mode. |
469 | 476 | # If maxsize is <= 0, the queue size is infinite. |
470 | 477 | # Increasing this value will increase memory space but could speed up |
Index: trunk/pywikipedia/wikipedia.py |
— | — | @@ -7762,6 +7762,9 @@ |
7763 | 7763 | elif arg == '-debug': |
7764 | 7764 | debug = True |
7765 | 7765 | config.special_page_limit = 500 |
| 7766 | + elif arg == '-simulate': |
| 7767 | + config.actions_to_block = ['edit', 'watch', 'move', 'delete', |
| 7768 | + 'undelete', 'protect'] |
7766 | 7769 | else: |
7767 | 7770 | # the argument is not global. Let the specific bot script care |
7768 | 7771 | # about it. |
— | — | @@ -7827,10 +7830,14 @@ |
7828 | 7831 | |
7829 | 7832 | -verbose Have the bot provide additional output that may be |
7830 | 7833 | -v useful in debugging. |
| 7834 | +-debug |
7831 | 7835 | |
7832 | 7836 | -cosmeticchanges Toggles the cosmetic_changes setting made in config.py or |
7833 | 7837 | -cc user_config.py to its inverse and overrules it. All other |
7834 | 7838 | settings and restrictions are untouched. |
| 7839 | + |
| 7840 | +-simulate Toggles writing to the wikipedia server. Useful for testing |
| 7841 | + and debugging of new code. |
7835 | 7842 | '''# % moduleName |
7836 | 7843 | output(globalHelp, toStdout=True) |
7837 | 7844 | try: |
Index: trunk/pywikipedia/query.py |
— | — | @@ -42,6 +42,18 @@ |
43 | 43 | sysop=False, back_response=False): |
44 | 44 | """Get data from the query api, and convert it into a data object |
45 | 45 | """ |
| 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 | + |
46 | 58 | if not site: |
47 | 59 | site = pywikibot.getSite() |
48 | 60 | data = {} |