mutt/offlineimap.py @ 3d37ca22c5c5 bpollack/use-command-to-explicitly-call-ag-and-us-1442506830050

Use command to explicitly call ag, and use compound if block
author Benjamin Pollack <benjamin@bitquabit.com>
date Thu, 17 Sep 2015 16:20:42 +0000
parents dbcbfa37f036
children (none)
#!/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/`whoami`/Library/Keychains/login.keychain',
    }
    command = "sudo -u `whoami` %(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)