This file is indexed.

/usr/lib/python3/dist-packages/AptUrl/gtk/GtkUI.py is in apturl 0.5.2ubuntu14.

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
from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import GObject
GObject.threads_init()

import os
import sys
import apt_pkg
import subprocess

from AptUrl.UI import AbstractUI
from AptUrl import Helpers
from AptUrl.Helpers import _

from .backend import get_backend


APTURL_UI_FILE = os.environ.get(
    # Set this envar to use a test .ui file.
    'APTURL_UI_FILE',
    # System file to use if the envar is not set.
    '/usr/share/apturl/apturl-gtk.ui'
    )


class GtkUI(AbstractUI):
    def __init__(self):
        Gtk.init_check(sys.argv)
        # create empty dialog
        self.dia_xml = Gtk.Builder()
        self.dia_xml.set_translation_domain("apturl")
        self.dia_xml.add_from_file(APTURL_UI_FILE)
        self.dia = self.dia_xml.get_object('confirmation_dialog')
        self.dia.start_available = self.start_available
        self.dia.start_error = self.start_error
        self.dia.exit = lambda: Gtk.main_quit()
        self.dia.realize()
        self.backend = get_backend(self.dia)

    def start_available(self, cancelled_update=False, error_occurred=False):
        self.dia.set_sensitive(True)
        Gtk.main_quit()

    def start_error(self, is_update_error, header, desc):
        Gtk.main_quit()

    def _action_done(self, backend, action, authorized, success, err_str, err_desc):
        self.dia.set_sensitive(True)
        Gtk.main_quit()

    # generic dialogs
    def _get_dialog(self, dialog_type, summary, msg="",
                    buttons=Gtk.ButtonsType.CLOSE):
        " internal helper for dialog construction "
        d = Gtk.MessageDialog(parent=self.dia,
                              flags=Gtk.DialogFlags.MODAL,
                              type=dialog_type,
                              buttons=buttons)
        d.set_title("")
        d.set_markup("<big><b>%s</b></big>\n\n%s" % (summary, msg))
        d.set_icon(Gtk.IconTheme.get_default().load_icon('package-x-generic', 16, False))
        d.set_keep_above(True)
        d.realize()
        d.get_window().set_functions(Gdk.WMFunction.MOVE)
        return d

    def error(self, summary, msg=""):
        d = self._get_dialog(Gtk.MessageType.ERROR, summary, msg)
        d.run()
        d.destroy()
        return False

    def message(self, summary, msg="", title=""):
        d = self._get_dialog(Gtk.MessageType.INFO, summary, msg)
        d.set_title(title)
        d.run()
        d.destroy()
        return True

    def yesNoQuestion(self, summary, msg, title="", default='no'):
        d = self._get_dialog(Gtk.MessageType.QUESTION, summary, msg,
                             buttons=Gtk.ButtonsType.YES_NO)
        d.set_title(title)
        res = d.run()
        d.destroy()
        if res != Gtk.ResponseType.YES:
            return False
        return True

    def _add_webkit_view(self, html, d):
        from gi.repository import WebKit2
        v = WebKit2.WebView()
        v.load_html(html, "file:/")
        d.get_content_area().pack_start(v, True, True, 0)
        v.set_size_request(400, 200)
        v.show_all()

    # specific dialogs
    def askEnableChannel(self, channel, channel_info_html):
        summary = _("Enable additional software channel")
        msg = _("Do you want to enable the following "
                "software channel: '%s'?") % channel
        d = self._get_dialog(Gtk.MessageType.QUESTION, summary, msg,
                             buttons=Gtk.ButtonsType.YES_NO)
        if channel_info_html:
            try:
                self._add_webkit_view(channel_info_html, d)
            except ImportError:
                pass
        res = d.run()
        d.destroy()
        if res != Gtk.ResponseType.YES:
            return False
        return True

    def doEnableSection(self, sections):
        cmd = ["pkexec",
               "software-properties-gtk",
               "-e", "%s" % ' '.join(sections)]
        try:
            output = subprocess.communicate(
                cmd,
                stdout=subprocess.PIPE,
                universal_newlines=True)
        except (OSError, subprocess.CalledProcessError) as e:
            print("Execution failed: %s" % e, file=sys.stderr)
            return True
        # FIXME: Very ugly, but gksu doesn't return the correct exit states
        if not output.startswith("Enabled the "):
            return False
        return True


    def doEnableChannel(self, channelpath, channelkey):
        cmd = ["pkexec",
               "install", "--mode=644","--owner=0",channelpath,
               apt_pkg.config.find_dir("Dir::Etc::sourceparts")]
        res = subprocess.call(cmd, universal_newlines=True)
        if res != 0:
            return False
        # install the key as well
        if os.path.exists(channelkey):
            cmd = ["pkexec",
                   "apt-key", "add",channelkey]
            res = subprocess.call(cmd, universal_newlines=True)
            if res != 0:
                return False
        return True

    def askInstallPackage(self, package, summary, description, homepage):
        # populate the dialog
        dia = self.dia
        dia_xml = self.dia_xml
        header = _("Install additional software?")
        body = _("Do you want to install package '%s'?") % package
        dia.set_keep_above(True)
        dia.set_title('')
        header_label = dia_xml.get_object('header_label')
        header_label.set_markup("<b><big>%s</big></b>" % header)
        body_label = dia_xml.get_object('body_label')
        body_label.set_label(body)
        description_text_view = dia_xml.get_object('description_text_view')
        tbuf = Gtk.TextBuffer()
        desc = "%s\n\n%s" % (summary, Helpers.format_description(description))
        tbuf.set_text(desc)
        description_text_view.set_buffer(tbuf)
        dia.set_icon(Gtk.IconTheme.get_default().load_icon('package-x-generic', 16, False))

        # check if another package manager is already running
        # FIXME: just checking for the existance of the file is
        #        not sufficient, it need to be tested if it can
        #        be locked via apt_pkg.get_lock()
        #        - but that needs to run as root
        #        - a dbus helper might be the best answer here
        #args = (update_button_status, dia_xml.get_object("yes_button"),
        #    dia_xml.get_object("infolabel"))
        #args[0](*args[1:])
        #timer_id = GObject.timeout_add(750, *args )

        # show the dialog
        res = dia.run()
        #GObject.source_remove(timer_id)
        if res != Gtk.ResponseType.YES:
            dia.hide()
            return False

        # don't set on-top while installing
        dia.set_keep_above(False)
        return True

    # progress etc
    def doUpdate(self):
        self.backend.update()
        self.dia.set_sensitive(False)
        Gtk.main()

    def doInstall(self, apturl):
        self.backend.commit([apturl.package], [], False)
        self.dia.set_sensitive(False)
        Gtk.main()

if __name__ == "__main__":
    ui = GtkUI()
    ui.error("foo","bar")