This file is indexed.

/usr/share/gdebi/GDebi/GDebiKDE.py is in gdebi-kde 0.9.5.5+nmu1.

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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
# -*- coding: utf-8 -*-
#
# Copyright (c) 2005-2007 Martin Böhm
# Copyright (c) 2008-2009 Canonical Ltd
#
# AUTHOR:
# Martin Böhm <martin.bohm@ubuntu.com>
#
# This file is part of GDebi
#
# GDebi 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.
#
# GDebi 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/>.

import logging
import os
import re
import sys


from PyKDE4.kdeui import (
    KApplication,
    KIcon,
    KMessageBox,
    DesktopIcon,
    )
from PyQt4.QtCore import (
    Qt,
    SIGNAL,
    QTimer,
    )
from PyQt4.QtGui import (
    QDialog,
    QHBoxLayout,
    QTextCursor,
    QTextEdit,
    QTextOption,
    )
from PyQt4 import uic

from apt.cache import Cache

import gettext

from .DebPackage import DebPackage
from .GDebiCommon import GDebiCommon, utf8, _
from .KDEAptDialogs import (
    CacheProgressAdapter,
    KDEDpkgInstallProgress,
    KDEFetchProgressAdapter,
    KDEInstallProgressAdapter,
    )


def __(catalog,str):
    return utf8(gettext.dgettext(catalog, str))

def loadUi(file, parent):
    """load local file if possible else use installed file"""
    if os.path.exists("data/" + file):
        uic.loadUi("data/" + file, parent)
    else:
        uic.loadUi("/usr/share/gdebi/" + file, parent)

class DumbTerminal(QTextEdit):
    """ a very dumb terminal """
    def __init__(self, parent_frame):
        """ really dumb terminal with simple editing support """
        QTextEdit.__init__(self, parent_frame)
        self.setFontFamily("Monospace")
        self.setFontPointSize(8)
        self.setWordWrapMode(QTextOption.NoWrap)
        self.setUndoRedoEnabled(False)
        self._block = False
        self.connect(self, SIGNAL("cursorPositionChanged(int,int)"), self.onCursorPositionChanged)

    def setInstallProgress(self, installProgress):
        self.installProgress = installProgress

    def insertWithTermCodes(self, text):
        """ support basic terminal codes """
        display_text = ""
        for c in text:
            # \b - backspace
            if c == chr(8):
                self.moveCursor(QTextEdit.MoveBackward, QTextCursor.KeepAnchor)
                self.cut() #self.removeSelectedText()  FIXME
            # \r - is filtered out
            elif c == chr(13):
                pass
            # \a - bell - ignore for now
            elif c == chr(7):
                pass
            else:
                display_text += c
        self.insertPlainText(display_text)

    def keyPressEvent(self, ev):
        """ send (ascii) key events to the pty """
        # no master_fd yet
        if not hasattr(self.installProgress, "master_fd"):
            return
        # special handling for backspace
        if ev.key() == Qt.Key_Backspace:
            #print "sent backspace"
            os.write(self.installProgress.master_fd, chr(8))
            return
        # do nothing for events like "shift"
        if not ev.text():
            return
        # now sent the key event to the termianl as utf-8
        os.write(self.installProgress.master_fd, ev.text().toUtf8())

    def onCursorPositionChanged(self, x, y):
        """ helper that ensures that the cursor is always at the end """
        if self._block:
            return
        # block signals so that we do not run into a recursion
        self._block = True
        #para = self.paragraphs() - 1
        #pos = self.paragraphLength(para)
        self.moveCursor(QTextCursor.End)
        self._block = False


class GDebiKDEDialog(QDialog):
    """Our main user interface, load from UI file"""
    def __init__(self, parent):
        QDialog.__init__(self, parent)
        loadUi("GDebiKDEDialog.ui", self)


