jenkins-bot has submitted this change and it was merged.

Change subject: upload.py: Add option to automatically abort upload on warning
......................................................................


upload.py: Add option to automatically abort upload on warning

Useful when a script is issuing a batch of upload.py commands to upload
a lot of files, and we want to skip files that are already uploaded
without user intervention. Unfortunately, it will also skip the upload
if there are warnings not related to upload over an existing filename,
but because how warnings are handled, there's no way to tell what kind
of warning we've received.

Bug: 69852
Change-Id: I5e23049fb51f1804c230bff67525baa15e4c1f1c
---
M scripts/upload.py
1 file changed, 13 insertions(+), 4 deletions(-)

Approvals:
  John Vandenberg: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/scripts/upload.py b/scripts/upload.py
index 108f564..ba59729 100755
--- a/scripts/upload.py
+++ b/scripts/upload.py
@@ -9,6 +9,7 @@
   -filename     Target filename
   -noverify     Do not ask for verification of the upload description if one
                 is given
+  -abortonwarn  Abort upload on warning
 
 If any other arguments are given, the first is the URL or filename to upload,
 and the rest is a proposed description to go with the upload. If none of these
@@ -40,7 +41,7 @@
     def __init__(self, url, urlEncoding=None, description=u'',
                  useFilename=None, keepFilename=False,
                  verifyDescription=True, ignoreWarning=False,
-                 targetSite=None, uploadByUrl=False):
+                 targetSite=None, uploadByUrl=False, abortOnWarn=False):
         """
         @param ignoreWarning: Set this to True if you want to upload even if
             another file would be overwritten or another mistake would be
@@ -54,6 +55,7 @@
         self.keepFilename = keepFilename
         self.verifyDescription = verifyDescription
         self.ignoreWarning = ignoreWarning
+        self.abortOnWarn = abortOnWarn
         if config.upload_to_commons:
             self.targetSite = targetSite or pywikibot.Site('commons',
                                                            'commons')
@@ -218,8 +220,11 @@
         except pywikibot.UploadWarning as warn:
             pywikibot.output(u"We got a warning message: ", newline=False)
             pywikibot.output(str(warn))
-            answer = pywikibot.inputChoice(u"Do you want to ignore?",
-                                           ['Yes', 'No'], ['y', 'N'], 'N')
+            if self.abortOnWarn:
+                answer = "N"
+            else:
+                answer = pywikibot.inputChoice(u"Do you want to ignore?",
+                                               ['Yes', 'No'], ['y', 'N'], 'N')
             if answer == "y":
                 self.ignoreWarning = 1
                 self.keepFilename = True
@@ -252,6 +257,7 @@
     keepFilename = False
     useFilename = None
     verifyDescription = True
+    abortOnWarn = False
 
     # process all global bot args
     # returns a list of non-global args, i.e. args for upload.py
@@ -263,6 +269,8 @@
                 useFilename = arg[10:]
             elif arg.startswith('-noverify'):
                 verifyDescription = False
+            elif arg.startswith('-abortonwarn'):
+                abortOnWarn = True
             elif url == u'':
                 url = arg
             else:
@@ -270,7 +278,8 @@
     description = u' '.join(description)
     bot = UploadRobot(url, description=description, useFilename=useFilename,
                       keepFilename=keepFilename,
-                      verifyDescription=verifyDescription)
+                      verifyDescription=verifyDescription,
+                      abortOnWarn=abortOnWarn)
     bot.run()
 
 if __name__ == "__main__":

-- 
To view, visit https://gerrit.wikimedia.org/r/155560
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I5e23049fb51f1804c230bff67525baa15e4c1f1c
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Martineznovo <[email protected]>
Gerrit-Reviewer: John Vandenberg <[email protected]>
Gerrit-Reviewer: Ladsgroup <[email protected]>
Gerrit-Reviewer: Merlijn van Deen <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits

Reply via email to