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

« back to all changes in this revision

Viewing changes to check-new-release-gtk

  • Committer: Michael Terry
  • Date: 2012-05-15 19:43:43 UTC
  • mto: This revision was merged to the branch mainline in revision 2428.
  • Revision ID: michael.terry@canonical.com-20120515194343-tocvo0awttmggie1
update several strings to match the software updater spec; most notably, rename from Update Manager to Software Updater

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
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 GObject
 
30
from gi.repository import Gtk
 
31
import locale
 
32
import logging
 
33
import sys
 
34
import time
 
35
 
 
36
import UpdateManager.GtkProgress
 
37
 
 
38
import gettext
 
39
from optparse import OptionParser
 
40
 
 
41
from DistUpgrade.utils import init_proxy
 
42
 
 
43
from UpdateManager.DistUpgradeFetcher import DistUpgradeFetcherGtk
 
44
from UpdateManager.MetaReleaseGObject import MetaRelease
 
45
from UpdateManager.SimpleGtk3builderApp import SimpleGtkbuilderApp
 
46
 
 
47
from gettext import gettext as _
 
48
 
 
49
GObject.threads_init()
 
50
 
 
51
# overwrite default upgrade fetcher and make it not show the
 
52
# release notes by default
 
53
class DistUpgradeFetcher(DistUpgradeFetcherGtk):
 
54
    def showReleaseNotes(self):
 
55
      # nothing to do
 
56
      return True
 
57
 
 
58
 
 
59
class CheckNewReleaseGtk(SimpleGtkbuilderApp):
 
60
  """ Gtk verson of the release notes check/download """
 
61
 
 
62
  # the timeout until we give up
 
63
  FETCH_TIMEOUT = 20
 
64
 
 
65
  def __init__(self, options):
 
66
    SimpleGtkbuilderApp.__init__(self, options.datadir+"/gtkbuilder/UpgradePromptDialog.ui", "update-manager")
 
67
    self.new_dist = None
 
68
    logging.debug("running with devel=%s proposed=%s" % (
 
69
            options.devel_release, options.proposed_release))
 
70
    m = MetaRelease(useDevelopmentRelease=options.devel_release,
 
71
                    useProposed=options.proposed_release)
 
72
    m.connect("new-dist-available", self.new_dist_available)
 
73
    # useful for testing
 
74
    if options.test_uri:
 
75
        self.build_ui()
 
76
        self.show_uri(options.test_uri)
 
77
    else:
 
78
        GObject.timeout_add_seconds(self.FETCH_TIMEOUT, self.timeout, None)
 
79
 
 
80
  def new_dist_available(self, meta_release, new_dist):
 
81
    logging.debug("new_dist_available: %s" % new_dist)
 
82
    self.new_dist = new_dist
 
83
    client =  Gio.Settings("com.ubuntu.update-manager")
 
84
    ignore_dist = client.get_string("check-new-release-ignore")
 
85
    # only honor the ignore list if the distro is still supported, otherwise
 
86
    # go into nag mode
 
87
    if (ignore_dist == new_dist.name and
 
88
        meta_release.no_longer_supported is None):
 
89
        logging.warn("found new dist '%s' but it is on the ignore list" % new_dist.name)
 
90
        Gtk.main_quit()
 
91
    self.build_ui()
 
92
    self.window_main.set_title(_("Ubuntu %(version)s Upgrade Available") % {'version': new_dist.version})
 
93
    self.linkbutton_release_notes.set_uri(new_dist.releaseNotesURI)
 
94
    html_uri = new_dist.releaseNotesHtmlUri
 
95
    if not html_uri:
 
96
        logging.warn("no ReleaseNotesHtmlUri found")
 
97
        return
 
98
    self.show_uri(html_uri)
 
99
    # show alert on unsupported distros
 
100
    if meta_release.no_longer_supported is not None:
 
101
        from UpdateManager.UpdateManager import show_dist_no_longer_supported_dialog
 
102
        self.window_main.realize()
 
103
        show_dist_no_longer_supported_dialog(self.window_main)
 
104
  
 
105
  def build_ui(self):
 
106
    from gi.repository import WebKit
 
107
    self.webkit_view = WebKit.WebView()
 
108
    self.webkit_view.show()
 
109
    settings = self.webkit_view.get_settings()
 
110
    settings.set_property("enable-plugins", False)
 
111
    # FIXME: do we want to have it in a Gtk.ScrolledWindow ?
 