class GDebiKDE(GDebiCommon, GDebiKDEDialog):

    def __init__(self, datadir, options, file="", parent=None, name=None,
                 modal=0, fl=0):
        GDebiKDEDialog.__init__(self,parent)
        GDebiCommon.__init__(self,datadir,options,file)
        # load the icon
        self.setWindowIcon(KIcon("application-x-deb"))
        # first, we load all the default descriptions -- pyuic doesn't use
        # gettext as default (FIXME, copy code from language-selector)
        self.textLabel1.setText(_("Package:"))
        self.textLabel1_2.setText(_("Status:"))
        self.detailsButton.setText(_("Details"))
        self.tabWidget2.setTabText(0,_("Description"))
        self.tabWidget2.setTabText(1,_("Details"))
        self.tabWidget2.setTabText(2,_("Included Files"))
        self.cancelButton.setText(__("kdelibs","&Cancel"))
        self.installButton.setText(_("&Install Package"))
        self.downloadButton.setText(_("&Download Package"))
        self.DetailsVersionLabel.setText(_("<b>Version:</b>"))
        self.DetailsMaintainerLabel.setText(_("<b>Maintainer:</b>"))
        self.DetailsPriorityLabel.setText(_("<b>Priority:</b>"))
        self.DetailsSectionLabel.setText(_("<b>Section:</b>"))
        self.DetailsSizeLabel.setText(_("<b>Size:</b>"))
        # translation finished
        self.setDisabled(True)
        self.PackageProgressBar.setEnabled(True)
        self.detailsButton.hide()
        self.downloadButton.hide()
        self.installButton.setIcon(KIcon("dialog-ok"))
        self.cancelButton.setIcon(KIcon("dialog-cancel"))
        self.show()
        self.kapp = KApplication.kApplication() #incidently, this stops it crashing on quit, no idea why, jriddell
        self.kapp.processEvents() #run because openCache takes a while to do its thing
        self.cprogress = CacheProgressAdapter(self.PackageProgressBar)
        if not self.openCache():
            KMessageBox.error(self, '<b>' + self.error_header + '</b><br>' + self.error_body,
                self.error_header)
            sys.exit(1)
        # try to open the file
        if file != "" and os.path.exists(file):
            self.open(file)
        else:
            header = _("The package file does not exist")
            body = _("A nonexistent file has been selected for installation. Please select an existing .deb package file.")
            KMessageBox.error(self, '<b>' + header + '</b><br>' + body, header)
            sys.exit(1)

        self.setEnabled(True)
        self.PackageProgressBar.hide()
        self.connect(self.cancelButton, SIGNAL("clicked()"), self.cancelButtonClicked)
        self.connect(self.installButton, SIGNAL("clicked()"), self.installButtonClicked)
        self.connect(self.downloadButton, SIGNAL("clicked()"), self.downloadButtonClicked)
        self.connect(self.detailsButton, SIGNAL("clicked()"), self.detailsButtonClicked)

    def open(self, file, downloaded=False):
        """ load the .deb file """
        res = GDebiCommon.open(self, file, downloaded)
        if res == False:
            KMessageBox.error(self, '<b>' + self.error_header + '</b><br>' + self.error_body, self.error_header)
            return False

        # set name
        self.setWindowTitle(_("Package Installer - %s") % self._deb.pkgname)
        self.textLabel1_3.setText(self._deb.pkgname)

        # set description
        buf = self.DecriptionEdit
        try:
            long_desc = ""
            raw_desc = str.splitlines(utf8(self._deb["Description"]))
            # append a newline to the summary in the first line
            summary = raw_desc[0]
            raw_desc[0] = ""
            long_desc = "%s\n" % summary
            for line in raw_desc:
                tmp = str.strip(line)
                if tmp == ".":
                    long_desc += "\n"
                else:
                    long_desc += tmp + "\n"
            # do some regular expression magic on the description
            # Add a newline before each bullet
            p = re.compile(r'^(\s|\t)*(\*|0|-)',re.MULTILINE)
            long_desc = p.sub('\n*', long_desc)
            # add the <b> tag to the first line
            long_desc = re.sub(r'\n','</b>\n',long_desc,1)
            # replace all newlines by spaces
            p = re.compile(r'\n', re.MULTILINE)
            long_desc = p.sub(" ", long_desc)
            # replace all multiple spaces by
            # paragraph tags
            p = re.compile(r'\s\s+', re.MULTILINE)
            long_desc = p.sub("</p><p>", long_desc)
            # add the remaining tags
            long_desc = '<p><b>' + long_desc + '</p>'
            # write the descr string to the buffer
            buf.setText(long_desc)
        except KeyError:
            buf.setText(_("No description is available"))

        # check deps
        if not self._deb.check():
            self.installButton.setEnabled(False)
            self.textLabel1_3_2.setText(utf8("<font color=\"#ff0000\"> Error: " + self._deb._failure_string + "</font>"))
            self.detailsButton.hide()
            return False

        # check provides
        provides = self.compareProvides()
        if provides:
            self.installButton.setEnabled(False)
            self.textLabel1_3_2.setText(utf8("<font color=\"#ff0000\"> Error: no longer provides " + ", ".join(provides) + "</font>"))    
            return False

        # set version_info_{msg,title} strings
        self.compareDebWithCache()

        version_status = self._deb.compare_to_version_in_cache(use_installed=False)
        if (version_status in (DebPackage.VERSION_SAME, DebPackage.VERSION_OUTDATED)):
            if not self._deb.downloaded:
                self.downloadButton.show()

        if self._deb.compare_to_version_in_cache() == DebPackage.VERSION_SAME:
            #self.textLabel1_3_2.setText(_("Same version is already installed"))
            self.installButton.setText(_("&Reinstall Package"))
            self.installButton.setIcon(KIcon("view-refresh"))
            #TODO
            #self.button_install.grab_default()
            #self.button_install.set_sensitive(True)
            #self.button_details.hide()

        # load changes into (self.install, self.remove, self.unauthenticated)
        self.get_changes()

        if self.version_info_title != "" and self.version_info_msg != "":
            self.infoIcon.setPixmap(DesktopIcon("dialog-information"))
            self.infoBox.setText(self.version_info_title + '\n' + self.version_info_msg)

        if len(self.remove) == len(self.install) == 0:
            pass # handled by common core
        else:
            self.detailsButton.show()

        self.textLabel1_3_2.setText(self.deps)
        # set various status bits
        self.DetailsVersion.setText(self._deb["Version"])
        self.DetailsMaintainer.setText(utf8(self._deb["Maintainer"]))
        self.DetailsPriority.setText(self._deb["Priority"])
        self.DetailsSection.setText(utf8(self._deb["Section"]))
        self.DetailsSize.setText(self._deb["Installed-Size"] + " KiB")

        # set filelist
        buf = self.IncFilesEdit
        buf.setText("\n".join(self._deb.filelist))

        if not self._deb.check():
            self.installButton.setText(_("&Install Package"))

        if self._deb.compare_to_version_in_cache() == DebPackage.VERSION_SAME:
            self.installButton.setText(_("Re&install Package"))

    def cancelButtonClicked(self):
        self.close()

    def detailsButtonClicked(self):
        changedList = list()
        (install, remove, unauthenticated) = self._deb.required_changes
        for i in install:
            changedList.append(_("To be installed: %s") % i)
        for r in remove:
            changedList.append(_("To be removed: %s") % r)

        KMessageBox.informationList(
            self,
            _("<b>To install the following changes are required:</b>"),
            changedList, _("Details"))

    def installButtonClicked(self):
        # if not root, start a new instance
        if os.getuid() != 0:
            if os.path.exists("gdebi-kde"):
                executable = os.path.curdir + "/gdebi-kde"
            else:
                executable = "/usr/bin/gdebi-kde"
            su_cmd = "/usr/bin/kdesudo"
            if not os.access(su_cmd, os.X_OK):
                su_cmd = "/usr/lib/kde4/libexec/kdesu"
            os.execl(su_cmd, os.path.basename(su_cmd), executable, "--", "-n", self._deb.filename)
            self.kapp.exit()

        if not self.try_acquire_lock():
            KMessageBox.error(self, '<b>' + self.error_header + '</b><br>' + self.error_body, self.error_header)
            return False
        if not self.try_acquire_lock():
            KMessageBox.error(self, '<b>' + self.error_header + '</b><br>' + self.error_body, self.error_header)
            return False
        # set the window as disabled
        self.setDisabled(True)
        self.installDialog = GDebiKDEInstall(self)
        self.installDialog.show()

        # FIXME: use the new python-apt acquire interface here,
        # or rather use it in the apt module and raise exception
        # when stuff goes wrong!
        if len(self.install) > 0 or len(self.remove) > 0:
            #if not self.acquire_lock():
            if not self.acquire_lock():
                #self.show_alert(Gtk.MessageType.ERROR, self.error_header, self.error_body)
                KMessageBox.sorry(self, '<b>' + self.error_header + '</b><br>' + self.error_body, self.error_header)
                return False
            fprogress = KDEFetchProgressAdapter(self.installDialog.installationProgress,
                                                self.installDialog.installingLabel,
                                                self.installDialog)
            iprogress = KDEInstallProgressAdapter(self.installDialog.installationProgress,
                                                  self.installDialog.installingLabel,
                                                  self.installDialog)
            self.installDialog.konsole.setInstallProgress(iprogress)
            #errMsg = None
            try:
                res = self._cache.commit(fprogress,iprogress)
            except IOError as msg:
                res = False
                #errMsg = "%s" % msg
                header = _("Could not download all required files")
                body = _("Please check your internet connection or "
                            "installation medium, or make sure your "
                            "APT cache is up-to-date.")
            except SystemError as msg:
                logging.warning("error: %s" % msg)
                res = False
                header = _("Could not install all dependencies")
                body = _("Usually this is related to an error of the "
                        "software distributor. See the terminal window for "
                        "more details.")
            if not res:
                #print "something bad happend"
                self.errorReport = KMessageBox.error(self, header + "<br>" + body, header)
                return

        # install the package itself
        #self.label_action.set_markup("<b><big>"+_("Installing package file")+"</big></b>")
        dprogress = KDEDpkgInstallProgress(self._deb.filename,
                                             self.installDialog.installingLabel,
                                             self.installDialog.installationProgress,
                                             self.installDialog.konsole, self.installDialog)
        dprogress.commit()
        #self.label_action.set_markup("<b><big>"+_("Package installed")+"</big></b>")
        # show the button
        #self.button_deb_install_close.set_sensitive(True)
        #self.button_deb_install_close.grab_default()
        self.installDialog.setWindowTitle(_("Installation finished"))
        if dprogress.exitstatus == 0:
            self.installDialog.installingLabel.setText(_("<b>" + "Package '%s' was installed" + "</b>") % self._deb.pkgname)
        else:
            self.installDialog.installingLabel.setText("<b>"+_("Failed to install package '%s'") % os.path.basename(self._deb.filename)+"</b>")
            self.installDialog.konsoleFrame.show()
        #self.statusbar_main.push(self.context,_("Installation complete"))
        # FIXME: Doesn't stop notifying
        #self.window_main.set_property("urgency-hint", 1)

        # reopen the cache, reread the file, FIXME: add progress reporting
        #self._cache = Cache(self.cprogress)
        self._cache = Cache()
        if self._cache._depcache.broken_count > 0:
            header = _("Failed to completely install all dependencies")
            text = _("To fix this run 'sudo apt-get install -f' in a "
                         "terminal window.")
            self.errorReport = KMessageBox.error(self, header + text, header)
            sys.exit(1)

    def downloadButtonClicked(self):
        if self.download_package():
            self.downloadButton.hide()

