Audiodude has uploaded a new change for review.
https://gerrit.wikimedia.org/r/151808
Change subject: Change transferbot to define exceptions, then handle them in
the if __name__=='__main__' block.
......................................................................
Change transferbot to define exceptions, then handle them in the if
__name__=='__main__' block.
Change-Id: If091461be0addece8600a413b7f64547e7cb7a8c
---
M scripts/transferbot.py
1 file changed, 26 insertions(+), 3 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core
refs/changes/08/151808/1
diff --git a/scripts/transferbot.py b/scripts/transferbot.py
index 50372da..0015455 100644
--- a/scripts/transferbot.py
+++ b/scripts/transferbot.py
@@ -47,6 +47,15 @@
'¶ms;': pagegenerators.parameterHelp,
}
+# Class of exceptions for this script.
+class WikiTransferException(Exception):
+ pass
+
+class TargetSiteMissing(WikiTransferException):
+ pass
+
+class TargetPagesMissing(WikiTransferException):
+ pass
def main():
tohandle = pywikibot.handleArgs()
@@ -75,11 +84,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"""
@@ -127,6 +136,20 @@
pywikibot.log("Putting edit history.")
edithistpage.put(historytable, comment=summary)
+def _print_exc(exc, fh):
+ fh.write('ERROR: Try running this script with -help for help/usage\n')
+ fh.write('ERROR: Error message from script:\n')
+ fh.write('ERROR:\t%s\n' % exc.message)
if __name__ == "__main__":
- main()
+ import sys
+ try:
+ main()
+ except TargetSiteMissing as e:
+ sys.stderr.write('ERROR: Need to specify a target site and/or
language\n')
+ _print_exc(e, sys.stderr)
+ sys.exit(1)
+ except TargetPagesMissing as e:
+ sys.stderr.write('ERROR: Need to specify a page range\n')
+ _print_exc(e, sys.stderr)
+ sys.exit(1)
--
To view, visit https://gerrit.wikimedia.org/r/151808
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: If091461be0addece8600a413b7f64547e7cb7a8c
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Audiodude <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits