jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/508278 )
Change subject: [IMPR] Reduce code complexity of welcome.py ......................................................................
[IMPR] Reduce code complexity of welcome.py
- split main function into parts to reduce code complexity reported by codeclimate as "critical" - remove issue_deprecation_warning which is 3 years old and replace it with a simple warning of unknown option.
Change-Id: I4c23bf754872ba48c496862104bfe48aa37a1e94 --- M scripts/welcome.py 1 file changed, 32 insertions(+), 22 deletions(-)
Approvals: Lokal Profil: Looks good to me, approved jenkins-bot: Verified
diff --git a/scripts/welcome.py b/scripts/welcome.py index df48877..bacf376 100755 --- a/scripts/welcome.py +++ b/scripts/welcome.py @@ -181,7 +181,7 @@ from pywikibot import config, i18n from pywikibot.exceptions import HiddenKeyError from pywikibot.tools.formatter import color_format -from pywikibot.tools import issue_deprecation_warning, PY2, UnicodeType +from pywikibot.tools import PY2, UnicodeType
if PY2: import cPickle as pickle # noqa: N813 @@ -922,9 +922,25 @@ globalvar = Global()
-def main(*args): - """ - Process command line arguments and invoke bot. +def _handle_offset(val): + """Handle -offset arg.""" + if not val: + val = pywikibot.input( + 'Which time offset for new users would you like to use? ' + '(yyyymmddhhmmss or yyyymmdd)') + try: + globalvar.offset = pywikibot.Timestamp.fromtimestampformat(val) + except ValueError: + # upon request, we could check for software version here + raise ValueError(fill( + 'Mediawiki has changed, -offset:# is not supported anymore, but ' + '-offset:TIMESTAMP is, assuming TIMESTAMP is yyyymmddhhmmss or ' + 'yyyymmdd. -timeoffset is now also supported. Please read this ' + 'script source header for documentation.')) + + +def handle_args(args): + """Process command line arguments.
If args is an empty list, sys.argv is used.
@@ -932,7 +948,7 @@ @type args: str """ for arg in pywikibot.handle_args(args): - arg, sep, val = arg.partition(':') + arg, _, val = arg.partition(':') if arg == '-edit': globalvar.attachEditCount = int(val or pywikibot.input( 'After how many edits would you like to welcome new users? ' @@ -946,20 +962,7 @@ 'For how many seconds would you like to bot to sleep before ' 'checking again?')) elif arg == '-offset': - if not val: - val = pywikibot.input( - 'Which time offset for new users would you like to use? ' - '(yyyymmddhhmmss or yyyymmdd)') - try: - globalvar.offset = pywikibot.Timestamp.fromtimestampformat(val) - except ValueError: - # upon request, we could check for software version here - raise ValueError(fill( - 'Mediawiki has changed, -offset:# is not supported ' - 'anymore, but -offset:TIMESTAMP is, assuming TIMESTAMP is ' - 'yyyymmddhhmmss or yyyymmdd. -timeoffset is now also ' - 'supported. Please read this script source header for ' - 'documentation.')) + _handle_offset(val) elif arg == '-file': globalvar.randomSign = True globalvar.signFileName = val or pywikibot.input( @@ -991,10 +994,17 @@ 'welcome log?')) elif arg == '-quiet': globalvar.quiet = True - elif arg == '-quick': - issue_deprecation_warning('The usage of "-quick" option', None, 2, - since='20160211') + else: + pywikibot.warning('Unknown option "{}"'.format(arg))
+ +def main(*args): + """Invoke bot. + + @param args: command line arguments + @type args: str + """ + handle_args(args) # Filename and Pywikibot path # file where is stored the random signature index filename = pywikibot.config.datafilepath('welcome-%s-%s.data'
pywikibot-commits@lists.wikimedia.org