jenkins-bot has submitted this change and it was merged.
Change subject: Rewritten handling of generic integer arguments
......................................................................
Rewritten handling of generic integer arguments
Change-Id: Ic45856cc7ec894da67d97f75a38638b0806e5db4
---
M pywikibot/bot.py
1 file changed, 11 insertions(+), 12 deletions(-)
Approvals:
Merlijn van Deen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index 8aaa050..ba93c5b 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -622,17 +622,15 @@
import daemonize
daemonize.daemonize(redirect_std=arg[11:])
else:
- # the argument depends numerical config settings
- cmd = []
- if ':' in arg:
- cmd = arg[1:].split(':')
- if len(cmd) == 2 and len(cmd[1]) > 0 and \
- hasattr(config, cmd[0]) and \
- type(getattr(config, cmd[0])) == int:
- setattr(config, cmd[0], cmd[1])
- # the argument is not global. Let the specific bot script care
- # about it.
- else:
+ # the argument depends on numerical config settings
+ try:
+ _arg, _val = arg[1:].split(':')
+ # explicitly check for int (so bool doesn't match)
+ if type(getattr(config, _arg)) is not int:
+ raise TypeError
+ setattr(config, _arg, int(_val))
+ except (ValueError, TypeError) as exc:
+ # argument not global -> specific bot script will take care
nonGlobalArgs.append(arg)
if username:
@@ -647,7 +645,8 @@
# have to - some git versions (like 1.7.0.4) seem to treat lines
# containing just `$Id:` as if they were ident lines (see
# gitattributes(5)) leading to unwanted behaviour like automatic
- # replacement with `$Id$` or `$Id$`.
+ # replacement with `$Id$`
+ # or `$Id$`.
m = re.search(r"\$Id"
r": (\w+) \$", ver)
pywikibot.output(u'Pywikipediabot r%s' % m.group(1))
--
To view, visit https://gerrit.wikimedia.org/r/87639
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ic45856cc7ec894da67d97f75a38638b0806e5db4
Gerrit-PatchSet: 6
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: DrTrigon <dr.trigon(a)surfeu.ch>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Legoktm <legoktm.wikipedia(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
jenkins-bot has submitted this change and it was merged.
Change subject: login: add logout option and hidden password note
......................................................................
login: add logout option and hidden password note
- scripts/login.py now has the -logout option to log out
- when asking for a password, pywikibot/login.py will note no characters
will be shown
Change-Id: If25cb90bfdde8fac0ed6ad8a0c224e5f7e811fcb
---
M pywikibot/login.py
M pywikibot/site.py
M scripts/login.py
3 files changed, 29 insertions(+), 6 deletions(-)
Approvals:
Merlijn van Deen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/login.py b/pywikibot/login.py
index 49cebaa..872ad68 100644
--- a/pywikibot/login.py
+++ b/pywikibot/login.py
@@ -161,10 +161,9 @@
# As we don't want the password to appear on the screen, we set
# password = True
self.password = pywikibot.input(
- u'Password for user %(name)s on %(site)s:'
+ u'Password for user %(name)s on %(site)s (no characters will be shown):'
% {'name': self.username, 'site': self.site},
password=True)
-
# self.password = self.password.encode(self.site.encoding())
pywikibot.output(u"Logging in to %(site)s as %(name)s"
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 13477b0..52d97fe 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -883,6 +883,14 @@
forceLogin = login # alias for backward-compatibility
+ def logout(self):
+ uirequest = api.Request(site=self, action="logout")
+ uidata = uirequest.submit()
+ self._loginstatus = LoginStatus.NOT_LOGGED_IN
+ if hasattr(self, "_userinfo"):
+ del self._userinfo
+ self.getuserinfo()
+
def getuserinfo(self):
"""Retrieve userinfo from site and store in _userinfo attribute.
diff --git a/scripts/login.py b/scripts/login.py
index 53638e6..02a4590 100755
--- a/scripts/login.py
+++ b/scripts/login.py
@@ -8,9 +8,17 @@
Parameters:
+ -family:FF
+ -lang:LL Log in to the LL language of the FF family.
+ Example: -family:wiktionary -lang:fr will log you in at
+ fr.wiktionary.org.
+
-all Try to log in on all sites where a username is defined in
user-config.py.
+ -logout Log out of the curren site. Combine with -all to log out of
+ all sites, or with -family and -lang to log out of a specific
+ site.
-force Ignores if the user is already logged in, and tries to log in.
@@ -57,10 +65,11 @@
password = None
sysop = False
logall = False
+ logout = False
for arg in pywikibot.handleArgs(*args):
if arg.startswith("-pass"):
if len(arg) == 5:
- password = pywikibot.input(u'Password for all accounts:',
+ password = pywikibot.input(u'Password for all accounts (no characters will be shown):',
password=True)
else:
password = arg[6:]
@@ -71,6 +80,8 @@
elif arg == "-force":
pywikibot.output(u"To force a re-login, please delete the revelant lines from '%s' (or the entire file) and try again." %
join(config.base_dir, 'pywikibot.lwp'))
+ elif arg == "-logout":
+ logout = True
else:
pywikibot.showHelp('login')
return
@@ -86,13 +97,18 @@
for lang in namedict[familyName]:
try:
site = pywikibot.getSite(code=lang, fam=familyName)
- site.login()
-
+ if logout:
+ site.logout()
+ else:
+ site.login()
user = site.user()
if user:
pywikibot.output(u"Logged in on %(site)s as %(user)s." % locals())
else:
- pywikibot.output(u"Not logged in on %(site)s." % locals())
+ if logout:
+ pywikibot.output(u"Logged out of %(site)s." % locals())
+ else:
+ pywikibot.output(u"Not logged in on %(site)s." % locals())
except NoSuchSite:
pywikibot.output(u'%s.%s is not a valid site, please remove it'
u' from your config' % (lang, familyName))
--
To view, visit https://gerrit.wikimedia.org/r/79730
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: If25cb90bfdde8fac0ed6ad8a0c224e5f7e811fcb
Gerrit-PatchSet: 12
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: DrTrigon <dr.trigon(a)surfeu.ch>
Gerrit-Reviewer: Hashar <hashar(a)free.fr>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Legoktm <legoktm.wikipedia(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Multichill <maarten(a)mdammers.nl>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot