summaryrefslogtreecommitdiffstats
path: root/pyanaconda/ui/gui/spokes/software.py
blob: 2083b5371812a5ffe8b3d380d52c043ab50aa4ae (plain)
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
# Software selection spoke classes
#
# Copyright (C) 2011-2012  Red Hat, Inc.
#
# This copyrighted material is made available to anyone wishing to use,
# modify, copy, or redistribute it subject to the terms and conditions of
# the GNU General Public License v.2, or (at your option) any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY expressed or implied, including the implied warranties 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, write to the
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.  Any Red Hat trademarks that are incorporated in the
# source code or documentation are not subject to the GNU General Public
# License and may only be used or replicated with the express permission of
# Red Hat, Inc.
#
# Red Hat Author(s): Chris Lumens <clumens@redhat.com>
#

import gettext
_ = lambda x: gettext.ldgettext("anaconda", x)
N_ = lambda x: x

from pyanaconda.flags import flags

from pyanaconda.ui.gui import communication
from pyanaconda.ui.gui.spokes import NormalSpoke
from pyanaconda.ui.gui.spokes.lib.detailederror import DetailedErrorDialog
from pyanaconda.ui.gui.utils import enlightbox, gdk_threaded
from pyanaconda.ui.gui.categories.software import SoftwareCategory
from .source import AdditionalReposDialog

from pyanaconda.kickstart import packagesSeen
from pykickstart.parser import Group

import sys

__all__ = ["SoftwareSelectionSpoke"]

