~ubuntu-core-dev/update-manager/main

2125.1.2 by Brendan Donegan
Removed some of the codes which aren't used by U-M (ASLEEP, DISCONNECTING, DISCONNECTED)
1
# UpdateManager.py
52 by Michael Vogt
* added a bunch of missing copyright notices in the files
2
#  
1988.1.4 by Alex Launi
Update UpdateManager.py header to add Alex Launi to authors, and update copyright
3
#  Copyright (c) 2004-2010 Canonical
52 by Michael Vogt
* added a bunch of missing copyright notices in the files
4
#                2004 Michiel Sikkes
5
#                2005 Martin Willemoes Hansen
1875.1.2 by Mohamed Amine IL Idrissi
Finished implementing the feature.
6
#                2010 Mohamed Amine IL Idrissi
52 by Michael Vogt
* added a bunch of missing copyright notices in the files
7
#  
8
#  Author: Michiel Sikkes <michiel@eyesopened.nl>
9
#          Michael Vogt <mvo@debian.org>
10
#          Martin Willemoes Hansen <mwh@sysrq.dk>
1875.1.2 by Mohamed Amine IL Idrissi
Finished implementing the feature.
11
#          Mohamed Amine IL Idrissi <ilidrissiamine@gmail.com>
1988.1.4 by Alex Launi
Update UpdateManager.py header to add Alex Launi to authors, and update copyright
12
#          Alex Launi <alex.launi@canonical.com>
52 by Michael Vogt
* added a bunch of missing copyright notices in the files
13
# 
14
#  This program is free software; you can redistribute it and/or 
15
#  modify it under the terms of the GNU General Public License as 
16
#  published by the Free Software Foundation; either version 2 of the
17
#  License, or (at your option) any later version.
18
# 
19
#  This program is distributed in the hope that it will be useful,
20
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
21
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
#  GNU General Public License for more details.
23
# 
24
#  You should have received a copy of the GNU General Public License
25
#  along with this program; if not, write to the Free Software
26
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
27
#  USA
28
2409 by Colin Watson
Tell Python to use absolute imports by default, and annotate cases where
29
from __future__ import absolute_import, print_function
2394 by Colin Watson
Use Python 3-style print functions.
30
2146.2.12 by Michael Vogt
get rid of gconfclient references
31
from gi.repository import Gtk
32
from gi.repository import Gdk
2119.1.1 by Robert Roth
Porting to PyGI
33
from gi.repository import GObject
2146.2.12 by Michael Vogt
get rid of gconfclient references
34
from gi.repository import Gio
2119.1.1 by Robert Roth
Porting to PyGI
35
GObject.threads_init()
2119.1.2 by Robert Roth
Porting to PyGI
36
from gi.repository import Pango
1170 by Michael Vogt
* UpdateManager/Common/MyCache.py,
37
358.1.79 by Michael Vogt
* DistUpgrade/DistUpgradeCache.py:
38
import warnings
1505 by Michael Vogt
* UpdateManager/Core/UpdateList.py, UpdateManager/UpdateManager.py:
39
warnings.filterwarnings("ignore", "Accessed deprecated property", DeprecationWarning)
2164 by Michael Vogt
make UpdateManager/, tests/ pyflakes clean
40
10 by Michael Vogt
* code cleanup, make it all more structured
41
import apt_pkg
358.1.62 by Michael Vogt
* DistUpgrade/DistUpgradeCache.py, UpdateManager/UpdateManager.py:
42
10 by Michael Vogt
* code cleanup, make it all more structured
43
import sys
44
import os
795 by Michael Vogt
- when no updates are available, display the information when the
45
import stat
10 by Michael Vogt
* code cleanup, make it all more structured
46
import re
1571.1.13 by Michael Vogt
* UpdateManager/UpdateManager.py:
47
import logging
10 by Michael Vogt
* code cleanup, make it all more structured
48
import subprocess
33 by Michael Vogt
* UpdateManager/UpdateManager.py: (re)added missing import time
49
import time
2407 by Colin Watson
Use the threading module instead of thread (renamed to _thread in Python
50
import threading
10 by Michael Vogt
* code cleanup, make it all more structured
51
import xml.sax.saxutils
18 by Michael Vogt
* dist-upgade tool can fetch the update tarball now
52
337.1.3 by Sebastian Heinlein
* use dbus to bring up another running instance update-manager
53
import dbus
54
import dbus.service
2355 by Colin Watson
Use 'from dbus.mainloop.glib import DBusGMainLoop;
55
from dbus.mainloop.glib import DBusGMainLoop
56
DBusGMainLoop(set_as_default=True)
18 by Michael Vogt
* dist-upgade tool can fetch the update tarball now
57
2420 by Colin Watson
Port to python-apt 0.8 progress classes.
58
from .GtkProgress import GtkAcquireProgress, GtkOpProgressInline
2409 by Colin Watson
Tell Python to use absolute imports by default, and annotate cases where
59
from .backend import get_backend
1170 by Michael Vogt
* UpdateManager/Common/MyCache.py,
60
10 by Michael Vogt
* code cleanup, make it all more structured
61
from gettext import gettext as _
1026 by Michael Vogt
* UpdateManager/UpdateManager.py:
62
from gettext import ngettext
10 by Michael Vogt
* code cleanup, make it all more structured
63
1248 by Michael Vogt
* move MyCache and UpdateList from Common into Core
64
2409 by Colin Watson
Tell Python to use absolute imports by default, and annotate cases where
65
from .Core.utils import (humanize_size,
66
                         on_battery,
67
                         inhibit_sleep,
68
                         allow_sleep)
69
from .Core.UpdateList import UpdateList
70
from .Core.MyCache import MyCache
71
from .Core.AlertWatcher import AlertWatcher
2167 by Michael Vogt
more pyflakes fixes, mostly good now
72
2164 by Michael Vogt
make UpdateManager/, tests/ pyflakes clean
73
from DistUpgrade.DistUpgradeCache import NotEnoughFreeSpaceError
2409 by Colin Watson
Tell Python to use absolute imports by default, and annotate cases where
74
from .DistUpgradeFetcher import DistUpgradeFetcherGtk
2167 by Michael Vogt
more pyflakes fixes, mostly good now
75
2409 by Colin Watson
Tell Python to use absolute imports by default, and annotate cases where
76
from .ChangelogViewer import ChangelogViewer
77
from .SimpleGtk3builderApp import SimpleGtkbuilderApp
78
from .MetaReleaseGObject import MetaRelease
79
from .UnitySupport import UnitySupport
14 by Michael Vogt
* move the MetaRelease code into it's own class/file
80
2093.1.4 by Bilal Akhtar
Move dbusmenu and Unity declaration to the top of script
81
337.4.5 by glatzor at ubuntu
* support unkown origins with the UpdateOrigin class
82
#import pdb
83
10 by Michael Vogt
* code cleanup, make it all more structured
84
# FIXME:
85
# - kill "all_changes" and move the changes into the "Update" class
86
87
# list constants
1794 by Michael Vogt
* UpdateManager/UpdateManager.py:
88
(LIST_CONTENTS, LIST_NAME, LIST_PKG, LIST_ORIGIN, LIST_TOGGLE_CHECKED) = range(5)
10 by Michael Vogt
* code cleanup, make it all more structured
89
90
# actions for "invoke_manager"
91
(INSTALL, UPDATE) = range(2)
92
1602 by Michael Vogt
* UpdateManager/UpdateManager.py:
93
# file that signals if we need to reboot
94
REBOOT_REQUIRED_FILE = "/var/run/reboot-required"
337.1.3 by Sebastian Heinlein
* use dbus to bring up another running instance update-manager
95
1875.1.9 by Mohamed Amine IL Idrissi
Enums. I like enums.
96
# NetworkManager enums
2409 by Colin Watson
Tell Python to use absolute imports by default, and annotate cases where
97
from .Core.roam import NetworkManagerHelper
1875.1.9 by Mohamed Amine IL Idrissi
Enums. I like enums.
98
1965 by Michael Vogt
* check-new-release-gtk:
99
def show_dist_no_longer_supported_dialog(parent=None):
100
    """ show a no-longer-supported dialog """
101
    msg = "<big><b>%s</b></big>\n\n%s" % (
102
        _("Your Ubuntu release is not supported anymore."),
103
        _("You will not get any further security fixes or critical "
104
          "updates. "
2345 by Michael Vogt
* UpdateManager/UpdateManager.py:
105
          "Please upgrade to a later version of Ubuntu."))
2119.1.1 by Robert Roth
Porting to PyGI
106
    dialog = Gtk.MessageDialog(parent, 0, Gtk.MessageType.WARNING,
107
                               Gtk.ButtonsType.CLOSE,"")
1965 by Michael Vogt
* check-new-release-gtk:
108
    dialog.set_title("")
109
    dialog.set_markup(msg)
2119.1.1 by Robert Roth
Porting to PyGI
110
    button = Gtk.LinkButton(uri="http://www.ubuntu.com/releaseendoflife",
1965 by Michael Vogt
* check-new-release-gtk:
111
                            label=_("Upgrade information"))
112
    button.show()
2153 by Michael Vogt
* UpdateManager/UpdateManager.py, check-new-release-gtk:
113
    dialog.get_content_area().pack_end(button, True, True, 0)
2076 by Michael Vogt
add tests around the distro end of life handling
114
    # this data used in the test to get the dialog
115
    if parent:
116
        parent.set_data("no-longer-supported-nag", dialog)
1965 by Michael Vogt
* check-new-release-gtk:
117
    dialog.run()
118
    dialog.destroy()
2076 by Michael Vogt
add tests around the distro end of life handling
119
    if parent:
120
        parent.set_data("no-longer-supported-nag", None)
1965 by Michael Vogt
* check-new-release-gtk:
121
122
1988.1.1 by Alex Launi
Fix misspelled class name
123
class UpdateManagerDbusController(dbus.service.Object):
337.1.3 by Sebastian Heinlein
* use dbus to bring up another running instance update-manager
124
    """ this is a helper to provide the UpdateManagerIFace """
125
    def __init__(self, parent, bus_name,
126
                 object_path='/org/freedesktop/UpdateManagerObject'):
127
        dbus.service.Object.__init__(self, bus_name, object_path)
128
        self.parent = parent
1988.1.3 by Alex Launi
Return false on update if disconnected from network
129
        self.alert_watcher = AlertWatcher ()
130
        self.alert_watcher.connect("network-alert", self._on_network_alert)
131
        self.connected = False
337.1.3 by Sebastian Heinlein
* use dbus to bring up another running instance update-manager
132
133
    @dbus.service.method('org.freedesktop.UpdateManagerIFace')
134
    def bringToFront(self):
135
        self.parent.window_main.present()
136
        return True
137
1988.1.2 by Alex Launi
Add DBus interface to drive check for upgrades, and upgrade
138
    @dbus.service.method('org.freedesktop.UpdateManagerIFace')
139
    def update(self):
140
        try:
1988.1.3 by Alex Launi
Return false on update if disconnected from network
141
            self.alert_watcher.check_alert_state ()
1988.1.2 by Alex Launi
Add DBus interface to drive check for upgrades, and upgrade
142
            self.parent.invoke_manager(UPDATE)
1988.1.3 by Alex Launi
Return false on update if disconnected from network
143
            return self.connected
1988.1.2 by Alex Launi
Add DBus interface to drive check for upgrades, and upgrade
144
        except:
145
            return False
146
147
    @dbus.service.method('org.freedesktop.UpdateManagerIFace')
148
    def upgrade(self):
149
        try:
150
            self.parent.cache.checkFreeSpace()
151
            self.parent.invoke_manager(INSTALL)
152
            return True
153
        except:
1995.1.1 by Brendan Donegan
Added updated signal and option to do no update on startup
154
            return False
155
156
    @dbus.service.signal('org.freedesktop.UpdateManagerIFace', 'b')
157
    def updated(self, success):
2404 by Colin Watson
Remove all hard tabs from Python code. Python 3 no longer tolerates
158
        pass
1988.1.1 by Alex Launi
Fix misspelled class name
159
1988.1.3 by Alex Launi
Return false on update if disconnected from network
160
    def _on_network_alert(self, watcher, state):
2125.1.1 by Brendan Donegan
Updated NetworkManagerHelper with new NM 0.9 states as well as updating the UpdateManager itself to handle codes more robustly
161
        if state in NetworkManagerHelper.NM_STATE_CONNECTED_LIST:
1988.1.3 by Alex Launi
Return false on update if disconnected from network
162
            self.connected = True
163
        else:
164
            self.connected = False
165
1452.1.1 by Michael Vogt
port to gtkbuilder
166
class UpdateManager(SimpleGtkbuilderApp):
11 by Michael Vogt
* use SimpleGladeApp in UpdateManager now
167
1262 by Michael Vogt
add "--no-focus-on-map option to bring update-manager up
168
  def __init__(self, datadir, options):
337.1.3 by Sebastian Heinlein
* use dbus to bring up another running instance update-manager
169
    self.setupDbus()
11 by Michael Vogt
* use SimpleGladeApp in UpdateManager now
170
    self.datadir = datadir
2192 by Michael Vogt
* remove old UpdateManager.glade file
171
    SimpleGtkbuilderApp.__init__(self, datadir+"gtkbuilder/UpdateManager.ui",
1528 by Michael Vogt
* DistUpgrade/DistUpgradeQuirks.py:
172
                                 "update-manager")
11 by Michael Vogt
* use SimpleGladeApp in UpdateManager now
173
1633.1.1 by sebi at glatzor
Make the InstallBackend an gobject and allow to process the actions asynchronously. Furthermore replace running synaptic in a separate thread by using gobject's spwan_async and child_watch_add.
174
    # Used for inhibiting power management
175
    self.sleep_cookie = None
176
    self.sleep_dev = None
177
2376 by Brian Murray
* DistUpgrade/Distupgrade.py:
178
    # workaround for LP: #945536
179
    self.clearing_store = False
180
2347.1.1 by Robert Roth
Update icon name to use FD.o standard (LP: #921310)
181
    self.image_logo.set_from_icon_name("system-software-update", Gtk.IconSize.DIALOG)
123.1.17 by Sebastian Heinlein
SoftwareProperties:
182
    self.window_main.set_sensitive(False)
187.2.10 by Sebastian Heinlein
* Fixed reload information
183
    self.window_main.grab_focus()
184
    self.button_close.grab_focus()
11 by Michael Vogt
* use SimpleGladeApp in UpdateManager now
185
    self.dl_size = 0
2047 by Michael Vogt
do not try to download changelogs if NM reports we are
186
    self.connected = True
11 by Michael Vogt
* use SimpleGladeApp in UpdateManager now
187
188
    # create text view
459 by Michael Vogt
* UpdateManager/ChangelogViewer.py:
189
    self.textview_changes = ChangelogViewer()
190
    self.textview_changes.show()
191
    self.scrolledwindow_changes.add(self.textview_changes)
11 by Michael Vogt
* use SimpleGladeApp in UpdateManager now
192
    changes_buffer = self.textview_changes.get_buffer()
2119.1.1 by Robert Roth
Porting to PyGI
193
    changes_buffer.create_tag("versiontag", weight=Pango.Weight.BOLD)
11 by Michael Vogt
* use SimpleGladeApp in UpdateManager now
194
195
    # expander
2428.1.1 by Michael Terry
move changelog widget into detail pane
196
    self.expander_details.connect("activate", self.pre_activate_details)
11 by Michael Vogt
* use SimpleGladeApp in UpdateManager now
197
    self.expander_details.connect("notify::expanded", self.activate_details)
2428.1.2 by Michael Terry
switch from pane view to second expander and also save state of toplevel expander
198
    self.expander_desc.connect("notify::expanded", self.activate_desc)
11 by Michael Vogt
* use SimpleGladeApp in UpdateManager now
199
200
    # useful exit stuff
123.1.33 by Sebastian Heinlein
* Do not allow to close the main window until actions are performed and the
201
    self.window_main.connect("delete_event", self.close)
187.2.10 by Sebastian Heinlein
* Fixed reload information
202
    self.button_close.connect("clicked", lambda w: self.exit())
11 by Michael Vogt
* use SimpleGladeApp in UpdateManager now
203
204
    # the treeview (move into it's own code!)
2119.1.1 by Robert Roth
Porting to PyGI
205
    self.store = Gtk.ListStore(str, str, GObject.TYPE_PYOBJECT, 
206
                               GObject.TYPE_PYOBJECT, bool)
11 by Michael Vogt
* use SimpleGladeApp in UpdateManager now
207
    self.treeview_update.set_model(self.store)
208
    self.treeview_update.set_headers_clickable(True);
2119.1.1 by Robert Roth
Porting to PyGI
209
    self.treeview_update.set_direction(Gtk.TextDirection.LTR)
11 by Michael Vogt
* use SimpleGladeApp in UpdateManager now
210
2119.1.1 by Robert Roth
Porting to PyGI
211
    tr = Gtk.CellRendererText()
337.4.3 by glatzor at ubuntu
* replace tabs by spaces
212
    tr.set_property("xpad", 6)
213
    tr.set_property("ypad", 6)
2119.1.1 by Robert Roth
Porting to PyGI
214
    cr = Gtk.CellRendererToggle()
11 by Michael Vogt
* use SimpleGladeApp in UpdateManager now
215
    cr.set_property("activatable", True)
337.4.3 by glatzor at ubuntu
* replace tabs by spaces
216
    cr.set_property("xpad", 6)
11 by Michael Vogt
* use SimpleGladeApp in UpdateManager now
217
    cr.connect("toggled", self.toggled)
351 by Michael Vogt
* UpdateManager/UpdateManager.py:
218
2361.1.1 by Gabor Kelemen
Mark two accessible descriptions for translation. LP: #957552
219
    column_install = Gtk.TreeViewColumn(_("Install"), cr, active=LIST_TOGGLE_CHECKED)
351 by Michael Vogt
* UpdateManager/UpdateManager.py:
220
    column_install.set_cell_data_func (cr, self.install_column_view_func)
2361.1.1 by Gabor Kelemen
Mark two accessible descriptions for translation. LP: #957552
221
    column = Gtk.TreeViewColumn(_("Name"), tr, markup=LIST_CONTENTS)
351 by Michael Vogt
* UpdateManager/UpdateManager.py:
222
    column.set_resizable(True)
1841 by Michael Vogt
* UpdateManager/GtkProgress.py:
223
2119.1.1 by Robert Roth
Porting to PyGI
224
    column_install.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
1841 by Michael Vogt
* UpdateManager/GtkProgress.py:
225
    column_install.set_fixed_width(30)
2119.1.1 by Robert Roth
Porting to PyGI
226
    column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
1841 by Michael Vogt
* UpdateManager/GtkProgress.py:
227
    column.set_fixed_width(100)
228
    self.treeview_update.set_fixed_height_mode(False)
11 by Michael Vogt
* use SimpleGladeApp in UpdateManager now
229
351 by Michael Vogt
* UpdateManager/UpdateManager.py:
230
    self.treeview_update.append_column(column_install)
231
    column_install.set_visible(True)
232
    self.treeview_update.append_column(column)
337.4.11 by glatzor at ubuntu
* Allow to select all or none update - fixes #42296
233
    self.treeview_update.set_search_column(LIST_NAME)
234
    self.treeview_update.connect("button-press-event", self.show_context_menu)
11 by Michael Vogt
* use SimpleGladeApp in UpdateManager now
235
187.1.7 by Sebastian Heinlein
* only show the help button if a help viewer is installed (currently only
236
    # setup the help viewer and disable the help button if there
237
    # is no viewer available
1312 by Michael Vogt
* DistUpgrade/cdromupgrade:
238
    #self.help_viewer = HelpViewer("update-manager")
239
    #if self.help_viewer.check() == False:
240
    #    self.button_help.set_sensitive(False)
187.1.7 by Sebastian Heinlein
* only show the help button if a help viewer is installed (currently only
241
1306 by Michael Vogt
* data/glade/UpdateManager.glade:
242
    if not os.path.exists("/usr/bin/software-properties-gtk"):
243
        self.button_settings.set_sensitive(False)
244
2146.2.12 by Michael Vogt
get rid of gconfclient references
245
    self.settings =  Gio.Settings("com.ubuntu.update-manager")
1307 by Michael Vogt
keep track of launch times via gconf
246
    # init show version
2146.2.12 by Michael Vogt
get rid of gconfclient references
247
    self.show_versions = self.settings.get_boolean("show-versions")
1857.1.1 by rugby471 at gmail
Fixes LP: #386196
248
    # init summary_before_name
2146.2.12 by Michael Vogt
get rid of gconfclient references
249
    self.summary_before_name = self.settings.get_boolean("summary-before-name")
1651 by Michael Vogt
* UpdateManager/SafeGConfClient.py
250
1262 by Michael Vogt
add "--no-focus-on-map option to bring update-manager up
251
    # get progress object
2409 by Colin Watson
Tell Python to use absolute imports by default, and annotate cases where
252
    self.progress = GtkOpProgressInline(
1841 by Michael Vogt
* UpdateManager/GtkProgress.py:
253
        self.progressbar_cache_inline, self.window_main)
1481 by Michael Vogt
* UpdateManager/UpdateManager.py:
254
255
    #set minimum size to prevent the headline label blocking the resize process
256
    self.window_main.set_size_request(500,-1) 
2428.1.2 by Michael Terry
switch from pane view to second expander and also save state of toplevel expander
257
    # restore details state, which will trigger a resize if necessary
258
    self.expander_details.set_expanded(self.settings.get_boolean("show-details"))
1357 by Michael Vogt
* UpdateManager/UpdateManager.py:
259
    # deal with no-focus-on-map
1262 by Michael Vogt
add "--no-focus-on-map option to bring update-manager up
260
    if options.no_focus_on_map:
261
        self.window_main.set_focus_on_map(False)
1855 by Michael Vogt
* UpdateManager/UpdateManager.py:
262
        if self.progress._window:
263
            self.progress._window.set_focus_on_map(False)
1357 by Michael Vogt
* UpdateManager/UpdateManager.py:
264
    # show the main window
187.2.56 by Sebastian Heinlein
* Show main window after restoring the size - bug #42277 -
265
    self.window_main.show()
1478 by Michael Vogt
* DistUpgrade/DistUpgradeQuirks.py: add check for ARMv6 or
266
    # get the install backend
2409 by Colin Watson
Tell Python to use absolute imports by default, and annotate cases where
267
    self.install_backend = get_backend(self.window_main)
1633.1.1 by sebi at glatzor
Make the InstallBackend an gobject and allow to process the actions asynchronously. Furthermore replace running synaptic in a separate thread by using gobject's spwan_async and child_watch_add.
268
    self.install_backend.connect("action-done", self._on_backend_done)
2135.1.1 by Evan Huus
Split unity urgency hints into seperate function and call those when we call the normal urgency hints
269
270
    # Create Unity launcher quicklist
271
    # FIXME: instead of passing parent we really should just send signals
272
    self.unity = UnitySupport(parent=self)
273
1357 by Michael Vogt
* UpdateManager/UpdateManager.py:
274
    # it can only the iconified *after* it is shown (even if the docs
275
    # claim otherwise)
276
    if options.no_focus_on_map:
277
        self.window_main.iconify()
1460 by Michael Vogt
make it less stealty by setting the stick() property if
278
        self.window_main.stick()
1357 by Michael Vogt
* UpdateManager/UpdateManager.py:
279
        self.window_main.set_urgency_hint(True)
2135.1.1 by Evan Huus
Split unity urgency hints into seperate function and call those when we call the normal urgency hints
280
        self.unity.set_urgency(True)
1488 by Michael Vogt
* UpdateManager/UpdateManager.py:
281
        self.initial_focus_id = self.window_main.connect(
282
            "focus-in-event", self.on_initial_focus_in)
1875.1.2 by Mohamed Amine IL Idrissi
Finished implementing the feature.
283
    
284
    # Alert watcher
285
    self.alert_watcher = AlertWatcher()
286
    self.alert_watcher.connect("network-alert", self._on_network_alert)
287
    self.alert_watcher.connect("battery-alert", self._on_battery_alert)
2038 by Michael Vogt
display warning when on 3g and when roaming
288
    self.alert_watcher.connect("network-3g-alert", self._on_network_3g_alert)
1488 by Michael Vogt
* UpdateManager/UpdateManager.py:
289
2093.1.1 by Bilal Akhtar
Provide launcher quicklist for 'Check for Updates' and 'Install All Available Updates' options.
290
2093.1.2 by Bilal Akhtar
Minor changes to make signal callbacks suit both those of Gtk and Dbusmenu
291
  def install_all_updates (self, menu, menuitem, data):
2093.1.1 by Bilal Akhtar
Provide launcher quicklist for 'Check for Updates' and 'Install All Available Updates' options.
292
    self.select_all_updgrades (None)
293
    self.on_button_install_clicked (None)
294
1488 by Michael Vogt
* UpdateManager/UpdateManager.py:
295
  def on_initial_focus_in(self, widget, event):
296
      """callback run on initial focus-in (if started unmapped)"""
297
      widget.unstick()
298
      widget.set_urgency_hint(False)
2135.1.1 by Evan Huus
Split unity urgency hints into seperate function and call those when we call the normal urgency hints
299
      self.unity.set_urgency(False)
1488 by Michael Vogt
* UpdateManager/UpdateManager.py:
300
      self.window_main.disconnect(self.initial_focus_id)
301
      return False
302
303
  def warn_on_battery(self):
304
      """check and warn if on battery"""
305
      if on_battery():
306
          self.dialog_on_battery.set_transient_for(self.window_main)
1602 by Michael Vogt
* UpdateManager/UpdateManager.py:
307
          self.dialog_on_battery.set_title("")
1488 by Michael Vogt
* UpdateManager/UpdateManager.py:
308
          res = self.dialog_on_battery.run()
309
          self.dialog_on_battery.hide()
2119.1.1 by Robert Roth
Porting to PyGI
310
          if res != Gtk.ResponseType.YES:
1488 by Michael Vogt
* UpdateManager/UpdateManager.py:
311
              sys.exit()
337.1.3 by Sebastian Heinlein
* use dbus to bring up another running instance update-manager
312
2146.2.1 by Michael Vogt
initial pygi port, fixup a based on the work of evfool (thanks!). fixed a bunch of stuff but still crashing (gtktextiter problem?)
313
  def install_column_view_func(self, cell_layout, renderer, model, iter, data):
351 by Michael Vogt
* UpdateManager/UpdateManager.py:
314
    pkg = model.get_value(iter, LIST_PKG)
358.1.39 by Michael Vogt
* UpdateManager/UpdateManager.py:
315
    if pkg is None:
2404 by Colin Watson
Remove all hard tabs from Python code. Python 3 no longer tolerates
316
        renderer.set_property("activatable", True)
358.1.39 by Michael Vogt
* UpdateManager/UpdateManager.py:
317
        return
1794 by Michael Vogt
* UpdateManager/UpdateManager.py:
318
    current_state = renderer.get_property("active")
1849 by Michael Vogt
UpdateManager/Core/utils.py,
319
    to_install = pkg.marked_install or pkg.marked_upgrade
358.1.39 by Michael Vogt
* UpdateManager/UpdateManager.py:
320
    renderer.set_property("active", to_install)
1794 by Michael Vogt
* UpdateManager/UpdateManager.py:
321
    # we need to update the store as well to ensure orca knowns
322
    # about state changes (it will not read view_func changes)
323
    if to_install != current_state:
324
        self.store[iter][LIST_TOGGLE_CHECKED] = to_install
337.4.25 by glatzor at ubuntu
* show not installable updates as disabled in the update list
325
    if pkg.name in self.list.held_back:
326
        renderer.set_property("activatable", False)
337.4.28 by glatzor at ubuntu
* Gtk seems to require that you set the activatable property of a cell
327
    else: 
328
        renderer.set_property("activatable", True)
329
337.1.3 by Sebastian Heinlein
* use dbus to bring up another running instance update-manager
330
  def setupDbus(self):
331
    """ this sets up a dbus listener if none is installed alread """
332
    # check if there is another g-a-i already and if not setup one
333
    # listening on dbus
334
    try:
335
        bus = dbus.SessionBus()
336
    except:
2394 by Colin Watson
Use Python 3-style print functions.
337
        print("warning: could not initiate dbus")
337.1.3 by Sebastian Heinlein
* use dbus to bring up another running instance update-manager
338
        return
339
    try:
433 by Michael Vogt
* setup.py:
340
        proxy_obj = bus.get_object('org.freedesktop.UpdateManager', 
341
                                   '/org/freedesktop/UpdateManagerObject')
342
        iface = dbus.Interface(proxy_obj, 'org.freedesktop.UpdateManagerIFace')
337.1.3 by Sebastian Heinlein
* use dbus to bring up another running instance update-manager
343
        iface.bringToFront()
2394 by Colin Watson
Use Python 3-style print functions.
344
        #print("send bringToFront")
337.1.3 by Sebastian Heinlein
* use dbus to bring up another running instance update-manager
345
        sys.exit(0)
2164 by Michael Vogt
make UpdateManager/, tests/ pyflakes clean
346
    except dbus.DBusException:
2394 by Colin Watson
Use Python 3-style print functions.
347
         #print("no listening object (%s) " % e)
337.1.3 by Sebastian Heinlein
* use dbus to bring up another running instance update-manager
348
         bus_name = dbus.service.BusName('org.freedesktop.UpdateManager',bus)
1995.1.1 by Brendan Donegan
Added updated signal and option to do no update on startup
349
         self.dbusController = UpdateManagerDbusController(self, bus_name)
337.1.3 by Sebastian Heinlein
* use dbus to bring up another running instance update-manager
350
10 by Michael Vogt
* code cleanup, make it all more structured
351
123.1.33 by Sebastian Heinlein
* Do not allow to close the main window until actions are performed and the
352
  def close(self, widget, data=None):
353
    if self.window_main.get_property("sensitive") is False:
354
        return True
355
    else:
356
        self.exit()
357
358
  
10 by Michael Vogt
* code cleanup, make it all more structured
359
  def set_changes_buffer(self, changes_buffer, text, name, srcpkg):
360
    changes_buffer.set_text("")
361
    lines = text.split("\n")
362
    if len(lines) == 1:
363
      changes_buffer.set_text(text)
364
      return
365
    
366
    for line in lines:
367
      end_iter = changes_buffer.get_end_iter()
352 by Michael Vogt
* UpdateManager/UpdateManager.py:
368
      version_match = re.match(r'^%s \((.*)\)(.*)\;.*$' % re.escape(srcpkg), line)
10 by Michael Vogt
* code cleanup, make it all more structured
369
      #bullet_match = re.match("^.*[\*-]", line)
370
      author_match = re.match("^.*--.*<.*@.*>.*$", line)
371
      if version_match:
372
        version = version_match.group(1)
2404 by Colin Watson
Remove all hard tabs from Python code. Python 3 no longer tolerates
373
        #upload_archive = version_match.group(2).strip()
10 by Michael Vogt
* code cleanup, make it all more structured
374
        version_text = _("Version %s: \n") % version
375
        changes_buffer.insert_with_tags_by_name(end_iter, version_text, "versiontag")
376
      elif (author_match):
377
        pass
378
      else:
379
        changes_buffer.insert(end_iter, line+"\n")
380
        
381
11 by Michael Vogt
* use SimpleGladeApp in UpdateManager now
382
  def on_treeview_update_cursor_changed(self, widget):
1520 by Michael Vogt
* UpdateManager/UpdateManager.py:
383
    path = widget.get_cursor()[0]
10 by Michael Vogt
* code cleanup, make it all more structured
384
    # check if we have a path at all
385
    if path == None:
386
      return
387
    model = widget.get_model()
388
    iter = model.get_iter(path)
389
390
    # set descr
351 by Michael Vogt
* UpdateManager/UpdateManager.py:
391
    pkg = model.get_value(iter, LIST_PKG)
337.4.3 by glatzor at ubuntu
* replace tabs by spaces
392
    if pkg == None or pkg.description == None:
393
      changes_buffer = self.textview_changes.get_buffer()
394
      changes_buffer.set_text("")
395
      desc_buffer = self.textview_descr.get_buffer()
396
      desc_buffer.set_text("")
397
      self.notebook_details.set_sensitive(False)
351 by Michael Vogt
* UpdateManager/UpdateManager.py:
398
      return
399
    long_desc = pkg.description
337.4.3 by glatzor at ubuntu
* replace tabs by spaces
400
    self.notebook_details.set_sensitive(True)
187.2.7 by Sebastian Heinlein
* Improve the rendering of the description in the update-manager
401
    # do some regular expression magic on the description
402
    # Add a newline before each bullet
403
    p = re.compile(r'^(\s|\t)*(\*|0|-)',re.MULTILINE)
404
    long_desc = p.sub('\n*', long_desc)
405
    # replace all newlines by spaces
406
    p = re.compile(r'\n', re.MULTILINE)
407
    long_desc = p.sub(" ", long_desc)
408
    # replace all multiple spaces by newlines
409
    p = re.compile(r'\s\s+', re.MULTILINE)
410
    long_desc = p.sub("\n", long_desc)
411
11 by Michael Vogt
* use SimpleGladeApp in UpdateManager now
412
    desc_buffer = self.textview_descr.get_buffer()
354 by Michael Vogt
* merged from glatzor
413
    desc_buffer.set_text(long_desc)
10 by Michael Vogt
* code cleanup, make it all more structured
414
415
    # now do the changelog
187.2.7 by Sebastian Heinlein
* Improve the rendering of the description in the update-manager
416
    name = model.get_value(iter, LIST_NAME)
10 by Michael Vogt
* code cleanup, make it all more structured
417
    if name == None:
418
      return
419
11 by Michael Vogt
* use SimpleGladeApp in UpdateManager now
420
    changes_buffer = self.textview_changes.get_buffer()
10 by Michael Vogt
* code cleanup, make it all more structured
421
    
2047 by Michael Vogt
do not try to download changelogs if NM reports we are
422
    # check if we have the changes already and if so, display them 
423
    # (even if currently disconnected)
57 by Michael Vogt
* [code-cleanup] moved get_changelog() to MyCache()
424
    if self.cache.all_changes.has_key(name):
425
      changes = self.cache.all_changes[name]
2248.1.1 by B. Clausius
Fixed wrong use of self.cache.all_changes[name] in UpdateManager.on_treeview_update_cursor_changed
426
      srcpkg = self.cache[name].sourcePackageName
427
      self.set_changes_buffer(changes_buffer, changes, name, srcpkg)
2047 by Michael Vogt
do not try to download changelogs if NM reports we are
428
    # if not connected, do not even attempt to get the changes
429
    elif not self.connected:
430
        changes_buffer.set_text(
431
            _("No network connection detected, you can not download "
432
              "changelog information."))
433
    # else, get it from the entwork
10 by Michael Vogt
* code cleanup, make it all more structured
434
    else:
11 by Michael Vogt
* use SimpleGladeApp in UpdateManager now
435
      if self.expander_details.get_expanded():
2407 by Colin Watson
Use the threading module instead of thread (renamed to _thread in Python
436
        lock = threading.Lock()
10 by Michael Vogt
* code cleanup, make it all more structured
437
        lock.acquire()
2407 by Colin Watson
Use the threading module instead of thread (renamed to _thread in Python
438
        changelog_thread = threading.Thread(
439
            target=self.cache.get_news_and_changelog, args=(name, lock))
440
        changelog_thread.start()
337.4.37 by Sebastian Heinlein
* place the cancel button into the changes textview
441
        changes_buffer.set_text("%s\n" % _("Downloading list of changes..."))
442
        iter = changes_buffer.get_iter_at_line(1)
443
        anchor = changes_buffer.create_child_anchor(iter)
2119.1.1 by Robert Roth
Porting to PyGI
444
        button = Gtk.Button(stock="gtk-cancel")
337.4.37 by Sebastian Heinlein
* place the cancel button into the changes textview
445
        self.textview_changes.add_child_at_anchor(button, anchor)
10 by Michael Vogt
* code cleanup, make it all more structured
446
        button.show()
447
        id = button.connect("clicked",
448
                            lambda w,lock: lock.release(), lock)
449
        # wait for the dl-thread
450
        while lock.locked():
887 by Michael Vogt
- do not crash on BadStatusLine exceptions (LP: #204075)
451
          time.sleep(0.01)
2119.1.1 by Robert Roth
Porting to PyGI
452
          while Gtk.events_pending():
453
            Gtk.main_iteration()
10 by Michael Vogt
* code cleanup, make it all more structured
454
        # download finished (or canceld, or time-out)
455
        button.hide()
2224.1.1 by Robert Roth
Only disconnect handler if it's still connected (LP: #133139)
456
        if button.handler_is_connected(id):
457
            button.disconnect(id)
1520 by Michael Vogt
* UpdateManager/UpdateManager.py:
458
    # check if we still are in the right pkg (the download may have taken
459
    # some time and the user may have clicked on a new pkg)
460
    path  = widget.get_cursor()[0]
461
    if path == None:
462
      return
463
    now_name = widget.get_model()[path][LIST_NAME]
464
    if name != now_name:
465
        return
1267 by Michael Vogt
support getting NEWS.Debian information in addition
466
    # display NEWS.Debian first, then the changelog
467
    changes = ""
468
    srcpkg = self.cache[name].sourcePackageName
469
    if self.cache.all_news.has_key(name):
470
        changes += self.cache.all_news[name]
57 by Michael Vogt
* [code-cleanup] moved get_changelog() to MyCache()
471
    if self.cache.all_changes.has_key(name):
1267 by Michael Vogt
support getting NEWS.Debian information in addition
472
        changes += self.cache.all_changes[name]
473
    if changes:
474
        self.set_changes_buffer(changes_buffer, changes, name, srcpkg)
10 by Michael Vogt
* code cleanup, make it all more structured
475
337.4.11 by glatzor at ubuntu
* Allow to select all or none update - fixes #42296
476
  def show_context_menu(self, widget, event):
477
    """
478
    Show a context menu if a right click was performed on an update entry
479
    """
2119.1.1 by Robert Roth
Porting to PyGI
480
    if event.type == Gdk.EventType.BUTTON_PRESS and event.button == 3:
2146.2.3 by Michael Vogt
fix context menu, fix cursor, fix software-properties-gtk loading
481
        # need to keep a reference here of menu, otherwise it gets
482
        # deleted when it goes out of scope and no menu is visible
483
        # (bug #806949)
484
        self.menu = menu = Gtk.Menu()
2182.1.1 by Robert Roth
Rename Check all/Uncheck all to Select/Deselect all
485
        item_select_none = Gtk.MenuItem.new_with_mnemonic(_("_Deselect All"))
337.4.11 by glatzor at ubuntu
* Allow to select all or none update - fixes #42296
486
        item_select_none.connect("activate", self.select_none_updgrades)
2146.2.3 by Michael Vogt
fix context menu, fix cursor, fix software-properties-gtk loading
487
        menu.append(item_select_none)
358.1.39 by Michael Vogt
* UpdateManager/UpdateManager.py:
488
        num_updates = self.cache.installCount
489
        if num_updates == 0:
337.4.11 by glatzor at ubuntu
* Allow to select all or none update - fixes #42296
490
            item_select_none.set_property("sensitive", False)
2182.1.1 by Robert Roth
Rename Check all/Uncheck all to Select/Deselect all
491
        item_select_all = Gtk.MenuItem.new_with_mnemonic(_("Select _All"))
337.4.11 by glatzor at ubuntu
* Allow to select all or none update - fixes #42296
492
        item_select_all.connect("activate", self.select_all_updgrades)
2146.2.3 by Michael Vogt
fix context menu, fix cursor, fix software-properties-gtk loading
493
        menu.append(item_select_all)
337.4.11 by glatzor at ubuntu
* Allow to select all or none update - fixes #42296
494
        menu.show_all()
2146.2.3 by Michael Vogt
fix context menu, fix cursor, fix software-properties-gtk loading
495
        menu.popup_for_device(
496
            None, None, None, None, None, event.button, event.time)
497
        menu.show()
337.4.11 by glatzor at ubuntu
* Allow to select all or none update - fixes #42296
498
        return True
499
2281 by Michael Vogt
* UpdateManager/UpdateManager.py:
500
  # we need this for select all/unselect all
501
  def _toggle_origin_headers(self, new_selection_value):
502
    """ small helper that will set/unset the origin headers
503
    """
504
    model = self.treeview_update.get_model()
505
    for row in model:
506
        if not model.get_value(row.iter, LIST_PKG):
507
            model.set_value(row.iter, LIST_TOGGLE_CHECKED, new_selection_value)
508
337.4.11 by glatzor at ubuntu
* Allow to select all or none update - fixes #42296
509
  def select_all_updgrades(self, widget):
510
    """
511
    Select all updates
512
    """
358.1.39 by Michael Vogt
* UpdateManager/UpdateManager.py:
513
    self.setBusy(True)
514
    self.cache.saveDistUpgrade()
2281 by Michael Vogt
* UpdateManager/UpdateManager.py:
515
    self._toggle_origin_headers(True)
358.1.39 by Michael Vogt
* UpdateManager/UpdateManager.py:
516
    self.treeview_update.queue_draw()
488 by Michael Vogt
* update download size if "check/uncheck" all was selected from
517
    self.refresh_updates_count()
358.1.39 by Michael Vogt
* UpdateManager/UpdateManager.py:
518
    self.setBusy(False)
337.4.11 by glatzor at ubuntu
* Allow to select all or none update - fixes #42296
519
520
  def select_none_updgrades(self, widget):
521
    """
522
    Select none updates
523
    """
358.1.39 by Michael Vogt
* UpdateManager/UpdateManager.py:
524
    self.setBusy(True)
525
    self.cache.clear()
2281 by Michael Vogt
* UpdateManager/UpdateManager.py:
526
    self._toggle_origin_headers(False)
358.1.39 by Michael Vogt
* UpdateManager/UpdateManager.py:
527
    self.treeview_update.queue_draw()
488 by Michael Vogt
* update download size if "check/uncheck" all was selected from
528
    self.refresh_updates_count()
358.1.39 by Michael Vogt
* UpdateManager/UpdateManager.py:
529
    self.setBusy(False)
337.4.11 by glatzor at ubuntu
* Allow to select all or none update - fixes #42296
530
358.1.39 by Michael Vogt
* UpdateManager/UpdateManager.py:
531
  def setBusy(self, flag):
532
      """ Show a watch cursor if the app is busy for more than 0.3 sec.
533
      Furthermore provide a loop to handle user interface events """
2146.2.1 by Michael Vogt
initial pygi port, fixup a based on the work of evfool (thanks!). fixed a bunch of stuff but still crashing (gtktextiter problem?)
534
      if self.window_main.get_window() is None:
358.1.39 by Michael Vogt
* UpdateManager/UpdateManager.py:
535
          return
536
      if flag == True:
2146.2.1 by Michael Vogt
initial pygi port, fixup a based on the work of evfool (thanks!). fixed a bunch of stuff but still crashing (gtktextiter problem?)
537
          self.window_main.get_window().set_cursor(Gdk.Cursor.new(Gdk.CursorType.WATCH))
358.1.39 by Michael Vogt
* UpdateManager/UpdateManager.py:
538
      else:
2146.2.1 by Michael Vogt
initial pygi port, fixup a based on the work of evfool (thanks!). fixed a bunch of stuff but still crashing (gtktextiter problem?)
539
          self.window_main.get_window().set_cursor(None)
2119.1.1 by Robert Roth
Porting to PyGI
540
      while Gtk.events_pending():
541
          Gtk.main_iteration()
358.1.39 by Michael Vogt
* UpdateManager/UpdateManager.py:
542
543
  def refresh_updates_count(self):
544
      self.button_install.set_sensitive(self.cache.installCount)
485 by Michael Vogt
* UpdateManager/UpdateManager.py:
545
      try:
1875.1.3 by Mohamed Amine IL Idrissi
Small fixes.
546
          inst_count = self.cache.installCount
485 by Michael Vogt
* UpdateManager/UpdateManager.py:
547
          self.dl_size = self.cache.requiredDownload
1881 by Michael Vogt
Implemented battery and network alerts directly in the main window.
548
          download_str = ""
1875.1.1 by Mohamed Amine IL Idrissi
Prepared the UI.
549
          if self.dl_size != 0:
1881 by Michael Vogt
Implemented battery and network alerts directly in the main window.
550
              download_str = _("%s will be downloaded.") % (humanize_size(self.dl_size))
1875.1.1 by Mohamed Amine IL Idrissi
Prepared the UI.
551
              self.image_downsize.set_sensitive(True)
1901 by Michael Vogt
* UpdateManager/UpdateManager.py:
552
              # do not set the buttons to sensitive/insensitive until NM
553
              # can deal with dialup connections properly
554
              #if self.alert_watcher.network_state != NM_STATE_CONNECTED:
555
              #    self.button_install.set_sensitive(False)
556
              #else:
557
              #    self.button_install.set_sensitive(True)
558
              self.button_install.set_sensitive(True)
2105 by Michael Vogt
move unity support into its own class so that its optional
559
              self.unity.set_install_menuitem_visible(True)
1875.1.1 by Mohamed Amine IL Idrissi
Prepared the UI.
560
          else:
1881 by Michael Vogt
Implemented battery and network alerts directly in the main window.
561
              if inst_count > 0:
2425.1.1 by Michael Terry
update several strings to match the software updater spec; most notably, rename from Update Manager to Software Updater
562
                  download_str = ngettext("The update has already been downloaded.",
563
                  "The updates have already been downloaded.", inst_count)
1875.1.3 by Mohamed Amine IL Idrissi
Small fixes.
564
                  self.button_install.set_sensitive(True)
2105 by Michael Vogt
move unity support into its own class so that its optional
565
                  self.unity.set_install_menuitem_visible(True)
1875.1.1 by Mohamed Amine IL Idrissi
Prepared the UI.
566
              else:
2299 by Brian Murray
* UpdateManager/UpdateManager.py
567
                  download_str = _("There are no updates to install.")
1875.1.3 by Mohamed Amine IL Idrissi
Small fixes.
568
                  self.button_install.set_sensitive(False)
2105 by Michael Vogt
move unity support into its own class so that its optional
569
                  self.unity.set_install_menuitem_visible(False)
1875.1.2 by Mohamed Amine IL Idrissi
Finished implementing the feature.
570
              self.image_downsize.set_sensitive(False)
2425.1.1 by Michael Terry
update several strings to match the software updater spec; most notably, rename from Update Manager to Software Updater
571
          self.label_downsize.set_text(download_str)
1875.1.2 by Mohamed Amine IL Idrissi
Finished implementing the feature.
572
          self.hbox_downsize.show()
573
          self.vbox_alerts.show()
2395 by Colin Watson
Use "except Exception as e" syntax rather than the old-style "except
574
      except SystemError as e:
2394 by Colin Watson
Use Python 3-style print functions.
575
          print("requiredDownload could not be calculated: %s" % e)
1875.1.1 by Mohamed Amine IL Idrissi
Prepared the UI.
576
          self.label_downsize.set_markup(_("Unknown download size."))
577
          self.image_downsize.set_sensitive(False)
1875.1.2 by Mohamed Amine IL Idrissi
Finished implementing the feature.
578
          self.hbox_downsize.show()
1875.1.3 by Mohamed Amine IL Idrissi
Small fixes.
579
          self.vbox_alerts.show()
795 by Michael Vogt
- when no updates are available, display the information when the
580
10 by Michael Vogt
* code cleanup, make it all more structured
581
  def update_count(self):
187.2.20 by Sebastian Heinlein
* remove some old duplicated code
582
      """activate or disable widgets and show dialog texts correspoding to
583
         the number of available updates"""
358.1.39 by Michael Vogt
* UpdateManager/UpdateManager.py:
584
      self.refresh_updates_count()
585
      num_updates = self.cache.installCount
2103 by Michael Vogt
merged from lp:~bilalakhtar/update-manager/unity-quicklist (thanks!) and add a bit of magic to show the install count
586
587
      # setup unity stuff
2105 by Michael Vogt
move unity support into its own class so that its optional
588
      self.unity.set_updates_count(num_updates)
2103 by Michael Vogt
merged from lp:~bilalakhtar/update-manager/unity-quicklist (thanks!) and add a bit of magic to show the install count
589
358.1.39 by Michael Vogt
* UpdateManager/UpdateManager.py:
590
      if num_updates == 0:
2425.1.1 by Michael Terry
update several strings to match the software updater spec; most notably, rename from Update Manager to Software Updater
591
          text_header= _("The software on this computer is up to date.")
1814 by Michael Vogt
fix minor UI resize issue (LP: #572228)
592
          self.label_downsize.set_text("\n")
1887.1.1 by Philip Muskovac
don't make the treeview and the notebook not sensitive if there are hold packages.
593
          if self.cache.keepCount() == 0:
1884.2.1 by Mohamed Amine IL Idrissi
Merge patch from Nicolò Chieffo, many thanks.
594
              self.notebook_details.set_sensitive(False)
595
              self.treeview_update.set_sensitive(False)
187.2.57 by Sebastian Heinlein
* disable the install button if there are updates to install - #42284
596
          self.button_install.set_sensitive(False)
2105 by Michael Vogt
move unity support into its own class so that its optional
597
          self.unity.set_install_menuitem_visible(False)
187.2.10 by Sebastian Heinlein
* Fixed reload information
598
          self.button_close.grab_default()
187.2.20 by Sebastian Heinlein
* remove some old duplicated code
599
          self.textview_changes.get_buffer().set_text("")
600
          self.textview_descr.get_buffer().set_text("")
105 by Michael Vogt
* improved HIGification
601
      else:
1263 by Michael Vogt
in the background (UX team)
602
          # show different text on first run (UX team suggestion)
2146.2.12 by Michael Vogt
get rid of gconfclient references
603
          firstrun = self.settings.get_boolean("first-run")
1263 by Michael Vogt
in the background (UX team)
604
          if firstrun:
2425.1.1 by Michael Terry
update several strings to match the software updater spec; most notably, rename from Update Manager to Software Updater
605
              text_header = _("Updated software has been issued since %s was released. Do you want to install it now?") % self.meta.current_dist_description
2146.2.12 by Michael Vogt
get rid of gconfclient references
606
              self.settings.set_boolean("first-run", False)
1263 by Michael Vogt
in the background (UX team)
607
          else:
2425.1.1 by Michael Terry
update several strings to match the software updater spec; most notably, rename from Update Manager to Software Updater
608
              text_header = _("Updated software is available for this computer. Do you want to install it now?")
187.2.19 by Sebastian Heinlein
* use update_count in a more elegenat way
609
          self.notebook_details.set_sensitive(True)
126 by Michael Vogt
* merged with sebastian
610
          self.treeview_update.set_sensitive(True)
123.1.1 by Sebastian Heinlein
* Fixed some spacings
611
          self.button_install.grab_default()
2345 by Michael Vogt
* UpdateManager/UpdateManager.py:
612
          self.treeview_update.set_cursor(Gtk.TreePath.new_from_string("1"), None, False)
187.2.19 by Sebastian Heinlein
* use update_count in a more elegenat way
613
      self.label_header.set_markup(text_header)
1556 by Michael Vogt
* UpdateManager/UpdateManager.py:
614
      return True
10 by Michael Vogt
* code cleanup, make it all more structured
615
2428.1.1 by Michael Terry
move changelog widget into detail pane
616
  # Before we shrink the window, capture the size
617
  def pre_activate_details(self, expander):
618
    expanded = self.expander_details.get_expanded()
619
    if expanded:
620
      self.save_state()
621
10 by Michael Vogt
* code cleanup, make it all more structured
622
  def activate_details(self, expander, data):
11 by Michael Vogt
* use SimpleGladeApp in UpdateManager now
623
    expanded = self.expander_details.get_expanded()
2428.1.2 by Michael Terry
switch from pane view to second expander and also save state of toplevel expander
624
    self.settings.set_boolean("show-details",expanded)
10 by Michael Vogt
* code cleanup, make it all more structured
625
    if expanded:
12 by Michael Vogt
* get rid of the "Update" class, use a normal apt.Package instead
626
      self.on_treeview_update_cursor_changed(self.treeview_update)
2428.1.1 by Michael Terry
move changelog widget into detail pane
627
      self.restore_state()
628
    self.window_main.set_resizable(expanded)
10 by Michael Vogt
* code cleanup, make it all more structured
629
2428.1.2 by Michael Terry
switch from pane view to second expander and also save state of toplevel expander
630
  def activate_desc(self, expander, data):
631
    expanded = self.expander_desc.get_expanded()
632
    self.expander_desc.set_vexpand(expanded)
633
1312 by Michael Vogt
* DistUpgrade/cdromupgrade:
634
  #def on_button_help_clicked(self, widget):
635
  #  self.help_viewer.run()
10 by Michael Vogt
* code cleanup, make it all more structured
636
1306 by Michael Vogt
* data/glade/UpdateManager.glade:
637
  def on_button_settings_clicked(self, widget):
2394 by Colin Watson
Use Python 3-style print functions.
638
    #print("on_button_settings_clicked")
1455 by Michael Vogt
* UpdateManager/UpdateManager.py:
639
    try:
1876 by Michael Vogt
more python-apt 0.8 porting
640
        apt_pkg.pkgsystem_unlock()
1455 by Michael Vogt
* UpdateManager/UpdateManager.py:
641
    except SystemError:
642
        pass
2221 by Michael Vogt
call software-properties-gtk without gksu, that is no longer
643
    cmd = ["/usr/bin/software-properties-gtk",
644
           "--open-tab","2",
2146.2.3 by Michael Vogt
fix context menu, fix cursor, fix software-properties-gtk loading
645
           # FIXME: once get_xid() is available via introspections, add 
646
           #        this back
2221 by Michael Vogt
call software-properties-gtk without gksu, that is no longer
647
           #"--toplevel", "%s" % self.window_main.get_window().get_xid() 
648
          ]
1455 by Michael Vogt
* UpdateManager/UpdateManager.py:
649
    self.window_main.set_sensitive(False)
650
    p = subprocess.Popen(cmd)
651
    while p.poll() is None:
2119.1.1 by Robert Roth
Porting to PyGI
652
        while Gtk.events_pending():
653
            Gtk.main_iteration()
1455 by Michael Vogt
* UpdateManager/UpdateManager.py:
654
        time.sleep(0.05)
655
    self.fillstore()
1306 by Michael Vogt
* data/glade/UpdateManager.glade:
656
10 by Michael Vogt
* code cleanup, make it all more structured
657
  def on_button_install_clicked(self, widget):
2394 by Colin Watson
Use Python 3-style print functions.
658
    #print("on_button_install_clicked")
1170.1.1 by Michael Vogt
fix free space check on regular update-manager
659
    err_sum = _("Not enough free disk space")
1171 by Michael Vogt
fix free space check on regular update-manager
660
    err_long= _("The upgrade needs a total of %s free space on disk '%s'. "
1170.1.1 by Michael Vogt
fix free space check on regular update-manager
661
                "Please free at least an additional %s of disk "
662
                "space on '%s'. "
663
                "Empty your trash and remove temporary "
664
                "packages of former installations using "
665
                "'sudo apt-get clean'.")
666
    # check free space and error if its not enough
667
    try:
668
        self.cache.checkFreeSpace()
2395 by Colin Watson
Use "except Exception as e" syntax rather than the old-style "except
669
    except NotEnoughFreeSpaceError as e:
1373 by Michael Vogt
* UpdateManager/UpdateManager.py:
670
        for req in e.free_space_required_list:
671
            self.error(err_sum, err_long % (req.size_total,
672
                                            req.dir,
673
                                            req.size_needed,
674
                                            req.dir))
1170.1.1 by Michael Vogt
fix free space check on regular update-manager
675
        return
2395 by Colin Watson
Use "except Exception as e" syntax rather than the old-style "except
676
    except SystemError as e:
1931 by Michael Vogt
* UpdateManager/UpdateManager.py:
677
        logging.exception("free space check failed")
10 by Michael Vogt
* code cleanup, make it all more structured
678
    self.invoke_manager(INSTALL)
488 by Michael Vogt
* update download size if "check/uncheck" all was selected from
679
    
1853 by Michael Vogt
* UpdateManager/UpdateManager.py:
680
  def on_button_restart_required_clicked(self, button=None):
681
      self._request_reboot_via_session_manager()
682
683
  def show_reboot_required_info(self):
684
    self.frame_restart_required.show()
685
    self.label_restart_required.set_text(_("The computer needs to restart to "
686
                                       "finish installing updates. Please "
687
                                       "save your work before continuing."))
688
689
  def _request_reboot_via_session_manager(self):
690
    try:
691
        bus = dbus.SessionBus()
692
        proxy_obj = bus.get_object("org.gnome.SessionManager",
693
                                   "/org/gnome/SessionManager")
694
        iface = dbus.Interface(proxy_obj, "org.gnome.SessionManager")
695
        iface.RequestReboot()
2035 by Lionel Le Folgoc
UpdateManager/UpdateManager.py: try to reboot using consolekit if
696
    except dbus.DBusException:
697
        self._request_reboot_via_consolekit()
698
    except:
699
        pass
700
701
  def _request_reboot_via_consolekit(self):
702
    try:
703
        bus = dbus.SystemBus()
704
        proxy_obj = bus.get_object("org.freedesktop.ConsoleKit",
705
                                   "/org/freedesktop/ConsoleKit/Manager")
706
        iface = dbus.Interface(proxy_obj, "org.freedesktop.ConsoleKit.Manager")
707
        iface.Restart()
2164 by Michael Vogt
make UpdateManager/, tests/ pyflakes clean
708
    except dbus.DBusException:
1853 by Michael Vogt
* UpdateManager/UpdateManager.py:
709
        pass
1602 by Michael Vogt
* UpdateManager/UpdateManager.py:
710
10 by Michael Vogt
* code cleanup, make it all more structured
711
  def invoke_manager(self, action):
712
    # check first if no other package manager is runing
713
714
    # don't display apt-listchanges, we already showed the changelog
715
    os.environ["APT_LISTCHANGES_FRONTEND"]="none"
716
358.1.1 by Michael Vogt
* merged from glatzor
717
    # Do not suspend during the update process
1633.1.1 by sebi at glatzor
Make the InstallBackend an gobject and allow to process the actions asynchronously. Furthermore replace running synaptic in a separate thread by using gobject's spwan_async and child_watch_add.
718
    (self.sleep_dev, self.sleep_cookie) = inhibit_sleep()
358.1.1 by Michael Vogt
* merged from glatzor
719
10 by Michael Vogt
* code cleanup, make it all more structured
720
    # set window to insensitive
11 by Michael Vogt
* use SimpleGladeApp in UpdateManager now
721
    self.window_main.set_sensitive(False)
2146.2.3 by Michael Vogt
fix context menu, fix cursor, fix software-properties-gtk loading
722
    self.window_main.get_window().set_cursor(Gdk.Cursor.new(Gdk.CursorType.WATCH))
1633.1.3 by sebi at glatzor
Move the cache and gconf logic from the InstallBackend into UpdateManager
723
#
1478 by Michael Vogt
* DistUpgrade/DistUpgradeQuirks.py: add check for ARMv6 or
724
    # do it
725
    if action == UPDATE:
726
        self.install_backend.update()
727
    elif action == INSTALL:
1633.1.3 by sebi at glatzor
Move the cache and gconf logic from the InstallBackend into UpdateManager
728
        # If the progress dialog should be closed automatically afterwards
2146.2.12 by Michael Vogt
get rid of gconfclient references
729
        settings = Gio.Settings("com.ubuntu.update-manager")
730
        close_on_done = settings.get_boolean("autoclose-install-window")
1633.1.3 by sebi at glatzor
Move the cache and gconf logic from the InstallBackend into UpdateManager
731
        # Get the packages which should be installed and update
732
        pkgs_install = []
733
        pkgs_upgrade = []
734
        for pkg in self.cache:
1849 by Michael Vogt
UpdateManager/Core/utils.py,
735
            if pkg.marked_install:
1633.1.3 by sebi at glatzor
Move the cache and gconf logic from the InstallBackend into UpdateManager
736
                pkgs_install.append(pkg.name)
1849 by Michael Vogt
UpdateManager/Core/utils.py,
737
            elif pkg.marked_upgrade:
1633.1.3 by sebi at glatzor
Move the cache and gconf logic from the InstallBackend into UpdateManager
738
                pkgs_upgrade.append(pkg.name)
739
        self.install_backend.commit(pkgs_install, pkgs_upgrade, close_on_done)
1633.1.1 by sebi at glatzor
Make the InstallBackend an gobject and allow to process the actions asynchronously. Furthermore replace running synaptic in a separate thread by using gobject's spwan_async and child_watch_add.
740
1994 by Michael Vogt
improve install-backend error checking
741
  def _on_backend_done(self, backend, action, authorized, success):
1995.1.1 by Brendan Donegan
Added updated signal and option to do no update on startup
742
    if (action == UPDATE):
743
        self.dbusController.updated(success)
1633.1.1 by sebi at glatzor
Make the InstallBackend an gobject and allow to process the actions asynchronously. Furthermore replace running synaptic in a separate thread by using gobject's spwan_async and child_watch_add.
744
    # check if there is a new reboot required notification
1853 by Michael Vogt
* UpdateManager/UpdateManager.py:
745
    if (action == INSTALL and
746
        os.path.exists(REBOOT_REQUIRED_FILE)):
747
        self.show_reboot_required_info()
1884.1.1 by Mohamed Amine IL Idrissi
Cache is no longer initialized when an operation is not authorized.
748
    if authorized:
749
        msg = _("Reading package information")
750
        self.label_cache_progress_title.set_label("<b><big>%s</big></b>" % msg)
751
        self.fillstore()
358.1.1 by Michael Vogt
* merged from glatzor
752
753
    # Allow suspend after synaptic is finished
1633.1.1 by sebi at glatzor
Make the InstallBackend an gobject and allow to process the actions asynchronously. Furthermore replace running synaptic in a separate thread by using gobject's spwan_async and child_watch_add.
754
    if self.sleep_cookie:
755
        allow_sleep(self.sleep_dev, self.sleep_cookie)
756
        self.sleep_cookie = self.sleep_dev = None
123.1.33 by Sebastian Heinlein
* Do not allow to close the main window until actions are performed and the
757
    self.window_main.set_sensitive(True)
2146.2.3 by Michael Vogt
fix context menu, fix cursor, fix software-properties-gtk loading
758
    self.window_main.get_window().set_cursor(None)
10 by Michael Vogt
* code cleanup, make it all more structured
759
1875.1.2 by Mohamed Amine IL Idrissi
Finished implementing the feature.
760
  def _on_network_alert(self, watcher, state):
1892 by Michael Vogt
* UpdateManager/UpdateManager.py:
761
      # do not set the buttons to sensitive/insensitive until NM
762
      # can deal with dialup connections properly
2125.1.1 by Brendan Donegan
Updated NetworkManagerHelper with new NM 0.9 states as well as updating the UpdateManager itself to handle codes more robustly
763
      if state in NetworkManagerHelper.NM_STATE_CONNECTING_LIST:
1875.1.2 by Mohamed Amine IL Idrissi
Finished implementing the feature.
764
          self.label_offline.set_text(_("Connecting..."))
765
          self.refresh_updates_count()
766
          self.hbox_offline.show()
767
          self.vbox_alerts.show()
2047 by Michael Vogt
do not try to download changelogs if NM reports we are
768
          self.connected = False
769
      # in doubt (STATE_UNKNOWN), assume connected
2125.1.3 by Brendan Donegan
Few little fixes to some syntax errors I didn't test properly. Seems to work perfectly in O now.
770
      elif (state in NetworkManagerHelper.NM_STATE_CONNECTED_LIST or 
771
           state == NetworkManagerHelper.NM_STATE_UNKNOWN):
1875.1.3 by Mohamed Amine IL Idrissi
Small fixes.
772
          self.refresh_updates_count()
1875.1.2 by Mohamed Amine IL Idrissi
Finished implementing the feature.
773
          self.hbox_offline.hide()
2047 by Michael Vogt
do not try to download changelogs if NM reports we are
774
          self.connected = True
775
          # trigger re-showing the current app to get changelog info (if needed)
776
          self.on_treeview_update_cursor_changed(self.treeview_update)
1875.1.2 by Mohamed Amine IL Idrissi
Finished implementing the feature.
777
      else:
2047 by Michael Vogt
do not try to download changelogs if NM reports we are
778
          self.connected = False
1875.1.2 by Mohamed Amine IL Idrissi
Finished implementing the feature.
779
          self.label_offline.set_text(_("You may not be able to check for updates or download new updates."))
780
          self.refresh_updates_count()
781
          self.hbox_offline.show()
782
          self.vbox_alerts.show()
783
          
784
  def _on_battery_alert(self, watcher, on_battery):
785
      if on_battery:
786
          self.hbox_battery.show()
787
          self.vbox_alerts.show()
788
      else:
789
          self.hbox_battery.hide()    
790
2038 by Michael Vogt
display warning when on 3g and when roaming
791
  def _on_network_3g_alert(self, watcher, on_3g, is_roaming):
2394 by Colin Watson
Use Python 3-style print functions.
792
      #print("on 3g: %s; roaming: %s" % (on_3g, is_roaming))
2038 by Michael Vogt
display warning when on 3g and when roaming
793
      if is_roaming:
794
          self.hbox_roaming.show()
795
          self.hbox_on_3g.hide()
796
      elif on_3g:
797
          self.hbox_on_3g.show()
798
          self.hbox_roaming.hide()
799
      else:
2040 by Michael Vogt
refactor so that all the constants are part of NetworkManagerHelper
800
          self.hbox_on_3g.hide()
2038 by Michael Vogt
display warning when on 3g and when roaming
801
          self.hbox_roaming.hide()
2074.1.3 by Robert Roth
Whitespace fixes
802
  def row_activated(self, treeview, path, column):
2074.1.2 by Robert Roth
Patch cleanup
803
      iter = self.store.get_iter(path)
804
          
805
      pkg = self.store.get_value(iter, LIST_PKG)
806
      origin = self.store.get_value(iter, LIST_ORIGIN)
807
      if pkg is not None:
808
          return
809
      self.toggle_from_origin(pkg, origin, True)
2074.1.3 by Robert Roth
Whitespace fixes
810
  def toggle_from_origin(self, pkg, origin, select_all = True ):
966 by egon
* UpdateManager/UpdateManager.py:
811
      self.setBusy(True)
1851 by Michael Vogt
more python0.8 API transition
812
      actiongroup = apt_pkg.ActionGroup(self.cache._depcache)
966 by egon
* UpdateManager/UpdateManager.py:
813
      for pkg in self.list.pkgs[origin]:
1849 by Michael Vogt
UpdateManager/Core/utils.py,
814
          if pkg.marked_install or pkg.marked_upgrade:
2394 by Colin Watson
Use Python 3-style print functions.
815
              #print("marking keep: ", pkg.name)
2074.1.3 by Robert Roth
Whitespace fixes
816
              pkg.mark_keep()
817
          elif not (pkg.name in self.list.held_back):
2394 by Colin Watson
Use Python 3-style print functions.
818
              #print("marking install: ", pkg.name)
2102.1.12 by Michael Vogt
fix arguments from "autInst" to "auto_inst" and
819
              pkg.mark_install(auto_fix=False,auto_inst=False)
966 by egon
* UpdateManager/UpdateManager.py:
820
      # check if we left breakage
1851 by Michael Vogt
more python0.8 API transition
821
      if self.cache._depcache.broken_count:
822
          Fix = apt_pkg.ProblemResolver(self.cache._depcache)
823
          Fix.resolve_by_keep()
966 by egon
* UpdateManager/UpdateManager.py:
824
      self.refresh_updates_count()
825
      self.treeview_update.queue_draw()
826
      del actiongroup
827
      self.setBusy(False)
2074.1.2 by Robert Roth
Patch cleanup
828
  
337.4.13 by glatzor at ubuntu
* no need to convert the path to a string in call of toggled
829
  def toggled(self, renderer, path):
10 by Michael Vogt
* code cleanup, make it all more structured
830
    """ a toggle button in the listview was toggled """
337.4.13 by glatzor at ubuntu
* no need to convert the path to a string in call of toggled
831
    iter = self.store.get_iter(path)
358.1.2 by Michael Vogt
* UpdateManager/UpdateManager.py:
832
    pkg = self.store.get_value(iter, LIST_PKG)
2074.1.1 by Robert Roth
Checkboxes for headers
833
    origin = self.store.get_value(iter, LIST_ORIGIN)
337.4.29 by glatzor at ubuntu
* do not allow to toggle deactivated updates by row activation
834
    # make sure that we don't allow to toggle deactivated updates
835
    # this is needed for the call by the row activation callback
2074.1.1 by Robert Roth
Checkboxes for headers
836
    if pkg is None:
2404 by Colin Watson
Remove all hard tabs from Python code. Python 3 no longer tolerates
837
        toggled_value = not self.store.get_value(iter, LIST_TOGGLE_CHECKED)
838
        self.toggle_from_origin(pkg, origin, toggled_value)
839
        self.store.set_value(iter, LIST_TOGGLE_CHECKED, toggled_value )
840
        self.treeview_update.queue_draw()
841
        return
475 by Michael Vogt
* UpdateManager/UpdateManager.py:
842
    if pkg is None or pkg.name in self.list.held_back:
337.4.29 by glatzor at ubuntu
* do not allow to toggle deactivated updates by row activation
843
        return False
844
    self.setBusy(True)
358.1.39 by Michael Vogt
* UpdateManager/UpdateManager.py:
845
    # update the cache
1849 by Michael Vogt
UpdateManager/Core/utils.py,
846
    if pkg.marked_install or pkg.marked_upgrade:
1851 by Michael Vogt
more python0.8 API transition
847
        pkg.mark_keep()
1849 by Michael Vogt
UpdateManager/Core/utils.py,
848
        if self.cache._depcache.broken_count:
1851 by Michael Vogt
more python0.8 API transition
849
            Fix = apt_pkg.ProblemResolver(self.cache._depcache)
850
            Fix.resolve_by_keep()
10 by Michael Vogt
* code cleanup, make it all more structured
851
    else:
2236 by Michael Vogt
* UpdateManager/UpdateManager.py:
852
        try:
853
            pkg.mark_install()
854
        except SystemError:
855
            pass
358.1.39 by Michael Vogt
* UpdateManager/UpdateManager.py:
856
    self.treeview_update.queue_draw()
857
    self.refresh_updates_count()
858
    self.setBusy(False)
10 by Michael Vogt
* code cleanup, make it all more structured
859
337.4.13 by glatzor at ubuntu
* no need to convert the path to a string in call of toggled
860
  def on_treeview_update_row_activated(self, treeview, path, column, *args):
1481 by Michael Vogt
* UpdateManager/UpdateManager.py:
861
    """
862
    If an update row was activated (by pressing space), toggle the 
863
    install check box
864
    """
865
    self.toggled(None, path)
866
10 by Michael Vogt
* code cleanup, make it all more structured
867
  def exit(self):
868
    """ exit the application, save the state """
869
    self.save_state()
2119.1.1 by Robert Roth
Porting to PyGI
870
    #Gtk.main_quit()
10 by Michael Vogt
* code cleanup, make it all more structured
871
    sys.exit(0)
872
873
  def save_state(self):
874
    """ save the state  (window-size for now) """
2428.1.1 by Michael Terry
move changelog widget into detail pane
875
    if self.expander_details.get_expanded():
876
      (w, h) = self.window_main.get_size()
877
      self.settings.set_int("window-width", w)
878
      self.settings.set_int("window-height", h)
10 by Michael Vogt
* code cleanup, make it all more structured
879
880
  def restore_state(self):
881
    """ restore the state (window-size for now) """
2146.2.12 by Michael Vogt
get rid of gconfclient references
882
    w = self.settings.get_int("window-width")
883
    h = self.settings.get_int("window-height")
2428.1.1 by Michael Terry
move changelog widget into detail pane
884
    if w > 0 and h > 0 and self.expander_details.get_expanded():
2146.2.11 by Michael Vogt
initial port from gconf -> gsettings, this needs some cleanup in the naming still
885
      self.window_main.resize(w, h)
2428.1.1 by Michael Terry
move changelog widget into detail pane
886
    return False
10 by Michael Vogt
* code cleanup, make it all more structured
887
888
  def fillstore(self):
187.2.16 by Sebastian Heinlein
* fixed a bug in the previous commit
889
    # use the watch cursor
358.1.39 by Michael Vogt
* UpdateManager/UpdateManager.py:
890
    self.setBusy(True)
2382 by Michael Vogt
* UpdateManager/UpdateManager.py:
891
    # disconnect the view first
892
    self.treeview_update.set_model(None)
893
    self.store.clear()
894
    
10 by Michael Vogt
* code cleanup, make it all more structured
895
    # clean most objects
896
    self.dl_size = 0
465 by Michael Vogt
* UpdateManager/UpdateManager.py:
897
    try:
1870 by Michael Vogt
remove a bunch of with ExecutionTime and move it out to the cache
898
        self.initCache()
2395 by Colin Watson
Use "except Exception as e" syntax rather than the old-style "except
899
    except SystemError as e:
465 by Michael Vogt
* UpdateManager/UpdateManager.py:
900
        msg = ("<big><b>%s</b></big>\n\n%s\n'%s'" %
901
               (_("Could not initialize the package information"),
859.1.1 by Brian Murray
string fixes for bugs 196269, 196229, 197015
902
                _("An unresolvable problem occurred while "
487 by Michael Vogt
* fix spelling mistakes (thanks to Bruce Cowan, LP#90833)
903
                  "initializing the package information.\n\n"
465 by Michael Vogt
* UpdateManager/UpdateManager.py:
904
                  "Please report this bug against the 'update-manager' "
905
                  "package and include the following error message:\n"),
906
                e)
907
               )
2119.1.1 by Robert Roth
Porting to PyGI
908
        dialog = Gtk.MessageDialog(self.window_main,
909
                                   0, Gtk.MessageType.ERROR,
910
                                   Gtk.ButtonsType.CLOSE,"")
465 by Michael Vogt
* UpdateManager/UpdateManager.py:
911
        dialog.set_markup(msg)
2175.1.1 by Michael Terry
don't use Gtk.MessageDialog.vbox, instead use get_content_area
912
        dialog.get_content_area().set_spacing(6)
465 by Michael Vogt
* UpdateManager/UpdateManager.py:
913
        dialog.run()
914
        dialog.destroy()
915
        sys.exit(1)
1870 by Michael Vogt
remove a bunch of with ExecutionTime and move it out to the cache
916
    self.list = UpdateList(self)
2382 by Michael Vogt
* UpdateManager/UpdateManager.py:
917
    
2119.1.1 by Robert Roth
Porting to PyGI
918
    while Gtk.events_pending():
919
        Gtk.main_iteration()
1995.1.1 by Brendan Donegan
Added updated signal and option to do no update on startup
920
10 by Michael Vogt
* code cleanup, make it all more structured
921
    # fill them again
406 by Michael Vogt
* UpdateManager/UpdateManager.py:
922
    try:
1995.1.1 by Brendan Donegan
Added updated signal and option to do no update on startup
923
        # This is  a quite nasty hack to stop the initial update 
924
        if not self.options.no_update:
925
            self.list.update(self.cache)
926
        else:
927
            self.options.no_update = False
2395 by Colin Watson
Use "except Exception as e" syntax rather than the old-style "except
928
    except SystemError as e:
406 by Michael Vogt
* UpdateManager/UpdateManager.py:
929
        msg = ("<big><b>%s</b></big>\n\n%s\n'%s'" %
930
               (_("Could not calculate the upgrade"),
859.1.1 by Brian Murray
string fixes for bugs 196269, 196229, 197015
931
                _("An unresolvable problem occurred while "
406 by Michael Vogt
* UpdateManager/UpdateManager.py:
932
                  "calculating the upgrade.\n\n"
933
                  "Please report this bug against the 'update-manager' "
934
                  "package and include the following error message:"),
935
                e)
936
               )
2119.1.1 by Robert Roth
Porting to PyGI
937
        dialog = Gtk.MessageDialog(self.window_main,
938
                                   0, Gtk.MessageType.ERROR,
939
                                   Gtk.ButtonsType.CLOSE,"")
406 by Michael Vogt
* UpdateManager/UpdateManager.py:
940
        dialog.set_markup(msg)
2175.1.1 by Michael Terry
don't use Gtk.MessageDialog.vbox, instead use get_content_area
941
        dialog.get_content_area().set_spacing(6)
406 by Michael Vogt
* UpdateManager/UpdateManager.py:
942
        dialog.run()
943
        dialog.destroy()
187.2.20 by Sebastian Heinlein
* remove some old duplicated code
944
    if self.list.num_updates > 0:
1869 by Michael Vogt
- limit the amount of set_fraction() here too (LP: #595845)
945
      #self.treeview_update.set_model(None)
1853 by Michael Vogt
* UpdateManager/UpdateManager.py:
946
      self.scrolledwindow_update.show()
337.4.4 by glatzor at ubuntu
* use -s option instead of the pipe to cut to get lsb information
947
      origin_list = self.list.pkgs.keys()
948
      origin_list.sort(lambda x,y: cmp(x.importance,y.importance))
337.4.9 by glatzor at ubuntu
* reverse the ording of the importance
949
      origin_list.reverse()
337.4.4 by glatzor at ubuntu
* use -s option instead of the pipe to cut to get lsb information
950
      for origin in origin_list:
358.1.39 by Michael Vogt
* UpdateManager/UpdateManager.py:
951
        self.store.append(['<b><big>%s</big></b>' % origin.description,
1794 by Michael Vogt
* UpdateManager/UpdateManager.py:
952
                           origin.description, None, origin,True])
351 by Michael Vogt
* UpdateManager/UpdateManager.py:
953
        for pkg in self.list.pkgs[origin]:
337.4.3 by glatzor at ubuntu
* replace tabs by spaces
954
          name = xml.sax.saxutils.escape(pkg.name)
1849 by Michael Vogt
UpdateManager/Core/utils.py,
955
          if not pkg.is_installed:
1463 by Michael Vogt
* UpdateManager/UpdateManager.py:
956
              name += _(" (New install)")
337.4.3 by glatzor at ubuntu
* replace tabs by spaces
957
          summary = xml.sax.saxutils.escape(pkg.summary)
1857.1.1 by rugby471 at gmail
Fixes LP: #386196
958
          if self.summary_before_name:
1871 by Michael Vogt
UpdateManager/UpdateManager.py: fix silly ordering in u-m
959
              contents = "%s\n<small>%s</small>" % (summary, name)
960
          else:
1857.1.1 by rugby471 at gmail
Fixes LP: #386196
961
              contents = "<b>%s</b>\n<small>%s</small>" % (name, summary)
337.4.6 by glatzor at ubuntu
* Handle to be newly installed "updates" in the version string
962
          #TRANSLATORS: the b stands for Bytes
337.4.42 by Sebastian Heinlein
* Fixed a missing import
963
          size = _("(Size: %s)") % humanize_size(pkg.packageSize)
1081 by Michael Vogt
* UpdateManager/UpdateManager.py:
964
          if pkg.installedVersion != None:
965
              version = _("From version %(old_version)s to %(new_version)s") %\
966
                  {"old_version" : pkg.installedVersion,
967
                   "new_version" : pkg.candidateVersion}
968
          else:
969
              version = _("Version %s") % pkg.candidateVersion
1253 by Michael Vogt
* UpdateManager/UpdateManager.py:
970
          if self.show_versions:
1081 by Michael Vogt
* UpdateManager/UpdateManager.py:
971
              contents = "%s\n<small>%s %s</small>" % (contents, version, size)
972
          else:
973
              contents = "%s <small>%s</small>" % (contents, size)
1794 by Michael Vogt
* UpdateManager/UpdateManager.py:
974
          self.store.append([contents, pkg.name, pkg, None, True])
1869 by Michael Vogt
- limit the amount of set_fraction() here too (LP: #595845)
975
      self.treeview_update.set_model(self.store)
187.2.19 by Sebastian Heinlein
* use update_count in a more elegenat way
976
    self.update_count()
358.1.39 by Michael Vogt
* UpdateManager/UpdateManager.py:
977
    self.setBusy(False)
2382 by Michael Vogt
* UpdateManager/UpdateManager.py:
978
    while Gtk.events_pending():
979
      Gtk.main_iteration()
337.4.26 by glatzor at ubuntu
* use a different label for the cache progress dialog if it gets
980
    self.check_all_updates_installable()
1875.1.3 by Mohamed Amine IL Idrissi
Small fixes.
981
    self.refresh_updates_count()
10 by Michael Vogt
* code cleanup, make it all more structured
982
    return False
983
14 by Michael Vogt
* move the MetaRelease code into it's own class/file
984
  def dist_no_longer_supported(self, meta_release):
1965 by Michael Vogt
* check-new-release-gtk:
985
    show_dist_no_longer_supported_dialog(self.window_main)
358.1.123 by Michael Vogt
* UpdateManager/UpdateManager.py:
986
1020 by Michael Vogt
* debian/control:
987
  def error(self, summary, details):
988
      " helper function to display a error message "
989
      msg = ("<big><b>%s</b></big>\n\n%s\n" % (summary, details) )
2119.1.1 by Robert Roth
Porting to PyGI
990
      dialog = Gtk.MessageDialog(self.window_main,
991
                                 0, Gtk.MessageType.ERROR,
992
                                 Gtk.ButtonsType.CLOSE,"")
1020 by Michael Vogt
* debian/control:
993
      dialog.set_markup(msg)
2175.1.1 by Michael Terry
don't use Gtk.MessageDialog.vbox, instead use get_content_area
994
      dialog.get_content_area().set_spacing(6)
1020 by Michael Vogt
* debian/control:
995
      dialog.run()
996
      dialog.destroy()
997
13 by Michael Vogt
* show button when new distro is available
998
  def on_button_dist_upgrade_clicked(self, button):
2394 by Colin Watson
Use Python 3-style print functions.
999
      #print("on_button_dist_upgrade_clicked")
1824 by Michael Vogt
* UpdateManager/Core/MetaRelease.py:
1000
      if self.new_dist.upgrade_broken:
1001
          return self.error(
1002
              _("Release upgrade not possible right now"),
1003
              _("The release upgrade can not be performed currently, "
1004
                "please try again later. The server reported: '%s'") % self.new_dist.upgrade_broken)
2420 by Colin Watson
Port to python-apt 0.8 progress classes.
1005
      fetcher = DistUpgradeFetcherGtk(new_dist=self.new_dist, parent=self, progress=GtkAcquireProgress(self, _("Downloading the release upgrade tool")))
1170.2.8 by Michael Vogt
add --sandbox option to the dist-upgrade fetcher
1006
      if self.options.sandbox:
1007
          fetcher.run_options.append("--sandbox")
179.1.11 by Michael Vogt
* move the fetcher code out into UpdateManager/DistUpgradeFetcher.py
1008
      fetcher.run()
18 by Michael Vogt
* dist-upgade tool can fetch the update tarball now
1009
      
14 by Michael Vogt
* move the MetaRelease code into it's own class/file
1010
  def new_dist_available(self, meta_release, upgradable_to):
13 by Michael Vogt
* show button when new distro is available
1011
    self.frame_new_release.show()
1503.1.1 by Josh Holland
Changed 'distribution' to 'Ubuntu'
1012
    self.label_new_release.set_markup(_("<b>New Ubuntu release '%s' is available</b>") % upgradable_to.version)
17 by Michael Vogt
* release notes information added
1013
    self.new_dist = upgradable_to
10 by Michael Vogt
* code cleanup, make it all more structured
1014
    
1015
1016
  # fixme: we should probably abstract away all the stuff from libapt
1017
  def initCache(self): 
1018
    # get the lock
1019
    try:
1876 by Michael Vogt
more python-apt 0.8 porting
1020
        apt_pkg.pkgsystem_lock()
2164 by Michael Vogt
make UpdateManager/, tests/ pyflakes clean
1021
    except SystemError:
337.1.3 by Sebastian Heinlein
* use dbus to bring up another running instance update-manager
1022
        pass
2119.1.1 by Robert Roth
Porting to PyGI
1023
        #d = Gtk.MessageDialog(parent=self.window_main,
1024
        #                      flags=Gtk.DialogFlags.MODAL,
1025
        #                      type=Gtk.MessageType.ERROR,
1026
        #                      buttons=Gtk.ButtonsType.CLOSE)
337.1.3 by Sebastian Heinlein
* use dbus to bring up another running instance update-manager
1027
        #d.set_markup("<big><b>%s</b></big>\n\n%s" % (
1028
        #    _("Only one software management tool is allowed to "
1029
        #      "run at the same time"),
1030
        #    _("Please close the other application e.g. 'aptitude' "
1031
        #      "or 'Synaptic' first.")))
2394 by Colin Watson
Use Python 3-style print functions.
1032
        #print("error from apt: '%s'" % e)
337.1.3 by Sebastian Heinlein
* use dbus to bring up another running instance update-manager
1033
        #d.set_title("")
1034
        #res = d.run()
1035
        #d.destroy()
1036
        #sys.exit()
10 by Michael Vogt
* code cleanup, make it all more structured
1037
112 by Michael Vogt
* warn if the cache is broken
1038
    try:
358.1.126 by Michael Vogt
* UpdateManager/UpdateManager.py:
1039
        if hasattr(self, "cache"):
1262 by Michael Vogt
add "--no-focus-on-map option to bring update-manager up
1040
            self.cache.open(self.progress)
358.1.126 by Michael Vogt
* UpdateManager/UpdateManager.py:
1041
            self.cache._initDepCache()
1042
        else:
1262 by Michael Vogt
add "--no-focus-on-map option to bring update-manager up
1043
            self.cache = MyCache(self.progress)
112 by Michael Vogt
* warn if the cache is broken
1044
    except AssertionError:
807 by Michael Vogt
* UpdateManager/UpdateManager.py:
1045
        # if the cache could not be opened for some reason,
1046
        # let the release upgrader handle it, it deals
1047
        # a lot better with this
1048
        self.ask_run_partial_upgrade()
112 by Michael Vogt
* warn if the cache is broken
1049
        # we assert a clean cache
1050
        msg=("<big><b>%s</b></big>\n\n%s"% \
123.1.26 by Sebastian Heinlein
* Use the label_status in GtkOpProgress and not the progress bar
1051
             (_("Software index is broken"),
1052
              _("It is impossible to install or remove any software. "
1053
                "Please use the package manager \"Synaptic\" or run "
2404 by Colin Watson
Remove all hard tabs from Python code. Python 3 no longer tolerates
1054
                "\"sudo apt-get install -f\" in a terminal to fix "
1055
                "this issue at first.")))
2119.1.1 by Robert Roth
Porting to PyGI
1056
        dialog = Gtk.MessageDialog(self.window_main,
1057
                                   0, Gtk.MessageType.ERROR,
1058
                                   Gtk.ButtonsType.CLOSE,"")
112 by Michael Vogt
* warn if the cache is broken
1059
        dialog.set_markup(msg)
2175.1.1 by Michael Terry
don't use Gtk.MessageDialog.vbox, instead use get_content_area
1060
        dialog.get_content_area().set_spacing(6)
112 by Michael Vogt
* warn if the cache is broken
1061
        dialog.run()
123.1.42 by Sebastian Heinlein
* Destroy all gtk.messagedialogs after use
1062
        dialog.destroy()
112 by Michael Vogt
* warn if the cache is broken
1063
        sys.exit(1)
187.1.13 by Sebastian Heinlein
* only run the progress bar one time during cache init
1064
    else:
1841 by Michael Vogt
* UpdateManager/GtkProgress.py:
1065
        self.progress.all_done()
123.1.16 by Sebastian Heinlein
DistUpgrade:
1066
337.4.24 by glatzor at ubuntu
* Move the "run full dit upgrade" dialog into the UpdateManager class -
1067
  def check_all_updates_installable(self):
1068
    """ Check if all available updates can be installed and suggest
1069
        to run a distribution upgrade if not """
358.1.113 by Michael Vogt
* UpdateManager/UpdateManager.py:
1070
    if self.list.distUpgradeWouldDelete > 0:
807 by Michael Vogt
* UpdateManager/UpdateManager.py:
1071
        self.ask_run_partial_upgrade()
1072
1073
  def ask_run_partial_upgrade(self):
337.4.24 by glatzor at ubuntu
* Move the "run full dit upgrade" dialog into the UpdateManager class -
1074
      self.dialog_dist_upgrade.set_transient_for(self.window_main)
1602 by Michael Vogt
* UpdateManager/UpdateManager.py:
1075
      self.dialog_dist_upgrade.set_title("")
337.4.24 by glatzor at ubuntu
* Move the "run full dit upgrade" dialog into the UpdateManager class -
1076
      res = self.dialog_dist_upgrade.run()
337.4.26 by glatzor at ubuntu
* use a different label for the cache progress dialog if it gets
1077
      self.dialog_dist_upgrade.hide()
2119.1.1 by Robert Roth
Porting to PyGI
1078
      if res == Gtk.ResponseType.YES:
337.4.24 by glatzor at ubuntu
* Move the "run full dit upgrade" dialog into the UpdateManager class -
1079
          os.execl("/usr/bin/gksu",
337.4.27 by glatzor at ubuntu
* use the update manager desktop file instead of the synaptic one, when
1080
                   "/usr/bin/gksu", "--desktop",
1081
                   "/usr/share/applications/update-manager.desktop",
1082
                   "--", "/usr/bin/update-manager", "--dist-upgrade")
807 by Michael Vogt
* UpdateManager/UpdateManager.py:
1083
      return False
123.1.16 by Sebastian Heinlein
DistUpgrade:
1084
642 by Michael Vogt
* UpdateManager/UpdateManager.py:
1085
  def check_metarelease(self):
1086
      " check for new meta-release information "
2146.2.12 by Michael Vogt
get rid of gconfclient references
1087
      settings = Gio.Settings("com.ubuntu.update-manager")
642 by Michael Vogt
* UpdateManager/UpdateManager.py:
1088
      self.meta = MetaRelease(self.options.devel_release,
1089
                              self.options.use_proposed)
1090
      self.meta.connect("dist_no_longer_supported",self.dist_no_longer_supported)
1091
      # check if we are interessted in dist-upgrade information
1092
      # (we are not by default on dapper)
2146.2.11 by Michael Vogt
initial port from gconf -> gsettings, this needs some cleanup in the naming still
1093
      if (self.options.check_dist_upgrades or
2146.2.12 by Michael Vogt
get rid of gconfclient references
1094
          settings.get_boolean("check-dist-upgrades")):
642 by Michael Vogt
* UpdateManager/UpdateManager.py:
1095
          self.meta.connect("new_dist_available",self.new_dist_available)
1096
      
1097
234 by Michael Vogt
* add "--devel-release" as option
1098
  def main(self, options):
642 by Michael Vogt
* UpdateManager/UpdateManager.py:
1099
    self.options = options
1100
1101
    # check for new distributin information
1102
    self.check_metarelease()
1103
2119.1.1 by Robert Roth
Porting to PyGI
1104
    while Gtk.events_pending():
1105
      Gtk.main_iteration()
10 by Michael Vogt
* code cleanup, make it all more structured
1106
1870 by Michael Vogt
remove a bunch of with ExecutionTime and move it out to the cache
1107
    self.fillstore()
1875.1.8 by Mohamed Amine IL Idrissi
Fixed a bunch of things at mvo's request.
1108
    self.alert_watcher.check_alert_state()
2119.1.1 by Robert Roth
Porting to PyGI
1109
    Gtk.main()