Skip to content

Instantly share code, notes, and snippets.

@fmoo
Created November 14, 2012 15:51
Show Gist options
  • Save fmoo/4072914 to your computer and use it in GitHub Desktop.
Save fmoo/4072914 to your computer and use it in GitHub Desktop.
Clowny CLI script to get stuff out of the keyring
#!/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