This file is indexed.

/usr/lib/python3/dist-packages/DistUpgrade/DistUpgradeFetcherKDE.py is in python3-distupgrade 1:16.04.12.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# DistUpgradeFetcherKDE.py
# -*- Mode: Python; indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
#
#  Copyright (c) 2008 Canonical Ltd
#  Copyright (c) 2014 Harald Sitter <apachelogger@kubuntu.org>
#
#  Author: Jonathan Riddell <jriddell@ubuntu.com>
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License as
#  published by the Free Software Foundation; either version 2 of the
#  License, or (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.

try:
    # 14.04 has a broken pyqt5, so don't even try to import it and require
    # pyqt4.
    # In 14.04 various signals in pyqt5 can not be connected because it thinks
    # the signal does not exist or has an incompatible signature. Since this
    # potentially renders the GUI entirely broken and pyqt5 was not actively
    # used back then it is fair to simply require qt4 on trusty systems.
    from .utils import get_dist
    if get_dist() == 'trusty':
        raise ImportError

    from PyQt5 import uic
    from PyQt5.QtCore import QTranslator, PYQT_VERSION, \
        QLocale, pyqtSlot, QUrl
    from PyQt5.QtGui import QIcon
    from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QMessageBox, \
        QApplication
except ImportError:
    from PyKDE4.kdeui import KIcon, KMessageBox, KStandardGuiItem
    from PyQt4.QtGui import QDialog, QDialogButtonBox, QApplication, QIcon
    from PyQt4.QtCore import PYQT_VERSION
    from PyQt4 import uic

import apt_pkg

from DistUpgrade.DistUpgradeFetcherCore import DistUpgradeFetcherCore
from gettext import gettext as _
from urllib.request import urlopen
from urllib.error import HTTPError
import os

import apt

from .QUrlOpener import QUrlOpener


# TODO: uifile resolution is an utter mess and should be revised globally for
#       both the fetcher and the upgrader GUI.

# TODO: make this a singleton
# We have no globally constructed QApplication available so we need to
# make sure that one is created when needed. Since from a module POV
# this can be happening in any order of the two classes this function takes
# care of it for the classes, the classes only hold a ref to the qapp returned
# to prevent it from getting GC'd, so in essence this is a singleton scoped to
# the longest lifetime of an instance from the Qt GUI. Since the lifetime is
# pretty much equal to the process' one we might as well singleton up.
def _ensureQApplication():
    if not QApplication.instance():
        app = QApplication(["ubuntu-release-upgrader"])
        # Try to load default Qt translations so we don't have to worry about
        # QStandardButton translations.
        # FIXME: make sure we dep on l10n
        translator = QTranslator(app)
        if type(PYQT_VERSION) == int:
            translator.load(QLocale.system(), 'qt', '_',
                            '/usr/share/qt5/translations')
        else:
            translator.load(QLocale.system(), 'qt', '_',
                            '/usr/share/qt4/translations')
        app.installTranslator(translator)
        return app
    return QApplication.instance()


# Qt 5 vs. KDELibs4 compat functions
def _warning(text):
    if type(PYQT_VERSION) == int:
        QMessageBox.warning(None, "", text)
    else:
        KMessageBox.sorry(None, text, "")


def _icon(name):
    if type(PYQT_VERSION) == int:
        return QIcon.fromTheme(name)
    else:
        return KIcon(name)


