1
# DistUpgradeFetcherKDE.py
2
# -*- Mode: Python; indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
4
# Copyright (c) 2008 Canonical Ltd
6
# Author: Jonathan Riddell <jriddell@ubuntu.com>
8
# This program is free software; you can redistribute it and/or
9
# modify it under the terms of the GNU General Public License as
10
# published by the Free Software Foundation; either version 2 of the
11
# License, or (at your option) any later version.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
18
# You should have received a copy of the GNU General Public License
19
# along with this program. If not, see <http://www.gnu.org/licenses/>.
21
from __future__ import absolute_import
23
from PyKDE4.kdecore import ki18n, KAboutData, KCmdLineOptions, KCmdLineArgs
24
from PyKDE4.kdeui import KIcon, KMessageBox, KApplication, KStandardGuiItem
25
from PyQt4.QtCore import QDir, QTimer
26
from PyQt4.QtGui import QDialog, QDialogButtonBox
32
from .Core.utils import inhibit_sleep, allow_sleep
33
from .Core.DistUpgradeFetcherCore import DistUpgradeFetcherCore
34
from gettext import gettext as _
36
from urllib.request import urlopen
37
from urllib.error import HTTPError
39
from urllib2 import urlopen, HTTPError
42
from .Core.MetaRelease import MetaReleaseCore
47
class DistUpgradeFetcherKDE(DistUpgradeFetcherCore):
48
"""A small application run by Adept to download, verify
49
and run the dist-upgrade tool"""
51
def __init__(self, useDevelopmentRelease=False, useProposed=False):
52
self.useDevelopmentRelease = useDevelopmentRelease
53
self.useProposed = useProposed
54
metaRelease = MetaReleaseCore(useDevelopmentRelease, useProposed)
55
while metaRelease.downloading:
57
if metaRelease.new_dist is None and __name__ == "__main__":
59
elif metaRelease.new_dist is None:
62
self.progressDialogue = QDialog()
63
if os.path.exists("fetch-progress.ui"):
64
self.APPDIR = QDir.currentPath()
66
self.APPDIR = "/usr/share/update-manager"
68
uic.loadUi(self.APPDIR + "/fetch-progress.ui", self.progressDialogue)
69
self.progressDialogue.setWindowIcon(KIcon("system-software-update"))
70
self.progressDialogue.setWindowTitle(_("Upgrade"))
71
self.progress = KDEAcquireProgressAdapter(
72
self.progressDialogue.installationProgress,
73
self.progressDialogue.installingLabel,
75
DistUpgradeFetcherCore.__init__(self, metaRelease.new_dist,
78
def error(self, summary, message):
79
KMessageBox.sorry(None, message, summary)
81
def runDistUpgrader(self):
83
# now run it with sudo
85
os.execv("/usr/bin/kdesudo",
87
self.script + " --frontend=DistUpgradeViewKDE"])
90
[self.script] + ["--frontend=DistUpgradeViewKDE"] +
92
# we shouldn't come to this point, but if we do, undo our
96
def showReleaseNotes(self):
97
# FIXME: care about i18n! (append -$lang or something)
98
self.dialogue = QDialog()
99
uic.loadUi(self.APPDIR + "/dialog_release_notes.ui", self.dialogue)
100
upgradeButton = self.dialogue.buttonBox.button(QDialogButtonBox.Ok)
101
upgradeButton.setText(_("Upgrade"))
102
upgradeButton.setIcon(KIcon("dialog-ok"))
103
cancelButton = self.dialogue.buttonBox.button(QDialogButtonBox.Cancel)
104
cancelButton.setIcon(KIcon("dialog-cancel"))
105
self.dialogue.setWindowTitle(_("Release Notes"))
107
if self.new_dist.releaseNotesURI is not None:
108
uri = self._expandUri(self.new_dist.releaseNotesURI)
109
# download/display the release notes
110
# FIXME: add some progress reporting here
113
release_notes = urlopen(uri)
114
notes = release_notes.read().decode("UTF-8", "replace")
115
self.dialogue.scrolled_notes.setText(notes)
116
result = self.dialogue.exec_()
118
primary = "<span weight=\"bold\" size=\"larger\">%s</span>" % \
119
_("Could not find the release notes")
120
secondary = _("The server may be overloaded. ")
121
KMessageBox.sorry(None, primary + "<br />" + secondary, "")
123
primary = "<span weight=\"bold\" size=\"larger\">%s</span>" % \
124
_("Could not download the release notes")
125
secondary = _("Please check your internet connection.")
126
KMessageBox.sorry(None, primary + "<br />" + secondary, "")
127
# user clicked cancel
128
if result == QDialog.Accepted:
129
self.progressDialogue.show()
131
if __name__ == "__main__":
132
KApplication.kApplication().exit(1)
133
if self.useDevelopmentRelease or self.useProposed:
134
#FIXME why does KApplication.kApplication().exit() crash but
140
class KDEAcquireProgressAdapter(apt.progress.base.AcquireProgress):
141
def __init__(self, progress, label, parent):
142
self.progress = progress
147
self.label.setText(_("Downloading additional package files..."))
148
self.progress.setValue(0)
153
def pulse(self, owner):
154
apt.progress.base.AcquireProgress.pulse(self, owner)
155
self.progress.setValue((self.current_bytes + self.current_items) /
156
float(self.total_bytes + self.total_items))
157
current_item = self.current_items + 1
158
if current_item > self.total_items:
159
current_item = self.total_items
160
label_text = _("Downloading additional package files...")
161
if self.current_cps > 0:
162
label_text += _("File %s of %s at %sB/s") % (
163
self.current_items, self.total_items,
164
apt_pkg.size_to_str(self.current_cps))
166
label_text += _("File %s of %s") % (
167
self.current_items, self.total_items)
168
self.label.setText(label_text)
169
KApplication.kApplication().processEvents()
172
def mediaChange(self, medium, drive):
173
msg = _("Please insert '%s' into the drive '%s'") % (medium, drive)
174
#change = QMessageBox.question(None, _("Media Change"), msg,
175
# QMessageBox.Ok, QMessageBox.Cancel)
176
change = KMessageBox.questionYesNo(None, _("Media Change"),
177
_("Media Change") + "<br>" + msg,
178
KStandardGuiItem.ok(),
179
KStandardGuiItem.cancel())
180
if change == KMessageBox.Yes:
184
if __name__ == "__main__":
186
appName = "dist-upgrade-fetcher"
188
programName = ki18n("Dist Upgrade Fetcher")
190
description = ki18n("Dist Upgrade Fetcher")
191
license = KAboutData.License_GPL
192
copyright = ki18n("(c) 2008 Canonical Ltd")
194
homePage = "https://launchpad.net/update-manager"
197
aboutData = KAboutData(appName, catalog, programName, version, description,
198
license, copyright, text, homePage, bugEmail)
200
aboutData.addAuthor(ki18n("Jonathan Riddell"), ki18n("Author"))
202
options = KCmdLineOptions()
204
KCmdLineArgs.init(sys.argv, aboutData)
205
KCmdLineArgs.addCmdLineOptions(options)
208
fetcher = DistUpgradeFetcherKDE()
209
QTimer.singleShot(10, fetcher.run)