jenkins-bot submitted this change.

View Change


Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[FEAT] Add a -textfile parameter to fetch the text from a file

Change-Id: I9fa2dd9ff61e9744398ca19f6ce4b41d37cdaab2
---
M scripts/clean_sandbox.py
1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/scripts/clean_sandbox.py b/scripts/clean_sandbox.py
index 5c63464..23b0060 100755
--- a/scripts/clean_sandbox.py
+++ b/scripts/clean_sandbox.py
@@ -18,7 +18,10 @@
The minimum delay time is 5 minutes.

-text The text that substitutes in the sandbox, you can use this
- when you haven't configured clean_candbox for your wiki.
+ when you haven't configured clean_sandbox for your wiki.
+
+ -textfile As an alternative to -text, you can use this to provide
+ a file containing the text to be used.

-summary Summary of the edit made by bot. Overrides the default
from i18n.
@@ -272,6 +275,7 @@
:param args: command line arguments
"""
opts = {}
+ textfile_opt = None
local_args = pywikibot.handle_args(args)
gen_factory = pagegenerators.GeneratorFactory()
for arg in local_args:
@@ -287,11 +291,27 @@
elif opt == 'text':
opts[opt] = value or pywikibot.input(
'What text do you want to substitute?')
+ elif opt == 'textfile':
+ textfile_opt = value or pywikibot.input(
+ 'What file contains the text you want to substitute with?')
elif opt == 'summary':
opts[opt] = value or pywikibot.input('Enter the summary:')
else:
gen_factory.handle_arg(arg)

+ if textfile_opt:
+ if 'text' in opts:
+ pywikibot.error(
+ 'Arguments -text and -textfile '
+ "can't be provided at the same time")
+ return
+ try:
+ with open(textfile_opt, 'r', encoding='utf-8') as textfile:
+ opts['text'] = textfile.read()
+ except OSError as e:
+ pywikibot.error(f'Error loading {opts["textfile"]}: {e}')
+ return
+
generator = gen_factory.getCombinedGenerator()

bot = SandboxBot(generator=generator, **opts)

To view, visit change 860977. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I9fa2dd9ff61e9744398ca19f6ce4b41d37cdaab2
Gerrit-Change-Number: 860977
Gerrit-PatchSet: 7
Gerrit-Owner: Platonides <platonides@gmail.com>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki@aol.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged