jenkins-bot has submitted this change and it was merged.
Change subject: Make transferbot exit cleanly when no arguments given.
......................................................................
Make transferbot exit cleanly when no arguments given.
Bug: 68662
Change-Id: If091461be0addece8600a413b7f64547e7cb7a8c
---
M scripts/transferbot.py
M tests/script_tests.py
2 files changed, 35 insertions(+), 4 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/transferbot.py b/scripts/transferbot.py
index 50372da..dcc6144 100644
--- a/scripts/transferbot.py
+++ b/scripts/transferbot.py
@@ -48,6 +48,29 @@
}
+class WikiTransferException(Exception):
+ """Base class for exceptions from this script.
+
+ Makes it easier for clients to catch all expected exceptions that the
script might
+ throw
+ """
+ pass
+
+
+class TargetSiteMissing(WikiTransferException):
+ """Thrown when the target site is the same as the source site.
+
+ Based on the way each are initialized, this is likely to happen when the
target site
+ simply hasn't been specified.
+ """
+ pass
+
+
+class TargetPagesMissing(WikiTransferException):
+ """Thrown if no page range has been specified for the script to operate
on."""
+ pass
+
+
def main():
tohandle = pywikibot.handleArgs()
@@ -75,11 +98,11 @@
tosite = pywikibot.Site(tolang, tofamily)
if fromsite == tosite:
- raise Exception('Target site not different from source site')
+ raise TargetSiteMissing('Target site not different from source site')
gen = genFactory.getCombinedGenerator()
if not gen:
- raise Exception('Target pages not specified')
+ raise TargetPagesMissing('Target pages not specified')
gen_args = ' '.join(gen_args)
pywikibot.output(u"""
@@ -129,4 +152,13 @@
if __name__ == "__main__":
- main()
+ try:
+ main()
+ except TargetSiteMissing as e:
+ pywikibot.error(u'Need to specify a target site and/or language')
+ pywikibot.error(u'Try running this script with -help for help/usage')
+ pywikibot.exception()
+ except TargetPagesMissing as e:
+ pywikibot.error(u'Need to specify a page range')
+ pywikibot.error(u'Try running this script with -help for help/usage')
+ pywikibot.exception()
diff --git a/tests/script_tests.py b/tests/script_tests.py
index 9b7ae9f..1e8e5a6 100644
--- a/tests/script_tests.py
+++ b/tests/script_tests.py
@@ -227,7 +227,6 @@
'imagerecat', # bug 68658
'imagetransfer', # bug 68659
'pagefromfile', # bug 68660
- 'transferbot', # raises custom Exception
'upload', # raises custom ValueError
] or \
(config.family == 'wikidata' and script_name ==
'lonelypages') or \
--
To view, visit https://gerrit.wikimedia.org/r/151808
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: If091461be0addece8600a413b7f64547e7cb7a8c
Gerrit-PatchSet: 5
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Audiodude <[email protected]>
Gerrit-Reviewer: Audiodude <[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