Created
November 14, 2012 15:51
-
-
Save fmoo/4072914 to your computer and use it in GitHub Desktop.
Clowny CLI script to get stuff out of the keyring
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from __future__ import absolute_import | |
from argparse import ArgumentParser | |
from getpass import getuser, getpass | |
ap = ArgumentParser() | |
ap.add_argument('key') | |
ap.add_argument('user', default=getuser(), nargs='?', | |
help='username [%(default)s]') | |
ap.add_argument('--clear', action='store_true') | |
ns = ap.parse_args() | |
import keyring | |
if ns.clear: | |
keyring.set_password(ns.key, ns.user, '') | |
password = keyring.get_password(ns.key, ns.user) | |
if not password: | |
password = getpass('Password for %s: ' % (ns.user)) | |
keyring.set_password(ns.key, ns.user, password) | |
import sys | |
sys.stdout.write(password) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment