~mvo/update-manager/pae-kernel-transtion

« back to all changes in this revision

Viewing changes to SoftwareProperties/SoftwareProperties.py.in

  • Committer: Michael Vogt
  • Date: 2005-11-15 13:18:07 UTC
  • Revision ID: egon@top-20051115131807-12fada324eb74180
* initial revision (after accidently killing it)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# gnome-software-properties.in - edit /etc/apt/sources.list
 
3
#
 
4
#  Copyright (c) 2004 Canonical
 
5
#                2004-2005 Michiel Sikkes
 
6
#
 
7
#  Author: Michiel Sikkes <michiel@eyesopened.nl>
 
8
#          Michael Vogt <mvo@debian.org>
 
9
#
 
10
#  This program is free software; you can redistribute it and/or
 
11
#  modify it under the terms of the GNU General Public License as
 
12
#  published by the Free Software Foundation; either version 2 of the
 
13
#  License, or (at your option) any later version.
 
14
#
 
15
#  This program is distributed in the hope that it will be useful,
 
16
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
#  GNU General Public License for more details.
 
19
#
 
20
#  You should have received a copy of the GNU General Public License
 
21
#  along with this program; if not, write to the Free Software
 
22
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 
23
#  USA
 
24
 
 
25
import sys
 
26
import gnome
 
27
import gconf
 
28
import apt_pkg
 
29
import gobject
 
30
import shutil
 
31
import gettext
 
32
 
 
33
sys.path.append("@prefix/share/update-manager/python")
 
34
 
 
35
from SimpleGladeApp import *
 
36
import aptsources
 
37
import dialog_add
 
38
import dialog_edit
 
39
from dialog_apt_key import apt_key
 
40
from utils import *
 
41
 
 
42
(LIST_MARKUP, LIST_ENABLED, LIST_ENTRY_OBJ) = range(3)
 
43
 
 
44
CONF_MAP = {
 
45
  "autoupdate"   : "APT::Periodic::Update-Package-Lists",
 
46
  "autodownload" : "APT::Periodic::Download-Upgradeable-Packages",
 
47
  "autoclean"    : "APT::Periodic::AutocleanInterval",
 
48
  "max_size"     : "APT::Archives::MaxSize",
 
49
  "max_age"      : "APT::Archives::MaxAge"
 
50
}
 
51
 
 
52
DATADIR = "@prefix@/share/update-manager"
 
53
 
 
54
 
 
55
class SoftwareProperties(SimpleGladeApp):
 
56
 
 
57
  def __init__(self, gladefile, root, domain, options):
 
58
    SimpleGladeApp.__init__(self, gladefile, None, domain)
 
59
    apt_pkg.InitConfig()
 
60
   
 
61
    self.modified = False
 
62
    
 
63
    _ = gettext.gettext
 
64
                  
 
65
    self.gnome_program = gnome.init("Software Properties", "0.41")
 
66
    self.gconfclient = gconf.client_get_default()
 
67
 
 
68
    # Get some configuration options
 
69
    self.show_disabled = self.gconfclient.get_bool("/apps/gnome-software-" \
 
70
                                                   "properties/show_disabled")
 
71
                   
 
72
    self.window_main.hide() 
 
73
                                   
 
74
    # If externally called, reparent to external application.
 
75
    if (options.socket != None):
 
76
      plug = gtk.Plug(long(options.socket))
 
77
      self.vbox1.reparent(plug)
 
78
      plug.show_all()
 
79
    else:
 
80
      self.window_main.show()
 
81
      
 
82
    self.init_sourceslist()
 
83
    self.reload_sourceslist()
 
84
      
 
85
    update_days = apt_pkg.Config.FindI(CONF_MAP["autoupdate"])
 
86
    
 
87
    self.spinbutton_update_interval.set_value(update_days)
 
88
    
 
89
    if update_days >= 1:
 
90
      self.checkbutton_auto_update.set_active(True)
 
91
    else:
 
92
      self.checkbutton_auto_update.set_active(False)
 
93
      
 
94
    self.apt_key = apt_key()
 
95
    
 
96
    self.init_keyslist()
 
97
    self.reload_keyslist()
 
98
    
 
99
  def init_sourceslist(self):
 
100
    self.source_store = gtk.ListStore(str, bool, gobject.TYPE_PYOBJECT)
 
101
    self.treeview1.set_model(self.source_store)
 
102
    
 
103
    tr = gtk.CellRendererText()
 
104
    
 
105
    source_col = gtk.TreeViewColumn("Description", tr, markup=LIST_MARKUP)
 
106
    source_col.set_max_width(500)
 
107
    self.treeview1.append_column(source_col)
 
108
    
 
109
    self.sourceslist = aptsources.SourcesList()
 
110
    self.matcher = aptsources.SourceEntryMatcher()
 
111
    
 
112
  def init_keyslist(self):
 
113
    self.keys_store = gtk.ListStore(str)
 
114
    self.treeview2.set_model(self.keys_store)
 
115
    
 
116
    tr = gtk.CellRendererText()
 
117
    
 
118
    keys_col = gtk.TreeViewColumn("Key", tr, text=0)
 
119
    self.treeview2.append_column(keys_col)
 
120
    
 
121
  def reload_sourceslist(self):
 
122
    self.source_store.clear()
 
123
    for source in self.sourceslist.list:
 
124
      if source.invalid or source.disabled:
 
125
        continue
 
126
      (a_type, dists, comps) = self.matcher.match(source)
 
127
      
 
128
      contents = ""
 
129
      if source.comment != "":
 
130
        contents += "<i>%s</i>\n\n" % (source.comment)
 
131
      contents += "%s <small>(%s)</small>" % (dists, a_type)
 
132
      
 
133
      self.source_store.append([contents, not source.disabled, source])
 
134
      
 
135
  def reload_keyslist(self):
 
136
    self.keys_store.clear()
 
137
    for key in self.apt_key.list():
 
138
      self.keys_store.append([key])
 
139
  
 
140
  def opt_autoupdate_toggled(self, widget):  
 
141
    if self.checkbutton_auto_update.get_active():
 
142
      if self.spinbutton_update_interval.get_value() == 0:
 
143
        self.spinbutton_update_interval.set_value(1)
 
144
        value = "1"
 
145
      else:
 
146
        value = str(self.spinbutton_update_interval.get_value()) 
 
147
    else:
 
148
      value = "0"
 
149
    
 
150
    apt_pkg.Config.Set(CONF_MAP["autoupdate"], str(value))
 
151
    
 
152
    # FIXME: Write config options, apt_pkg should be able to do this.
 
153
    self.write_config()
 
154
    
 
155
  def write_config(self):
 
156
    periodic = "/etc/apt/apt.conf.d/10periodic"
 
157
    
 
158
    content = []
 
159
    
 
160
    if os.path.isfile(periodic):
 
161
      content = open(periodic, "r").readlines()
 
162
      
 
163
    cnf = apt_pkg.Config.SubTree("APT::Periodic")
 
164
    
 
165
    f = open(periodic, "w+")
 
166
    for line in content:
 
167
      found = False
 
168
      for key in cnf.List():
 
169
        if line.find("APT::Periodic::%s" % (key)) >= 0:
 
170
          found = True
 
171
          break
 
172
        if not found:
 
173
          f.write(line)
 
174
          
 
175
    for i in cnf.List():
 
176
      f.write("APT::Periodic::%s \"%s\";\n" % (i, cnf.FindI(i)))
 
177
    f.close()    
 
178
    
 
179
  def save_sourceslist(self):
 
180
    location = "/etc/apt/sources.list"
 
181
    shutil.copy(location, location + ".save")
 
182
    self.sourceslist.save(location)
 
183
    
 
184
  def on_add_clicked(self, widget):
 
185
    dialog = dialog_add.dialog_add(self.window_main, self.sourceslist, DATADIR)
 
186
    if dialog.run() == gtk.RESPONSE_OK:
 
187
      self.reload_sourceslist()
 
188
    
 
189
    self.modified = True
 
190
      
 
191
  def on_edit_clicked(self, widget):
 
192
    sel = self.treeview1.get_selection()
 
193
    (model, iter) = sel.get_selected()
 
194
    source_entry = model.get_value(iter, LIST_ENTRY_OBJ)
 
195
    
 
196
    dialog = dialog_edit.dialog_edit(self.window_main, self.sourceslist,
 
197
                                     source_entry, DATADIR)
 
198
                                     
 
199
    if dialog.run() == gtk.RESPONSE_OK:
 
200
      self.reload_sourceslist()
 
201
      
 
202
    self.modified = True
 
203
      
 
204
  def on_remove_clicked(self, widget):
 
205
    sel = self.treeview1.get_selection()
 
206
    (model, iter) = sel.get_selected()
 
207
    
 
208
    if iter:
 
209
      source = model.get_value(iter, LIST_ENTRY_OBJ)
 
210
      self.sourceslist.remove(source)
 
211
      self.reload_sourceslist()  
 
212
    
 
213
    self.modified = True
 
214
    
 
215
  def add_key_clicked(self, widget):
 
216
    _ = gettext.gettext
 
217
    chooser = gtk.FileChooserDialog(title=_("Choose a key-file"),
 
218
                                    parent=self.window_main,
 
219
                                    buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_REJECT,
 
220
                                             gtk.STOCK_OK,gtk.RESPONSE_ACCEPT))
 
221
    res = chooser.run()
 
222
    chooser.hide()
 
223
    if res == gtk.RESPONSE_ACCEPT:
 
224
      if not self.apt_key.add(chooser.get_filename()):
 
225
        error(self.window_main,
 
226
              _("Error importing selected file"),
 
227
              _("The selected file may not be a GPG key file " \
 
228
                "or it might be corrupt."))
 
229
        self.reload_keyslist()
 
230
        
 
231
  def remove_key_clicked(self, widget):
 
232
    selection = self.treeview2.get_selection()
 
233
    (model,a_iter) = selection.get_selected()
 
234
    if a_iter == None:
 
235
        return
 
236
    key = model.get_value(a_iter,0)
 
237
    if not self.apt_key.rm(key[:8]):
 
238
      error(self.main,
 
239
        _("Error removing the key"),
 
240
        _("The key you selected could not be removed. "
 
241
          "Please report this as a bug."))
 
242
    self.reload_keyslist()
 
243
    
 
244
  def on_restore_clicked(self, widget):
 
245
    self.apt_key.update()
 
246
    self.reload_keyslist()
 
247
    
 
248
  def on_delete_event(self, widget, args):
 
249
    self.save_sourceslist()
 
250
    self.quit()
 
251
    
 
252
  def on_close_button(self, widget):
 
253
    self.save_sourceslist()
 
254
    self.quit()
 
255
    
 
256
  def on_help_button(self, widget):
 
257
    gnome.help_display_desktop(self.gnome_program, 
 
258
                               "update-manager", "update-manager", 
 
259
                               "setting-preferences")