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