jenkins-bot merged this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[IMPR] Add prefix for filenames to UploadBot

Bug: T170123
Change-Id: I4ac4938f0d34451f3509de38710508e07ef6870f
---
M pywikibot/specialbots.py
M scripts/upload.py
2 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/pywikibot/specialbots.py b/pywikibot/specialbots.py
index 0818e72..9af4eb2 100644
--- a/pywikibot/specialbots.py
+++ b/pywikibot/specialbots.py
@@ -3,7 +3,7 @@
"""Library containing special bots."""
#
# (C) Rob W.W. Hooft, Andre Engels 2003-2004
-# (C) Pywikibot team, 2003-2017
+# (C) Pywikibot team, 2003-2018
#
# Distributed under the terms of the MIT license.
#
@@ -44,10 +44,9 @@

@deprecated_args(uploadByUrl=None)
def __init__(self, url, urlEncoding=None, description=u'',
- useFilename=None, keepFilename=False,
- verifyDescription=True, ignoreWarning=False,
- targetSite=None, aborts=[], chunk_size=0,
- summary=None, **kwargs):
+ useFilename=None, keepFilename=False, verifyDescription=True,
+ ignoreWarning=False, targetSite=None, aborts=[], chunk_size=0,
+ summary=None, filename_prefix=None, **kwargs):
"""
Constructor.

@@ -82,6 +81,9 @@
restartable) specified in bytes. If no value is specified the file
will be uploaded as whole.
@type chunk_size: integer
+ @param filename_prefix: Specify prefix for the title of every
+ file's page.
+ @type filename_prefix: string
@param always: Disables any input, requires that either ignoreWarning
or aborts are set to True and that the description is also set. It
overwrites verifyDescription to False and keepFilename to True.
@@ -112,6 +114,7 @@
self.aborts = aborts
self.chunk_size = chunk_size
self.summary = summary
+ self.filename_prefix = filename_prefix
if config.upload_to_commons:
self.targetSite = targetSite or pywikibot.Site('commons',
'commons')
@@ -249,6 +252,8 @@
filename = os.path.basename(filename)
if self.useFilename:
filename = self.useFilename
+ if self.filename_prefix:
+ filename = self.filename_prefix + filename
if not self.keepFilename:
pywikibot.output(
u"The filename on the target wiki will default to: %s"
diff --git a/scripts/upload.py b/scripts/upload.py
index 091457f..c0146d2 100755
--- a/scripts/upload.py
+++ b/scripts/upload.py
@@ -6,7 +6,8 @@
Arguments:

-keep Keep the filename as is
- -filename Target filename without the namespace prefix
+ -filename: Target filename without the namespace prefix
+ -prefix: Add specified prefix to every filename.
-noverify Do not ask for verification of the upload description if one
is given
-abortonwarn: Abort upload on the specified warning type. If no warning type
@@ -31,7 +32,7 @@
the 'exists' warning.
-recursive When the filename is a directory it also uploads the files from
the subdirectories.
- -summary Pick a custom edit summary for the bot.
+ -summary: Pick a custom edit summary for the bot.

It is possible to combine -abortonwarn and -ignorewarn so that if the specific
warning is given it won't apply the general one but more specific one. So if it
@@ -105,6 +106,7 @@
keepFilename = False
always = False
useFilename = None
+ filename_prefix = None
verifyDescription = True
aborts = set()
ignorewarn = set()
@@ -128,6 +130,8 @@
keepFilename = True
elif arg == '-filename':
useFilename = value
+ elif arg == '-prefix':
+ filename_prefix = value
elif arg == '-summary':
summary = value
elif arg == '-noverify':
@@ -196,10 +200,10 @@

bot = UploadRobot(url, description=description, useFilename=useFilename,
keepFilename=keepFilename,
- verifyDescription=verifyDescription,
- aborts=aborts, ignoreWarning=ignorewarn,
- chunk_size=chunk_size, always=always,
- summary=summary)
+ verifyDescription=verifyDescription, aborts=aborts,
+ ignoreWarning=ignorewarn, chunk_size=chunk_size,
+ always=always, summary=summary,
+ filename_prefix=filename_prefix)
bot.run()


To view, visit change 433823. To unsubscribe, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I4ac4938f0d34451f3509de38710508e07ef6870f
Gerrit-Change-Number: 433823
Gerrit-PatchSet: 3
Gerrit-Owner: Dvorapa <dvorapa@seznam.cz>
Gerrit-Reviewer: Dalba <dalba.wiki@gmail.com>
Gerrit-Reviewer: Dvorapa <dvorapa@seznam.cz>
Gerrit-Reviewer: Framawiki <framawiki@tools.wmflabs.org>
Gerrit-Reviewer: John Vandenberg <jayvdb@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: Zoranzoki21 <zorandori4444@gmail.com>
Gerrit-Reviewer: jenkins-bot <>