class GDebiKDEInstall(QDialog):
    def __init__(self, parent):
        QDialog.__init__(self, parent)
        loadUi("GDebiKDEInstallDialog.ui", self)
        self.setWindowTitle(_("Installing"))
        self.showDetailsButton.setText(__("libept","Show Details")) #FIXME check i18n
        self.closeButton.setText(__("kdelibs","&Close"))
        self.showDetailsButton.setIcon(KIcon("utilities-terminal"))
        self.closeButton.setIcon(KIcon("window-close"))
        self.closeButton.setEnabled(False)
        self.closeButton.setVisible(False)
        self.parent = parent
        self.konsole = None
        self.konsoleFrameLayout = QHBoxLayout(self.konsoleFrame)
        self.konsoleFrame.hide()
        self.newKonsole()
        kapp = KApplication.kApplication()
        kapp.processEvents()

    def newKonsole(self):
        self.konsole = DumbTerminal(self.konsoleFrame)
        self.konsoleFrame.setMinimumSize(500, 400)
        self.konsoleFrameLayout.addWidget(self.konsole)

    def showTerminal(self):
        if self.konsoleFrame.isVisible():
            self.konsoleFrame.hide()
            self.showDetailsButton.setText(__("libept","Show Details"))
            QTimer.singleShot(1, self.changeSize)
        else:
            self.konsoleFrame.show()
            self.showDetailsButton.setText(__("libept","Hide Details"))

    def changeSize(self):
        self.resize(self.minimumSize())

    def closeButtonClicked(self):
        self.close()

    def closeEvent(self, event):
        self.close()

    def close(self):
        self.accept()
        KApplication.kApplication().exit()