~ubuntu-core-dev/ubuntu-release-upgrader/trunk

« back to all changes in this revision

Viewing changes to check-new-release-gtk

  • Committer: Balint Reczey
  • Date: 2019-12-17 20:29:55 UTC
  • Revision ID: balint.reczey@canonical.com-20191217202955-nqe4xz2c54s60y59
Moved to git at https://git.launchpad.net/ubuntu-release-upgrader

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python3
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
6
 
#  
7
 
#  Copyright (c) 2010,2011 Canonical
8
 
#  
9
 
#  Author: Michael Vogt <mvo@ubuntu.com>
10
 
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.
15
 
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.
20
 
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
24
 
#  USA
25
 
 
26
 
from __future__ import print_function
27
 
 
28
 
from gi.repository import Gio
29
 
from gi.repository import GLib
30
 
from gi.repository import Gtk
31
 
import locale
32
 
import logging
33
 
import os
34
 
import subprocess
35
 
import sys
36
 
import time
37
 
 
38
 
import gettext
39
 
from optparse import OptionParser
40
 
 
41
 
from UpdateManager.Core.utils import init_proxy
42
 
 
43
 
from DistUpgrade.DistUpgradeFetcher import DistUpgradeFetcherGtk
44
 
from UpdateManager.MetaReleaseGObject import MetaRelease
45
 
from DistUpgrade.SimpleGtk3builderApp import SimpleGtkbuilderApp
46
 
 
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
55
 
else:
56
 
  _ = translation.ugettext
57
 
 
58
 
# overwrite default upgrade fetcher and make it not show the
59
 
# release notes by default
60
 
class DistUpgradeFetcher(DistUpgradeFetcherGtk):
61
 
    def showReleaseNotes(self):
62
 
      # nothing to do
63
 
      return True
64
 
 
65
 
 
66
 
class CheckNewReleaseGtk(SimpleGtkbuilderApp):
67
 
  """ Gtk version of the release notes check/download """
68
 
 
69
 
  # the timeout until we give up
70
 
  FETCH_TIMEOUT = 20
71
 
 
72
 
  def __init__(self, options):
73
 
    self.options = options
74
 
    self.datadir = options.datadir
75
 
    self.new_dist = None
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)
82
 
 
83
 
  def _run_dialog(self, dialog):
84
 
    window = Gtk.Window()
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)
89
 
 
90
 
    window.add(dialog)
91
 
    dialog.start()
92
 
    window.show_all()
93
 
    Gtk.main()
94
 
 
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
101
 
    # go into nag mode
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)
105
 
        sys.exit()
106
 
 
107
 
    # show alert on unsupported distros
108
 
    if meta_release.no_longer_supported is not None:
109
 
        subprocess.call(['update-manager', '--no-update'])
110
 
        Gtk.main_quit()
111
 
    else:
112
 
        self.build_ui()
113
 
        self.window_main.set_title(_("Ubuntu %(version)s Upgrade Available") % {'version': new_dist.version})
114
 
        self.window_main.show()
115
 
 
116
 
  def close(self):
117
 
    self.window_main.destroy()
118
 
    Gtk.main_quit()
119
 
 
120
 
  def build_ui(self):
121
 
    SimpleGtkbuilderApp.__init__(self, self.datadir+"/gtkbuilder/UpgradePromptDialog.ui", "ubuntu-release-upgrader")
122
 
 
123
 
  def on_button_upgrade_now_clicked(self, button):
124
 
    logging.debug("upgrade now")
125
 
    extra_args = []
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)
133
 
 
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))
140
 
    Gtk.main_quit()
141
 
 
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)
149
 
    Gtk.main_quit()
150
 
 
151
 
  def on_linkbutton_release_notes_clicked(self, linkbutton):
152
 
    # gtk will do the right thing if uri is set
153
 
    pass
154
 
 
155
 
  def window_delete_event_cb(self, window, event):
156
 
    Gtk.main_quit()
157
 
 
158
 
  def timeout(self, user_data):
159
 
    if self.new_dist is None:
160
 
      logging.warning("timeout reached, exiting")
161
 
      Gtk.main_quit()
162
 
 
163
 
if __name__ == "__main__":
164
 
 
165
 
  Gtk.init_check(sys.argv)
166
 
 
167
 
  try:
168
 
    locale.setlocale(locale.LC_ALL, "")
169
 
  except:
170
 
    pass
171
 
 
172
 
  init_proxy()
173
 
 
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 "
178
 
                          "is possible"))
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()
188
 
  if options.debug:
189
 
      logging.basicConfig(level=logging.DEBUG)
190
 
 
191
 
  # create object
192
 
  cnr = CheckNewReleaseGtk(options)
193
 
 
194
 
  Gtk.main()
195