def __init__(self, path): "new(path) path - location of the glade file" gladefile = os.path.join(path, "PyGtkGpgKeys.glade") self.wtree = gtk.glade.XML(gladefile) self.wtree.signal_autoconnect(self) self.mainwin = self.wtree.get_widget("GPGAdminWindow") self.treeview = self.wtree.get_widget("GPGKeysView") self.model = gtk.TreeStore( *[x.type for x in visible_columns + helper_columns]) self.context = Context() self.context.set_passphrase_cb(self.get_password, "") self.progress = None self.context.set_progress_cb(self.gen_progress, None) # Use mode.SIGS to include signatures in the list. self.context.set_keylist_mode(mode.SIGS) self.load_keys(True) self.treeview.set_model(self.model) self.treeview.get_selection().set_mode(gtk.SELECTION_MULTIPLE) self.add_columns() gtk.main()
def load_keys(): "Download keys from the keyring" context = Context() sec_keys = {} for key in context.op_keylist_all(None, 1): sec_keys[key.subkeys[0].fpr] = 1 # print sec_keys context.set_keylist_mode(keylist.mode.SIGS) for key in context.op_keylist_all(None, 0): secret = sec_keys.has_key(key.subkeys[0].fpr) # print key, secret if key.can_encrypt: print key
stat2str[getattr(status, name)] = name # Print the output received since the last prompt before giving the new prompt def edit_fnc(stat, args, helper): global stat_strings try: while True: helper["data"].seek(helper["skip"], 0) data = helper["data"].read() helper["skip"] += len(data) print data return raw_input("(%s) %s > " % (stat2str[stat], args)) except EOFError: pass # Simple interactive editor to test editor scripts if len(sys.argv) != 2: sys.stderr.write("Usage: %s <Gpg key patter>\n" % sys.argv[0]) else: c = Context() out = Data() c.op_keylist_start(sys.argv[1], 0) key = c.op_keylist_next() helper = {"skip": 0, "data": out} c.op_edit(key, edit_fnc, helper, out) print "[-- Final output --]" out.seek(helper["skip"], 0) print out.read()