Comment 11 for bug 432882

Revision history for this message
sentimental bryan (sentimental-bryan) wrote :

Just as some background, I'm trying to use it with offlineimap, which allows the user to include python functions to retrieve username or password.

% egrep "(passeval|py)" ~/.offlineimaprc
pythonfile = ~/.offlineimap.gnome.py
remotepasseval = get_password("offlineimap", "gmail.test.account")

% cat .offlineimap.gnome.py
#!/usr/bin/python

import sys
import pygtk
pygtk.require('2.0')
import gtk # sets app name
import gnomekeyring

def get_password(keyringid,identifier):
    #This pops up the password prompt but is currently broken
    #https://bugs.launchpad.net/ubuntu/+source/gnome-python-desktop/+bug/432882
    #gnomekeyring.unlock_sync(keyringid, None)
    for keyring in gnomekeyring.list_keyring_names_sync():
        if(keyring == keyringid):
            for id in gnomekeyring.list_item_ids_sync(keyring):
                item = gnomekeyring.item_get_info_sync(keyring, id)
                print(item.get_display_name())
                if(item.get_display_name() == identifier):
                    return item.get_secret()

def main():
    print( get_password("offlineimap","gmail.test.account") )

if __name__ == "__main__":
    main()