1
# dialog_apt_key.py.in - edit the apt keys
3
# Copyright (c) 2004 Canonical
5
# Author: Michael Vogt <mvo@debian.org>
7
# This program is free software; you can redistribute it and/or
8
# modify it under the terms of the GNU General Public License as
9
# published by the Free Software Foundation; either version 2 of the
10
# License, or (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program; if not, write to the Free Software
19
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
29
from subprocess import PIPE
33
def dummy(e): return e
37
N_("Ubuntu Archive Automatic Signing Key <ftpmaster@ubuntu.com>")
38
N_("Ubuntu CD Image Automatic Signing Key <cdimage@ubuntu.com>")
42
self.gpg = ["/usr/bin/gpg"]
43
self.base_opt = self.gpg + ["--no-options", "--no-default-keyring",
44
"--secret-keyring", "/etc/apt/secring.gpg",
45
"--trustdb-name", "/etc/apt/trustdb.gpg",
46
"--keyring", "/etc/apt/trusted.gpg"]
47
self.list_opt = self.base_opt + ["--with-colons", "--batch",
49
self.rm_opt = self.base_opt + ["--quiet", "--batch",
50
"--delete-key", "--yes"]
51
self.add_opt = self.base_opt + ["--quiet", "--batch",
58
p = subprocess.Popen(self.list_opt,stdout=PIPE).stdout
59
for line in p.readlines():
60
fields = line.split(":")
61
if fields[0] == "pub":
63
res.append("%s %s\n%s" %((fields[4])[-8:],fields[5], _(name)))
66
def add(self, filename):
67
#print "request to add " + filename
70
p = subprocess.Popen(cmd)
71
return (p.wait() == 0)
74
cmd = ["/usr/bin/apt-key", "update"]
75
p = subprocess.Popen(cmd)
76
return (p.wait() == 0)
79
#print "request to remove " + key
82
p = subprocess.Popen(cmd)
83
return (p.wait() == 0)
86
def __init__(self, parent, datadir):
88
if os.path.exists("../data/SoftwarePropertiesDialogs.glade"):
89
self.gladexml = gtk.glade.XML("../data/SoftwarePropertiesDialogs.glade")
91
self.gladexml = gtk.glade.XML("%s/SoftwarePropertiesDialogs.glade", datadir)
92
self.main = self.gladexml.get_widget("dialog_apt_key")
93
self.main.set_transient_for(parent)
95
self.gladexml.signal_connect("on_button_key_add_clicked",
96
self.on_button_key_add_clicked)
97
self.gladexml.signal_connect("on_button_key_remove_clicked",
98
self.on_button_key_remove_clicked)
99
self.gladexml.signal_connect("on_button_apt_key_update_clicked",
100
self.on_button_apt_key_update_clicked)
102
# create apt-key object (abstraction for the apt-key command)
103
self.apt_key = apt_key()
106
self.treeview_apt_key = self.gladexml.get_widget("treeview_apt_key")
107
self.liststore_apt_key = gtk.ListStore(str)
108
self.treeview_apt_key.set_model(self.liststore_apt_key)
109
# Create columns and append them.
110
tr = gtk.CellRendererText()
111
tr.set_property("xpad", 10)
112
tr.set_property("ypad", 10)
113
c0 = gtk.TreeViewColumn("Key", tr, text=0)
114
self.treeview_apt_key.append_column(c0)
115
self.update_key_list()
117
def on_button_apt_key_update_clicked(self, widget):
118
self.apt_key.update()
119
self.update_key_list()
121
def on_button_key_add_clicked(self, widget):
122
chooser = gtk.FileChooserDialog(title=_("Choose a key-file"),
124
buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_REJECT,
125
gtk.STOCK_OK,gtk.RESPONSE_ACCEPT))
128
if res == gtk.RESPONSE_ACCEPT:
129
#print chooser.get_filename()
130
if not self.apt_key.add(chooser.get_filename()):
131
dialog_error(self.main,
132
_("Error importing selected file"),
133
_("The selected file may not be a GPG key file "
134
"or it might be corrupt."))
135
self.update_key_list()
137
def on_button_key_remove_clicked(self, widget):
138
selection = self.treeview_apt_key.get_selection()
139
(model,a_iter) = selection.get_selected()
142
key = model.get_value(a_iter,0)
143
if not self.apt_key.rm(key[:8]):
145
_("Error removing the key"),
146
_("The key you selected could not be removed. "
147
"Please report this as a bug."))
148
self.update_key_list()
150
def update_key_list(self):
151
self.liststore_apt_key.clear()
152
for key in self.apt_key.list():
153
self.liststore_apt_key.append([key])
156
res = self.main.run()
160
if __name__ == "__main__":
161
ui = dialog_apt_key(None)