class DistUpgradeFetcherKDE(DistUpgradeFetcherCore):

    def __init__(self, new_dist, progress, parent, datadir):
        DistUpgradeFetcherCore.__init__(self, new_dist, progress)

        self.app = _ensureQApplication()
        self.app.setWindowIcon(_icon("system-software-update"))

        self.datadir = datadir

        QUrlOpener().setupUrlHandles()

        QApplication.processEvents()

    def error(self, summary, message):
        if type(PYQT_VERSION) == int:
            QMessageBox.critical(None, summary, message)
        else:
            KMessageBox.sorry(None, message, summary)

    def runDistUpgrader(self):
        # now run it with sudo
        if os.getuid() != 0:
            os.execv("/usr/bin/kdesudo",
                     ["kdesudo",
                      self.script + " --frontend=DistUpgradeViewKDE"])
        else:
            os.execv(self.script,
                     [self.script, "--frontend=DistUpgradeViewKDE"] +
                     self.run_options)

    def showReleaseNotes(self):
        # FIXME: care about i18n! (append -$lang or something)
        # TODO:  ^ what is this supposed to mean?
        self.dialog = QDialog()
        uic.loadUi(self.datadir + "/dialog_release_notes.ui", self.dialog)
        upgradeButton = self.dialog.buttonBox.button(QDialogButtonBox.Ok)
        upgradeButton.setText(_("&Upgrade"))
        upgradeButton.setIcon(_icon("dialog-ok"))
        cancelButton = self.dialog.buttonBox.button(QDialogButtonBox.Cancel)
        cancelButton.setText(_("&Cancel"))
        cancelButton.setIcon(_icon("dialog-cancel"))
        self.dialog.setWindowTitle(_("Release Notes"))
        self.dialog.show()
        if self.new_dist.releaseNotesHtmlUri is not None:
            uri = self._expandUri(self.new_dist.releaseNotesHtmlUri)
            # download/display the release notes
            # TODO: add some progress reporting here
            result = None
            try:
                release_notes = urlopen(uri)
                notes = release_notes.read().decode("UTF-8", "replace")
                self.dialog.scrolled_notes.setText(notes)
                result = self.dialog.exec_()
            except HTTPError:
                primary = "<span weight=\"bold\" size=\"larger\">%s</span>" % \
                          _("Could not find the release notes")
                secondary = _("The server may be overloaded. ")
                _warning(primary + "<br />" + secondary)
            except IOError:
                primary = "<span weight=\"bold\" size=\"larger\">%s</span>" % \
                          _("Could not download the release notes")
                secondary = _("Please check your internet connection.")
                _warning(primary + "<br />" + secondary)
            # user clicked cancel
            if result == QDialog.Accepted:
                return True
        return False

    # FIXME: largely code copy from ReleaseNotesViewer which imports GTK.
    @pyqtSlot(QUrl)
    def openUrl(self, url):
        url = url.toString()
        import subprocess
        """Open the specified URL in a browser"""
        # Find an appropiate browser
        if os.path.exists("/usr/bin/kde-open"):
            command = ["kde-open", url]
        elif os.path.exists("/usr/bin/xdg-open"):
            command = ["xdg-open", url]
        elif os.path.exists("/usr/bin/exo-open"):
            command = ["exo-open", url]
        elif os.path.exists('/usr/bin/gnome-open'):
            command = ['gnome-open', url]
        else:
            command = ['x-www-browser', url]
        # Avoid to run the browser as user root
        if os.getuid() == 0 and 'SUDO_USER' in os.environ:
            command = ['sudo', '-u', os.environ['SUDO_USER']] + command
        subprocess.Popen(command)


class KDEAcquireProgressAdapter(apt.progress.base.AcquireProgress):
    def __init__(self, parent, datadir, label):
        self.app = _ensureQApplication()
        self.dialog = QDialog()

        uiFile = os.path.join(datadir, "fetch-progress.ui")
        uic.loadUi(uiFile, self.dialog)
        self.dialog.setWindowTitle(_("Upgrade"))
        self.dialog.installingLabel.setText(label)
        self.dialog.buttonBox.rejected.connect(self.abort)

        # This variable is used as return value for AcquireProgress pulses.
        # Setting it to False will abort the Acquire and consequently the
        # entire fetcher.
        self._continue = True

        QApplication.processEvents()

    def abort(self):
        self._continue = False

    def start(self):
        self.dialog.installingLabel.setText(
            _("Downloading additional package files..."))
        self.dialog.installationProgress.setValue(0)
        self.dialog.show()

    def stop(self):
        self.dialog.hide()

    def pulse(self, owner):
        apt.progress.base.AcquireProgress.pulse(self, owner)
        self.dialog.installationProgress.setValue(
            (self.current_bytes + self.current_items) /
            float(self.total_bytes + self.total_items) * 100)
        current_item = self.current_items + 1
        if current_item > self.total_items:
            current_item = self.total_items
        label_text = _("Downloading additional package files...")
        if self.current_cps > 0:
            label_text += _("File %s of %s at %sB/s") % (
                self.current_items, self.total_items,
                apt_pkg.size_to_str(self.current_cps))
        else:
            label_text += _("File %s of %s") % (
                self.current_items, self.total_items)
        self.dialog.installingLabel.setText(label_text)
        QApplication.processEvents()
        return self._continue

    def mediaChange(self, medium, drive):
        msg = _("Please insert '%s' into the drive '%s'") % (medium, drive)
        if type(PYQT_VERSION) == int:
            change = QMessageBox.question(None, _("Media Change"), msg,
                                          QMessageBox.Ok, QMessageBox.Cancel)
            if change == QMessageBox.Ok:
                return True
        else:
            change = KMessageBox.questionYesNo(None, _("Media Change"),
                                               _("Media Change") + "<br>" +
                                               msg, KStandardGuiItem.ok(),
                                               KStandardGuiItem.cancel())
            if change == KMessageBox.Yes:
                return True
        return False