A bunch of stuff from the past few days.
    
        | author | 
        Steve Losh <steve@stevelosh.com> | 
    
    
        | date | 
        Thu, 08 Sep 2011 09:20:01 -0400 | 
    
    
        | parents | 
        c6446e280dab  | 
    
    
        | children | 
        dbcbfa37f036  | 
    
#!/usr/bin/python
import re, subprocess
def get_keychain_pass(account=None, server=None):
    params = {
        'security': '/usr/bin/security',
        'command': 'find-internet-password',
        'account': account,
        'server': server,
        'keychain': '/Users/sjl/Library/Keychains/login.keychain',
    }
    command = "sudo -u sjl %(security)s -v %(command)s -g -a %(account)s -s %(server)s %(keychain)s" % params
    output = subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT)
    outtext = [l for l in output.splitlines()
               if l.startswith('password: ')][0]
    return re.match(r'password: "(.*)"', outtext).group(1)