112
    #self.alignment_webkit_view.add(self.webkit_view)
 
113
    self.scrolledwindow_webkit_view.add(self.webkit_view)
 
114
 
 
115
  def on_button_upgrade_now_clicked(self, button):
 
116
    logging.debug("upgrade now")
 
117
    progress=UpdateManager.GtkProgress.GtkAcquireProgress(self, _("Downloading the release upgrade tool"))
 
118
    fetcher = DistUpgradeFetcher(new_dist=self.new_dist, 
 
119
                                 parent=self,
 
120
                                 progress=progress)
 
121
    res = fetcher.run()
 
122
    res # pyflakes
 
123
 
 
124
  def on_button_ask_me_later_clicked(self, button):
 
125
    logging.debug("ask me later")
 
126
    # check again in a week
 
127
    next_check = time.time() + 7*24*60*60
 
128
    client = Gio.Settings("com.ubuntu.update-notifier")
 
129
    client.set_int("release-check-time", int(next_check))
 
130
    Gtk.main_quit()
 
131
 
 
132
  def on_button_dont_upgrade_clicked(self, button):
 
133
    #print("don't upgrade")
 
134
    s = _("You have declined the upgrade to Ubuntu %s") % self.new_dist.version
 
135
    self.dialog_really_do_not_upgrade.set_markup("<b>%s</b>" % s)
 
136
    if self.dialog_really_do_not_upgrade.run() == Gtk.ResponseType.OK:
 
137
        client = Gio.Settings("com.ubuntu.update-manager")
 
138
        client.set_string("check-new-release-ignore", self.new_dist.name)
 
139
    Gtk.main_quit()
 
140
 
 
141
  def on_linkbutton_release_notes_clicked(self, linkbutton):
 
142
    # gtk will do the right thing if uri is set
 
143
    pass
 
144
 
 
145
  def window_delete_event_cb(self, window, event):
 
146
    Gtk.main_quit()
 
147
 
 
148
  def show_uri(self, uri):
 
149
    logging.debug("using uri '%s'" % uri)
 
150
    self.webkit_view.open(uri)
 
151
    self.webkit_view.connect("load-finished", self._on_load_finished)
 
152
 
 
153
  def _on_load_finished(self, view, frame):
 
154
    self.window_main.show_all()
 
155
    # hide redundant release notes button
 
156
    self.linkbutton_release_notes.hide()
 
157
 
 
158
  def timeout(self, user_data):
 
159
    if self.new_dist is None:
 
160
      logging.warn("timeout reached, exiting")
 
161
      Gtk.main_quit()
 
162
 
 
163
if __name__ == "__main__":
 
164
 
 
165
  Gtk.init_check(sys.argv)
 
166
 
 
167
  gettext.bindtextdomain("update-manager", "/usr/share/locale")
 
168
  gettext.textdomain("update-manager")
 
169
 
 
170
  try:
 
171
    locale.setlocale(locale.LC_ALL, "")
 
172
  except:
 
173
    pass
 
174
 
 
175
  init_proxy()
 
176
 
 
177
  parser = OptionParser()
 
178
  #FIXME: Workaround a bug in optparser which doesn't handle unicode/str
 
179
  #       correctly, see http://bugs.python.org/issue4391
 
180
  #       Shoudl be resolved by Python3
 
181
  enc = locale.getpreferredencoding()
 
182
  parser.add_option ("-d", "--devel-release", action="store_true",
 
183
                     dest="devel_release", default=False,
 
184
                     help=_("Check if upgrading to the latest devel release "
 
185
                          "is possible").decode(enc))
 
186
  parser.add_option ("-p", "--proposed", action="store_true",
 
187
                     dest="proposed_release", default=False,
 
188
                     help=_("Try upgrading to the latest release using "
 
189
                            "the upgrader from $distro-proposed").decode(enc))
 
190
  # mostly useful for development
 
191
  parser.add_option ("", "--datadir", default="/usr/share/update-manager")
 
192
  parser.add_option ("", "--test-uri")
 
193
  parser.add_option ("", "--debug", action="store_true", default=False,
 
194
                     help=_("Add debug output").decode(enc))
 
195
  (options, args) = parser.parse_args()
 
196
 
 
197
  if options.debug:
 
198
      logging.basicConfig(level=logging.DEBUG)
 
199
 
 
200
  # create object
 
201
  cnr = CheckNewReleaseGtk(options)
 
202
 
 
203
  Gtk.main()
 
204