2
# check-new-release-gtk - this is called periodically in the background
3
# (currently by update-notifier every 48h) to
4
# gather information about new releases of Ubuntu
5
# or to nag about no longer supported versions
7
# Copyright (c) 2010,2011 Canonical
9
# Author: Michael Vogt <mvo@ubuntu.com>
11
# This program is free software; you can redistribute it and/or
12
# modify it under the terms of the GNU General Public License as
13
# published by the Free Software Foundation; either version 2 of the
14
# License, or (at your option) any later version.
16
# This program is distributed in the hope that it will be useful,
17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
# GNU General Public License for more details.
21
# You should have received a copy of the GNU General Public License
22
# along with this program; if not, write to the Free Software
23
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
26
from __future__ import print_function
28
from gi.repository import Gio
29
from gi.repository import GLib
30
from gi.repository import Gtk
39
from optparse import OptionParser
41
from UpdateManager.Core.utils import init_proxy
43
from DistUpgrade.DistUpgradeFetcher import DistUpgradeFetcherGtk
44
from UpdateManager.MetaReleaseGObject import MetaRelease
45
from DistUpgrade.SimpleGtk3builderApp import SimpleGtkbuilderApp
47
#FIXME: Workaround a bug in optparser which doesn't handle unicode/str
48
# correctly, see http://bugs.python.org/issue4391
49
# Should be resolved by Python3
50
gettext.bindtextdomain("ubuntu-release-upgrader", "/usr/share/locale")
51
gettext.textdomain("ubuntu-release-upgrader")
52
translation = gettext.translation("ubuntu-release-upgrader", fallback=True)
53
if sys.version >= '3':
54
_ = translation.gettext
56
_ = translation.ugettext
58
# overwrite default upgrade fetcher and make it not show the
59
# release notes by default
60
class DistUpgradeFetcher(DistUpgradeFetcherGtk):
61
def showReleaseNotes(self):
66
class CheckNewReleaseGtk(SimpleGtkbuilderApp):
67
""" Gtk version of the release notes check/download """
69
# the timeout until we give up
72
def __init__(self, options):
73
self.options = options
74
self.datadir = options.datadir
76
logging.debug("running with devel=%s proposed=%s" % (
77
options.devel_release, options.proposed_release))
78
m = MetaRelease(useDevelopmentRelease=options.devel_release,
79
useProposed=options.proposed_release)
80
m.connect("new-dist-available", self.new_dist_available)
81
GLib.timeout_add_seconds(self.FETCH_TIMEOUT, self.timeout, None)
83
def _run_dialog(self, dialog):
85
window.set_title(_("Software Updater"))
86
window.set_icon_name("system-software-update")
87
window.set_position(Gtk.WindowPosition.CENTER)
88
window.set_resizable(False)
95
def new_dist_available(self, meta_release, new_dist):
96
logging.debug("new_dist_available: %s" % new_dist)
97
self.new_dist = new_dist
98
client = Gio.Settings.new("com.ubuntu.update-manager")
99
ignore_dist = client.get_string("check-new-release-ignore")
100
# only honor the ignore list if the distro is still supported, otherwise
102
if (ignore_dist == new_dist.name and
103
meta_release.no_longer_supported is None):
104
logging.warning("found new dist '%s' but it is on the ignore list" % new_dist.name)
107
# show alert on unsupported distros
108
if meta_release.no_longer_supported is not None:
109
subprocess.call(['update-manager', '--no-update'])
113
self.window_main.set_title(_("Ubuntu %(version)s Upgrade Available") % {'version': new_dist.version})
114
self.window_main.show()
117
self.window_main.destroy()
121
SimpleGtkbuilderApp.__init__(self, self.datadir+"/gtkbuilder/UpgradePromptDialog.ui", "ubuntu-release-upgrader")
123
def on_button_upgrade_now_clicked(self, button):
124
logging.debug("upgrade now")
126
if options.devel_release:
127
extra_args += ["--devel-release"]
128
if options.proposed_release:
129
extra_args += ["--proposed"]
130
os.execv("/usr/bin/do-release-upgrade",
131
["do-release-upgrade",
132
"--frontend=DistUpgradeViewGtk3"] + extra_args)
134
def on_button_ask_me_later_clicked(self, button):
135
logging.debug("ask me later")
136
# check again in a week
137
next_check = time.time() + 7*24*60*60
138
client = Gio.Settings("com.ubuntu.update-notifier")
139
client.set_uint("release-check-time", int(next_check))
142
def on_button_dont_upgrade_clicked(self, button):
143
#print("don't upgrade")
144
s = _("You have declined the upgrade to Ubuntu %s") % self.new_dist.version
145
self.dialog_really_do_not_upgrade.set_markup("<b>%s</b>" % s)
146
if self.dialog_really_do_not_upgrade.run() == Gtk.ResponseType.OK:
147
client = Gio.Settings("com.ubuntu.update-manager")
148
client.set_string("check-new-release-ignore", self.new_dist.name)
151
def on_linkbutton_release_notes_clicked(self, linkbutton):
152
# gtk will do the right thing if uri is set
155
def window_delete_event_cb(self, window, event):
158
def timeout(self, user_data):
159
if self.new_dist is None:
160
logging.warning("timeout reached, exiting")
163
if __name__ == "__main__":
165
Gtk.init_check(sys.argv)
168
locale.setlocale(locale.LC_ALL, "")
174
parser = OptionParser()
175
parser.add_option ("-d", "--devel-release", action="store_true",
176
dest="devel_release", default=False,
177
help=_("Check if upgrading to the latest devel release "
179
parser.add_option ("-p", "--proposed", action="store_true",
180
dest="proposed_release", default=False,
181
help=_("Try upgrading to the latest release using "
182
"the upgrader from $distro-proposed"))
183
# mostly useful for development
184
parser.add_option ("", "--datadir", default="/usr/share/ubuntu-release-upgrader")
185
parser.add_option ("", "--debug", action="store_true", default=False,
186
help=_("Add debug output"))
187
(options, args) = parser.parse_args()
189
logging.basicConfig(level=logging.DEBUG)
192
cnr = CheckNewReleaseGtk(options)