class SoftwareSelectionSpoke(NormalSpoke):
    builderObjects = ["addonStore", "environmentStore", "softwareWindow"]
    mainWidgetName = "softwareWindow"
    uiFile = "spokes/software.glade"

    category = SoftwareCategory

    icon = "package-x-generic-symbolic"
    title = N_("SOFTWARE SELECTION")

    def __init__(self, *args, **kwargs):
        NormalSpoke.__init__(self, *args, **kwargs)
        self._errorMsgs = None
        self._tx_id = None
        self._selectFlag = False

        self.selectedGroups = []
        self.excludedGroups = []
        self.environment = None

        self._addRepoDialog = AdditionalReposDialog(self.data)

    def apply(self):
        # NOTE:  Other apply methods work directly with the ksdata, but this
        # one does not.  However, selectGroup/deselectGroup modifies ksdata as
        # part of its operation.  So this is fine.
        from pyanaconda.threads import threadMgr, AnacondaThread

        row = self._get_selected_environment()
        if row:
            self._selectFlag = False
            self.payload.data.packages.groupList = []
            self.payload.selectEnvironment(row[2])
            self.environment = row[2]
            for group in self.selectedGroups:
                self.payload.selectGroup(group)

        communication.send_not_ready(self.__class__.__name__)
        threadMgr.add(AnacondaThread(name="AnaCheckSoftwareThread",
                                     target=self.checkSoftwareSelection))

    def checkSoftwareSelection(self):
        from pyanaconda.packaging import DependencyError
        communication.send_message(self.__class__.__name__,
                                   _("Checking software dependencies..."))
        try:
            self.payload.checkSoftwareSelection()
        except DependencyError as e:
            self._errorMsgs = "\n".join(sorted(e.message))
            communication.send_message(self.__class__.__name__,
                                       _("Error checking software dependencies"))
            self._tx_id = None
        else:
            self._errorMsgs = None
            self._tx_id = self.payload.txID
        finally:
            communication.send_ready(self.__class__.__name__)

    @property
    def completed(self):
        from pyanaconda.threads import threadMgr

        processingDone = not threadMgr.get("AnaCheckSoftwareThread") and \
                         not self._errorMsgs and \
                         self._tx_id == self.payload.txID

        if flags.automatedInstall and packagesSeen:
            return processingDone
        else:
            return self._get_selected_environment() is not None and processingDone

    @property
    def ready(self):
        # By default, the software selection spoke is not ready.  We have to
        # wait until the installation source spoke is completed.  This could be
        # becasue the user filled something out, or because we're done fetching
        # repo metadata from the mirror list, or we detected a DVD/CD.
        from pyanaconda.threads import threadMgr
        return (not threadMgr.get("AnaSoftwareWatcher") and
                not threadMgr.get("AnaPayloadMDThread") and
                not threadMgr.get("AnaCheckSoftwareThread") and
                self.payload.baseRepo is not None)

    @property
    def showable(self):
        return not flags.livecdInstall

    @property
    def status(self):
        from pyanaconda.threads import threadMgr

        if self._errorMsgs:
            return _("Error checking software selection")

        if threadMgr.get("AnaPayloadMDThread") or self.payload.baseRepo is None:
            return _("Installation source not set up")

        row = self._get_selected_environment()
        if not row:
            # Kickstart installs with %packages will have a row selected, unless
            # they did an install without a desktop environment.  This should
            # catch that one case.
            if flags.automatedInstall and packagesSeen:
                return _("Custom software selected")

            return _("Nothing selected")

        return self.payload.environmentDescription(row[2])[0]

    def initialize(self):
        from pyanaconda.threads import threadMgr, AnacondaThread

        NormalSpoke.initialize(self)
        threadMgr.add(AnacondaThread(name="AnaSoftwareWatcher", target=self._initialize))

    def _initialize(self):
        from pyanaconda.packaging import MetadataError
        from pyanaconda.threads import threadMgr

        communication.send_message(self.__class__.__name__, _("Downloading package metadata..."))

        payloadThread = threadMgr.get("AnaPayloadThread")
        if payloadThread:
            payloadThread.join()

        communication.send_message(self.__class__.__name__, _("Downloading group metadata..."))

        # we have no way to select environments with kickstart right now
        # so don't try.
        if flags.automatedInstall and packagesSeen:
            # We don't want to do a full refresh, just
            # join the metadata thread
            mdGatherThread = threadMgr.get("AnaPayloadMDThread")
            if mdGatherThread:
                mdGatherThread.join()
        else:
            with gdk_threaded():
                # Grabbing the list of groups could potentially take a long time the
                # first time (yum does a lot of magic property stuff, some of which
                # involves side effects like network access) so go ahead and grab
                # them once now.
                try:
                    self.refresh()
                except MetadataError:
                    communication.send_message(self.__class__.__name__,
                                               _("No installation source available"))
                    return

        self.payload.release()

        communication.send_ready(self.__class__.__name__)

        # If packages were provided by an input kickstart file (or some other means),
        # we should do dependency solving here.
        self.apply()

    def refresh(self):
        from pyanaconda.threads import threadMgr
        NormalSpoke.refresh(self)

        mdGatherThread = threadMgr.get("AnaPayloadMDThread")
        if mdGatherThread:
            mdGatherThread.join()

        self._environmentStore = self.builder.get_object("environmentStore")
        self._environmentStore.clear()

        clasess = []
        firstEnvironment = True
        for environment in self.payload.environments:
            (name, desc) = self.payload.environmentDescription(environment)

            itr = self._environmentStore.append([environment == self.environment, "<b>%s</b>\n%s" % (name, desc), environment])
            # Either:
            # (1) Select the environment given by kickstart or selected last
            #     time this spoke was displayed; or
            # (2) Select the first environment given by display order as the
            #     default if nothing is selected.
            if (environment == self.environment) or \
               (not self.environment and firstEnvironment):
                sel = self.builder.get_object("environmentSelector")
                sel.select_iter(itr)
                self.environment = environment

            firstEnvironment = False

        self.refreshAddons()

    def refreshAddons(self):
        from gi.repository import Gtk

        self._addonStore = self.builder.get_object("addonStore")
        self._addonStore.clear()
        if self.environment:
            for grp in self.payload.groups:
                if self.payload.environmentHasOption(self.environment, grp) or (self.payload._isGroupVisible(grp) and self.payload._groupHasInstallableMembers(grp)):
                    (name, desc) = self.payload.groupDescription(grp)
                    selected = self.payload.groupSelected(grp)

                    self._addonStore.append([selected, "<b>%s</b>\n%s" % (name, desc), grp])

        self.selectedGroups = [g.name for g in self.data.packages.groupList]
        self.excludedGroups = [g.name
                                for g in self.data.packages.excludedGroupList]
        self._selectFlag = True

        if self._errorMsgs:
            self.window.set_info(Gtk.MessageType.WARNING, _("Error checking software dependencies.  Click for details."))

    # Returns the row in the store corresponding to what's selected on the
    # left hand panel, or None if nothing's selected.
    def _get_selected_environment(self):
        environmentView = self.builder.get_object("environmentView")
        (store, itr) = environmentView.get_selection().get_selected()
        if not itr:
            return None

        return self._environmentStore[itr]

    # Signal handlers
    def on_environment_toggled(self, renderer, path):
        if not self._selectFlag:
            return

        # First, mark every row as unselected so the radio button on whatever
        # row was previously selected will be cleared out.
        for row in self._environmentStore:
            row[0] = False

        # Remove all groups from the previous environment from the selected
        # list, but don't explicitly exclude them.
        for groupid in self.payload.environmentGroups(self.environment):
            grp = Group(groupid)
            if grp in self.data.packages.groupList:
                self.data.packages.groupList.remove(grp)

        # Then mark the clicked environment as selected and update the screen.
        self._environmentStore[path][0] = True
        self.environment = self._environmentStore[path][2]
        self.refreshAddons()

    def on_addon_toggled(self, renderer, path):
        selected = not self._addonStore[path][0]
        group = self._addonStore[path][2]
        self._addonStore[path][0] = selected
        if selected:
            if group not in self.selectedGroups:
                self.selectedGroups.append(group)

            if group in self.excludedGroups:
                self.excludedGroups.remove(group)

        elif not selected and group in self.selectedGroups:
            self.selectedGroups.remove(group)

    def on_custom_clicked(self, button):
        with enlightbox(self.window, self._addRepoDialog.window):
            response =  self._addRepoDialog.run()

    def on_info_bar_clicked(self, *args):
        if not self._errorMsgs:
            return

        label = _("The following software marked for installation has errors.  "
                  "This is likely caused by an error with\nyour installation source.  "
                  "You can attempt to remove these packages from your installation.\n"
                  "change your installation source, or quit the installer.")
        dialog = DetailedErrorDialog(self.data, buttons=[_("_Quit"), _("_Cancel"),
                                                         _("_Remove Packages"),
                                                         _("_Modify Software Source")],
                                                label=label)
        with enlightbox(self.window, dialog.window):
            dialog.refresh(self._errorMsgs)
            rc = dialog.run()

        dialog.window.destroy()

        if rc == 0:
            # Quit.
            sys.exit(0)
        elif rc == 1:
            # Close the dialog so the user can change selections.
            pass
        elif rc == 2:
            # TODO:  Attempt to remove the affected packages.
            pass
        elif rc == 3:
            # Send the user to the installation source spoke.
            self.skipTo = "SourceSpoke"
            self.window.emit("button-clicked")