/
installation_source.py
1830 lines (1501 loc) · 75.8 KB
/
installation_source.py
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
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Installation source spoke classes
#
# Copyright (C) 2019 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.
#
import time
import threading
import os
import signal
import re
from collections import namedtuple
from urllib.parse import urlsplit
from pyanaconda.core import glib, constants
from pyanaconda.core.process_watchers import PidWatcher
from pyanaconda.flags import flags
from pyanaconda.core.i18n import _, N_, CN_
from pyanaconda.payload.image import find_optical_install_media, find_potential_hdiso_sources, \
get_hdiso_source_info, get_hdiso_source_description
from pyanaconda.core.util import ProxyString, ProxyStringError, cmp_obj_attrs, id_generator
from pyanaconda.ui.communication import hubQ
from pyanaconda.ui.helpers import InputCheck, InputCheckHandler
from pyanaconda.ui.gui import GUIObject
from pyanaconda.ui.gui.helpers import GUIDialogInputCheckHandler, GUISpokeInputCheckHandler
from pyanaconda.ui.gui.spokes import NormalSpoke
from pyanaconda.ui.categories.software import SoftwareCategory
from pyanaconda.ui.gui.utils import blockedHandler, fire_gtk_action, find_first_child
from pyanaconda.ui.gui.utils import gtk_call_once, really_hide, really_show, fancy_set_sensitive
from pyanaconda.threading import threadMgr, AnacondaThread
from pyanaconda.payload import PackagePayload
from pyanaconda.payload import utils as payload_utils
from pyanaconda.payload.manager import payloadMgr, PayloadState
from pyanaconda.core.configuration.anaconda import conf
from pyanaconda.core.regexes import REPO_NAME_VALID, URL_PARSE, HOSTNAME_PATTERN_WITHOUT_ANCHORS
from pyanaconda.modules.common.constants.services import NETWORK, STORAGE
from pyanaconda.modules.common.constants.objects import DEVICE_TREE
from pyanaconda.modules.common.structures.storage import DeviceData
from pyanaconda.storage.utils import device_matches
from pyanaconda.ui.lib.storage import mark_protected_device, unmark_protected_device
from pyanaconda.anaconda_loggers import get_module_logger
log = get_module_logger(__name__)
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
__all__ = ["SourceSpoke"]
BASEREPO_SETUP_MESSAGE = N_("Setting up installation source...")
# These need to match the IDs in protocolComboBox and repoProtocolComboBox in
# installation_source.glade.
PROTOCOL_HTTP = 'http'
PROTOCOL_HTTPS = 'https'
PROTOCOL_FTP = 'ftp'
PROTOCOL_NFS = 'nfs'
PROTOCOL_FILE = 'file'
PROTOCOL_MIRROR = 'Closest mirror'
URL_TYPE_URL = 'url'
URL_TYPE_MIRRORLIST = 'mirrorlist'
URL_TYPE_METALINK = 'metalink'
# Repo Store Columns
REPO_ENABLED_COL = 0
REPO_NAME_COL = 1
REPO_OBJ = 2
# Additional repo protocol combobox fields
MODEL_ROW_VALUE = 0
MODEL_ROW_NAME = 1
REPO_PROTO = {PROTOCOL_HTTP: "http://",
PROTOCOL_HTTPS: "https://",
PROTOCOL_FTP: "ftp://",
PROTOCOL_NFS: "nfs://",
PROTOCOL_FILE: "file://"
}
CLICK_FOR_DETAILS = N_(' <a href="">Click for details.</a>')
def _validate_proxy(proxy_string, username_set, password_set):
"""Validate a proxy string and return an input code usable by InputCheck
:param str proxy_string: the proxy URL string
:param bool username_set: Whether a username has been specified external to the URL
:param bool password_set: Whether a password has been speicifed external to the URL
"""
proxy_match = URL_PARSE.match(proxy_string)
if not proxy_match:
return _("Invalid proxy URL")
# Ensure the protocol is something that makes sense
protocol = proxy_match.group("protocol")
if protocol and protocol not in ('http://', 'https://', 'ftp://'):
return _("Invalid proxy protocol: %s") % protocol
# Path and anything after makes no sense for a proxy URL
# Allow '/' as a path so you can use http://proxy.example.com:8080/
if (proxy_match.group("path") and proxy_match.group("path") != "/") \
or proxy_match.group("query") or proxy_match.group("fragment"):
return _("Extra characters in proxy URL")
# Check if if authentication data is both in the URL and specified externally
if (proxy_match.group("username") or proxy_match.group("password")) \
and (username_set or password_set):
return _("Proxy authentication data duplicated")
return InputCheck.CHECK_OK
RepoChecks = namedtuple("RepoChecks", ["name_check", "url_check", "proxy_check"])
class ProxyDialog(GUIObject, GUIDialogInputCheckHandler):
builderObjects = ["proxyDialog"]
mainWidgetName = "proxyDialog"
uiFile = "spokes/installation_source.glade"
def __init__(self, data, proxy_url):
GUIObject.__init__(self, data)
self._proxy_ok_button = self.builder.get_object("proxyOkButton")
GUIDialogInputCheckHandler.__init__(self, self._proxy_ok_button)
self.proxy_url = proxy_url
self._proxy_check = self.builder.get_object("enableProxyCheck")
self._proxy_info_box = self.builder.get_object("proxyInfoBox")
self._auth_check = self.builder.get_object("enableAuthCheck")
self._proxy_auth_box = self.builder.get_object("proxyAuthBox")
self._proxy_url_entry = self.builder.get_object("proxyURLEntry")
self._proxy_username_entry = self.builder.get_object("proxyUsernameEntry")
self._proxy_password_entry = self.builder.get_object("proxyPasswordEntry")
self._proxy_validate = self.add_check(self._proxy_url_entry, self._check_proxy_url)
self._proxy_validate.update_check_status()
def _check_proxy_url(self, inputcheck):
proxy_string = self.get_input(inputcheck.input_obj)
# Don't set an error icon on empty input, but still consider it an error
if not proxy_string:
return InputCheck.CHECK_SILENT
return _validate_proxy(proxy_string, self._is_username_set(), self._is_password_set())
def _is_username_set(self):
return self._proxy_username_entry.is_sensitive() and self._proxy_username_entry.get_text()
def _is_password_set(self):
return self._proxy_password_entry.is_sensitive() and self._proxy_password_entry.get_text()
# Update the proxy validation check on username and password changes to catch
# changes in duplicated authentication data
def on_proxyUsernameEntry_changed(self, entry, user_data=None):
self._proxy_validate.update_check_status()
def on_proxyPasswordEntry_changed(self, entry, user_data=None):
self._proxy_validate.update_check_status()
def on_proxy_enable_toggled(self, button, *args):
self._proxy_info_box.set_sensitive(button.get_active())
if button.get_active():
self.set_status(self._proxy_validate)
else:
self._proxy_ok_button.set_sensitive(True)
def on_proxy_auth_toggled(self, button, *args):
self._proxy_auth_box.set_sensitive(button.get_active())
self._proxy_validate.update_check_status()
def refresh(self):
GUIObject.refresh(self)
if not self.proxy_url:
self._proxy_check.set_active(False)
self.on_proxy_enable_toggled(self._proxy_check)
self._auth_check.set_active(False)
self.on_proxy_auth_toggled(self._auth_check)
return
try:
proxy = ProxyString(self.proxy_url)
if proxy.username:
self._proxy_username_entry.set_text(proxy.username)
if proxy.password:
self._proxy_password_entry.set_text(proxy.password)
self._proxy_url_entry.set_text(proxy.noauth_url)
except ProxyStringError as e:
log.error("Failed to parse proxy for ProxyDialog.refresh %s: %s", self.proxy_url, e)
return
self._proxy_check.set_active(True)
self._auth_check.set_active(bool(proxy.username or proxy.password))
self.on_proxy_enable_toggled(self._proxy_check)
self.on_proxy_auth_toggled(self._auth_check)
def run(self):
while True:
response = self.window.run()
if response == 1:
if self.on_ok_clicked():
# Ok clicked with valid input, save the proxy data
if self._proxy_check.get_active():
url = self._proxy_url_entry.get_text()
if self._auth_check.get_active():
username = self._proxy_username_entry.get_text()
password = self._proxy_password_entry.get_text()
else:
username = None
password = None
proxy = ProxyString(url=url, username=username, password=password)
self.proxy_url = proxy.url
else:
self.proxy_url = ""
break
else:
# Ok clicked with invalid input, keep running the dialog
continue
else:
# Cancel or Esc, just exit
break
self.window.destroy()
class MediaCheckDialog(GUIObject):
builderObjects = ["mediaCheckDialog"]
mainWidgetName = "mediaCheckDialog"
uiFile = "spokes/installation_source.glade"
def __init__(self, data):
super().__init__(data)
self.progressBar = self.builder.get_object("mediaCheck-progressBar")
self._pid = None
def _check_iso_ends_cb(self, pid, status):
done_button = self.builder.get_object("doneButton")
verify_label = self.builder.get_object("verifyLabel")
if os.WIFSIGNALED(status):
pass
elif status == 0:
verify_label.set_text(_("This media is good to install from."))
else:
verify_label.set_text(_("This media is not good to install from."))
self.progressBar.set_fraction(1.0)
done_button.set_sensitive(True)
glib.spawn_close_pid(pid)
self._pid = None
def _check_iso_stdout_watcher(self, fd, condition):
if condition == glib.IOCondition.HUP:
return False
channel = glib.IOChannel(fd)
line = channel.readline().strip()
if not line.isdigit():
return True
pct = float(line)/100
if pct > 1.0:
pct = 1.0
self.progressBar.set_fraction(pct)
return True
def run(self, device_path):
(retval, self._pid, _stdin, stdout, _stderr) = \
glib.spawn_async_with_pipes(None, ["checkisomd5", "--gauge", device_path], [],
glib.SpawnFlags.DO_NOT_REAP_CHILD |
glib.SpawnFlags.SEARCH_PATH,
None, None)
if not retval:
return
# This function waits for checkisomd5 to end and then cleans up after it.
PidWatcher().watch_process(self._pid, self._check_iso_ends_cb)
# This function watches the process's stdout.
glib.io_add_watch(stdout,
glib.IOCondition.IN | glib.IOCondition.HUP,
self._check_iso_stdout_watcher)
self.window.run()
def on_close(self, *args):
if self._pid:
os.kill(self._pid, signal.SIGKILL)
self.window.destroy()
def on_done_clicked(self, *args):
self.window.destroy()
# This class is responsible for popping up the dialog that allows the user to
# choose the ISO image they want to use. We can get away with this instead of
# selecting a directory because we no longer support split media.
#
# Two assumptions about the use of this class:
# (1) This class is responsible for mounting and unmounting the partition
# containing the ISO images.
# (2) When you call refresh() with a currentFile argument or when you get a
# result from run(), the file path you use is relative to the root of the
# mounted partition. In other words, it will not contain the
# "/mnt/isodir/install" part. This is consistent with the rest of anaconda.
class IsoChooser(GUIObject):
builderObjects = ["isoChooserDialog", "isoFilter"]
mainWidgetName = "isoChooserDialog"
uiFile = "spokes/installation_source.glade"
def __init__(self, data):
super().__init__(data)
self._chooser = self.builder.get_object("isoChooserDialog")
# Hide the places sidebar, since it makes no sense in this context
# This is discouraged, but the alternative suggested is to reinvent the
# wheel. See also https://bugzilla.gnome.org/show_bug.cgi?id=751730
places_sidebar = find_first_child(self._chooser,
lambda x: isinstance(x, Gtk.PlacesSidebar))
if places_sidebar:
really_hide(places_sidebar)
# pylint: disable=arguments-differ
def refresh(self, currentFile=""):
super().refresh()
self._chooser.connect("current-folder-changed", self.on_folder_changed)
self._chooser.set_filename(constants.ISO_DIR + "/" + currentFile)
def run(self, device_name):
retval = None
device_path = payload_utils.get_device_path(device_name)
mounts = payload_utils.get_mount_paths(device_path)
mountpoint = None
# We have to check both ISO_DIR and the DRACUT_ISODIR because we
# still reference both, even though /mnt/install is a symlink to
# /run/install. Finding mount points doesn't handle the symlink
if constants.ISO_DIR not in mounts and constants.DRACUT_ISODIR not in mounts:
# We're not mounted to either location, so do the mount
mountpoint = constants.ISO_DIR
payload_utils.mount_device(device_name, mountpoint)
# If any directory was chosen, return that. Otherwise, return None.
rc = self.window.run()
if rc == Gtk.ResponseType.OK:
f = self._chooser.get_filename()
if f:
retval = f.replace(constants.ISO_DIR, "")
if not mounts:
payload_utils.unmount_device(device_name, mountpoint)
self.window.destroy()
return retval
# There doesn't appear to be any way to restrict a GtkFileChooser to a
# given directory (see https://bugzilla.gnome.org/show_bug.cgi?id=155729)
# so we'll just have to fake it by setting you back to inside the directory
# should you change out of it.
def on_folder_changed(self, chooser):
d = chooser.get_current_folder()
if not d:
return
if not d.startswith(constants.ISO_DIR):
chooser.set_current_folder(constants.ISO_DIR)
class SourceSpoke(NormalSpoke, GUISpokeInputCheckHandler):
"""
.. inheritance-diagram:: SourceSpoke
:parts: 3
"""
builderObjects = ["isoChooser", "isoFilter", "partitionStore", "sourceWindow",
"dirImage", "repoStore"]
mainWidgetName = "sourceWindow"
uiFile = "spokes/installation_source.glade"
helpFile = "SourceSpoke.xml"
category = SoftwareCategory
icon = "media-optical-symbolic"
title = CN_("GUI|Spoke", "_Installation Source")
def __init__(self, *args, **kwargs):
NormalSpoke.__init__(self, *args, **kwargs)
GUISpokeInputCheckHandler.__init__(self)
self._current_iso_file = None
self._ready = False
self._error = False
self._error_msg = ""
self._proxy_url = ""
self._proxy_change = False
self._updates_change = False
self._cdrom = None
self._repo_counter = id_generator()
self._repo_checks = {}
self._repo_store_lock = threading.Lock()
self._network_module = NETWORK.get_proxy()
self._device_tree = STORAGE.get_proxy(DEVICE_TREE)
self._treeinfo_repos_already_disabled = False
def apply(self):
payloadMgr.restart_thread(self.payload, checkmount=False)
self.clear_info()
def _method_changed(self):
""" Check to see if the install method has changed.
:returns: True if it changed, False if not
:rtype: bool
"""
# FIXME:
# This is an ugly temporary fix, because we cannot use deepcopy since
# pykickstart 3. This entire module should be rewritten anyway.
old_method = self.data.method.method
old_partition = getattr(self.data.method, "partition", None)
old_dir = getattr(self.data.method, "dir", None)
old_url = getattr(self.data.method, "url", None)
old_server = getattr(self.data.method, "server", None)
old_opts = getattr(self.data.method, "opts", None)
old_mirrorlist = getattr(self.data.method, "mirrorlist", None)
old_metalink = getattr(self.data.method, "metalink", None)
if self._autodetect_button.get_active():
if not self._cdrom:
return False
self.data.method.method = "cdrom"
self.payload.install_device = self._cdrom
if old_method == "cdrom":
# XXX maybe we should always redo it for cdrom in case they
# switched disks
return False
elif self._hmc_button.get_active():
self.data.method.method = "hmc"
elif self._iso_button.get_active():
# If the user didn't select a partition (not sure how that would
# happen) or didn't choose a directory (more likely), then return
# as if they never did anything.
partition = self._get_selected_partition()
if not partition or not self._current_iso_file:
return False
self.data.method.method = "harddrive"
self.data.method.partition = partition
# The / gets stripped off by payload.ISO_image
self.data.method.dir = "/" + self._current_iso_file
if old_method == "harddrive" \
and payload_utils.resolve_device(old_partition) == partition \
and old_dir in [self._current_iso_file, "/" + self._current_iso_file]:
return False
# Make sure anaconda doesn't touch this device.
mark_protected_device(partition)
elif self._mirror_active():
# this preserves the url for later editing
self.data.method.method = None
self.data.method.proxy = self._proxy_url
if not old_method and self.payload.base_repo and \
not self._proxy_change and not self._updates_change:
return False
elif self._ftp_active():
url = self._url_entry.get_text().strip()
# If the user didn't fill in the URL entry, just return as if they
# selected nothing.
if url == "":
return False
# Make sure the URL starts with the protocol. dnf will want that
# to know how to fetch, and the refresh method needs that to know
# which element of the combo to default to should this spoke be
# revisited.
if not url.startswith("ftp://"):
url = "ftp://" + url
if old_method == "url" and not self._proxy_change and \
old_url == url:
return False
self.data.method.method = "url"
self.data.method.proxy = self._proxy_url
self.data.method.url = url
self.data.method.mirrorlist = ""
self.data.method.metalink = ""
elif self._http_active():
url = self._url_entry.get_text().strip()
# If the user didn't fill in the URL entry, just return as if they
# selected nothing.
if url == "":
return False
# Make sure the URL starts with the protocol. dnf will want that
# to know how to fetch, and the refresh method needs that to know
# which element of the combo to default to should this spoke be
# revisited.
elif (self._protocol_combo_box.get_active_id() == PROTOCOL_HTTP
and not url.startswith("http://")):
url = "http://" + url
elif (self._protocol_combo_box.get_active_id() == PROTOCOL_HTTPS
and not url.startswith("https://")):
url = "https://" + url
url_type = self._url_type_combo_box.get_active_id()
url_changed = self._url_changed(url, url_type, old_url, old_mirrorlist, old_metalink)
if old_method == "url" and not self._proxy_change and not url_changed:
return False
self.data.method.method = "url"
self.data.method.proxy = self._proxy_url
self.data.method.url = self.data.method.mirrorlist = self.data.method.metalink = ""
if url_type == URL_TYPE_MIRRORLIST:
self.data.method.mirrorlist = url
elif url_type == URL_TYPE_METALINK:
self.data.method.metalink = url
else:
self.data.method.url = url
elif self._nfs_active():
url = self._url_entry.get_text().strip()
if url == "":
return False
self.data.method.method = "nfs"
try:
(self.data.method.server, self.data.method.dir) = url.split(":", 2)
except ValueError as e:
log.error("ValueError: %s", e)
self._error = True
self._error_msg = _("Failed to set up installation source; check the repo url")
return
self.data.method.opts = self.builder.get_object("nfsOptsEntry").get_text() or ""
if old_method == "nfs" \
and old_server == self.data.method.server \
and old_dir == self.data.method.dir \
and old_opts == self.data.method.opts:
return False
# If the user moved from an HDISO method to some other, we need to
# clear the protected bit on that device.
if old_method == "harddrive" and old_partition:
if not self._iso_button.get_active():
# Only clear this if iso isn't selected
self._current_iso_file = None
self._iso_chooser_button.set_label(self._orig_iso_chooser_button)
self._iso_chooser_button.set_use_underline(True)
unmark_protected_device(old_partition)
self._proxy_change = False
self._updates_change = False
return True
def _url_changed(self, url, url_type, old_url, old_mirrorlist, old_metalink):
if url_type == URL_TYPE_URL:
return url != old_url
elif url_type == URL_TYPE_MIRRORLIST:
return url != old_mirrorlist
else:
return url != old_metalink
def _update_file_protocol(self, ksrepo):
"""Show file protocol for repositories that already have it. Remove it when unselected."""
if ksrepo.baseurl and ksrepo.baseurl.startswith(REPO_PROTO[PROTOCOL_FILE]):
self._set_file_protocol_to_repo_combobox()
self._repo_protocol_combo_box.set_sensitive(False)
else:
self._remove_file_protocol_from_repo_combobox()
self._repo_protocol_combo_box.set_sensitive(True)
def _set_file_protocol_to_repo_combobox(self):
# file protocol will be always the last one
model = self._repo_protocol_combo_box.get_model()
row = self._get_protocol_row(PROTOCOL_FILE)
if row is None:
model.append([REPO_PROTO[PROTOCOL_FILE], PROTOCOL_FILE])
self._protocol_combo_box.set_active_id(PROTOCOL_FILE)
def _remove_file_protocol_from_repo_combobox(self):
model = self._repo_protocol_combo_box.get_model()
row = self._get_protocol_row(PROTOCOL_FILE)
if row:
model.remove(row.iter)
def _get_protocol_row(self, protocol):
model = self._repo_protocol_combo_box.get_model()
for row in model:
if row[MODEL_ROW_NAME] == protocol:
return row
return None
@property
def changed(self):
method_changed = self._method_changed()
update_payload_repos = self._update_payload_repos()
return method_changed or update_payload_repos or self._error
@property
def completed(self):
""" WARNING: This can be called before _initialize is done, make sure that it
doesn't access things that are not setup (eg. payload.*) until it is ready
"""
if flags.automatedInstall and self.ready and not self.payload.base_repo:
return False
else:
return not self._error and self.ready and \
(self.data.method.method or self.payload.base_repo)
@property
def mandatory(self):
return True
@property
def ready(self):
return (self._ready and
not threadMgr.get(constants.THREAD_PAYLOAD) and
not threadMgr.get(constants.THREAD_SOFTWARE_WATCHER) and
not threadMgr.get(constants.THREAD_CHECK_SOFTWARE))
@property
def status(self):
if threadMgr.get(constants.THREAD_CHECK_SOFTWARE):
return _("Checking software dependencies...")
elif not self.ready:
return _(BASEREPO_SETUP_MESSAGE)
elif not self.payload.base_repo:
return _("Error setting up base repository")
elif self._error:
return _("Error setting up software source")
elif self.data.method.method == "url":
return self.data.method.url or self.data.method.mirrorlist or self.data.method.metalink
elif self.data.method.method == "nfs":
return _("NFS server %s") % self.data.method.server
elif self.data.method.method == "cdrom":
return _("Local media")
elif self.data.method.method == "hmc":
return _("Local media via SE/HMC")
elif self.data.method.method == "harddrive":
if not self._current_iso_file:
if self.payload.base_repo:
return "{}:{}".format(self._get_harddrive_partition_name(),
self.data.method.dir)
return _("Error setting up installation from HDD")
return os.path.basename(self._current_iso_file)
elif self.payload.base_repo:
return _("Closest mirror")
else:
return _("Nothing selected")
def _get_harddrive_partition_name(self):
devices = device_matches(self.data.method.partition)
if not devices:
log.warning("Device for installation from HDD can't be found!")
return ""
elif len(devices) > 1:
log.warning("More than one device is found for HDD installation!")
return devices[0]
def _grab_objects(self):
self._autodetect_button = self.builder.get_object("autodetectRadioButton")
self._autodetect_box = self.builder.get_object("autodetectBox")
self._autodetect_device_label = self.builder.get_object("autodetectDeviceLabel")
self._autodetect_label = self.builder.get_object("autodetectLabel")
self._hmc_button = self.builder.get_object("hmcRadioButton")
self._iso_button = self.builder.get_object("isoRadioButton")
self._iso_box = self.builder.get_object("isoBox")
self._network_button = self.builder.get_object("networkRadioButton")
self._network_box = self.builder.get_object("networkBox")
self._url_entry = self.builder.get_object("urlEntry")
self._protocol_combo_box = self.builder.get_object("protocolComboBox")
self._iso_chooser_button = self.builder.get_object("isoChooserButton")
self._orig_iso_chooser_button = self._iso_chooser_button.get_label()
# Attach a validator to the URL entry. Start it as disabled, and it will be
# enabled/disabled as entry sensitivity is enabled/disabled.
self._url_check = self.add_check(self._url_entry, self._check_url_entry)
self._url_check.enabled = False
self._url_type_combo_box = self.builder.get_object("urlTypeComboBox")
self._url_type_label = self.builder.get_object("urlTypeLabel")
self._updates_radio_button = self.builder.get_object("updatesRadioButton")
self._verify_iso_button = self.builder.get_object("verifyIsoButton")
# addon repo objects
self._repo_entry_box = self.builder.get_object("repoEntryBox")
self._repo_store = self.builder.get_object("repoStore")
self._repo_selection = self.builder.get_object("repoSelection")
self._repo_name_entry = self.builder.get_object("repoNameEntry")
self._repo_protocol_combo_box = self.builder.get_object("repoProtocolComboBox")
self._repo_url_entry = self.builder.get_object("repoUrlEntry")
self._repo_url_type_combo_box = self.builder.get_object("repoUrlTypeComboBox")
self._repo_proxy_url_entry = self.builder.get_object("repoProxyUrlEntry")
self._repo_proxy_username_entry = self.builder.get_object("repoProxyUsernameEntry")
self._repo_proxy_password_entry = self.builder.get_object("repoProxyPasswordEntry")
self._repo_view = self.builder.get_object("repoTreeView")
self._repo_remove_button = self.builder.get_object("removeButton")
# Create a check for duplicate repo ids
# Call InputCheckHandler directly since this check operates on rows of a TreeModel
# instead of GtkEntry inputs. Updating the check is handled by the signal handlers
# connected to repoStore.
self._duplicate_repo_check = InputCheckHandler.add_check(self, self._repo_store,
self._check_duplicate_repos)
# Create a dictionary for the checks on fields in individual repos
# These checks will be added and removed as repos are added and removed from repoStore
self._repo_checks = {}
# updates option container
self._updates_box = self.builder.get_object("updatesBox")
self._proxy_button = self.builder.get_object("proxyButton")
self._nfs_opts_box = self.builder.get_object("nfsOptsBox")
# Connect scroll events on the viewport with focus events on the box
main_viewport = self.builder.get_object("mainViewport")
main_box = self.builder.get_object("mainBox")
main_box.set_focus_vadjustment(Gtk.Scrollable.get_vadjustment(main_viewport))
def initialize(self):
NormalSpoke.initialize(self)
self.initialize_start()
self._grab_objects()
# I shouldn't have to do this outside GtkBuilder, but it really doesn't
# want to let me pass in user data.
# See also: https://bugzilla.gnome.org/show_bug.cgi?id=727919
self._autodetect_button.connect("toggled", self.on_source_toggled, self._autodetect_box)
self._hmc_button.connect("toggled", self.on_source_toggled, None)
self._iso_button.connect("toggled", self.on_source_toggled, self._iso_box)
self._network_button.connect("toggled", self.on_source_toggled, self._network_box)
self._network_button.connect("toggled", self._update_url_entry_check)
# Show or hide the updates option based on the configuration
if conf.payload.enable_updates:
really_show(self._updates_box)
else:
really_hide(self._updates_box)
# Register listeners for payload events
payloadMgr.add_listener(PayloadState.STARTED, self._payload_refresh)
payloadMgr.add_listener(PayloadState.WAITING_STORAGE, self._probing_storage)
payloadMgr.add_listener(PayloadState.DOWNLOADING_PKG_METADATA,
self._downloading_package_md)
payloadMgr.add_listener(PayloadState.DOWNLOADING_GROUP_METADATA,
self._downloading_group_md)
payloadMgr.add_listener(PayloadState.FINISHED, self._payload_finished)
payloadMgr.add_listener(PayloadState.ERROR, self._payload_error)
# Start the thread last so that we are sure initialize_done() is really called only
# after all initialization has been done.
threadMgr.add(AnacondaThread(name=constants.THREAD_SOURCE_WATCHER,
target=self._initialize))
def _payload_refresh(self):
hubQ.send_not_ready("SoftwareSelectionSpoke")
hubQ.send_not_ready(self.__class__.__name__)
hubQ.send_message(self.__class__.__name__, _(BASEREPO_SETUP_MESSAGE))
# this sleep is lame, but without it the message above doesn't seem
# to get processed by the hub in time, and is never shown.
# FIXME this should get removed when we figure out how to ensure
# that the message takes effect on the hub before we try to mount
# a bad NFS server.
time.sleep(1)
def _probing_storage(self):
hubQ.send_message(self.__class__.__name__, _(constants.PAYLOAD_STATUS_PROBING_STORAGE))
def _downloading_package_md(self):
# Reset the error state from previous payloads
self._error = False
self._error_msg = ""
hubQ.send_message(self.__class__.__name__, _(constants.PAYLOAD_STATUS_PACKAGE_MD))
def _downloading_group_md(self):
hubQ.send_message(self.__class__.__name__, _(constants.PAYLOAD_STATUS_GROUP_MD))
def _payload_finished(self):
hubQ.send_ready("SoftwareSelectionSpoke", False)
self._ready = True
hubQ.send_ready(self.__class__.__name__, False)
def _payload_error(self):
self._error = True
hubQ.send_message(self.__class__.__name__, payloadMgr.error)
if not (hasattr(self.data.method, "proxy") and self.data.method.proxy):
self._error_msg = _("Failed to set up installation source; check the repo url.")
else:
self._error_msg = _("Failed to set up installation source; check the repo url"
" and proxy settings.")
if self.payload.verbose_errors:
self._error_msg += _(CLICK_FOR_DETAILS)
self._ready = True
hubQ.send_ready(self.__class__.__name__, False)
def _initialize(self):
threadMgr.wait(constants.THREAD_PAYLOAD)
# If there's no fallback mirror to use, we should just disable that option
# in the UI.
if not self.payload.mirrors_available:
model = self._protocol_combo_box.get_model()
itr = model.get_iter_first()
while itr and model[itr][self._protocol_combo_box.get_id_column()] != PROTOCOL_MIRROR:
itr = model.iter_next(itr)
if itr:
model.remove(itr)
# If we've previously set up to use a CD/DVD method, the media has
# already been mounted by payload.setup. We can't try to mount it
# again. So just use what we already know to create the selector.
# Otherwise, check to see if there's anything available.
if self.data.method.method == "cdrom":
self._cdrom = self.payload.install_device
elif not flags.automatedInstall:
self._cdrom = find_optical_install_media()
if self._cdrom:
self._show_autodetect_box_with_device(self._cdrom)
if self.data.method.method == "harddrive":
if self.payload.ISO_image:
self._current_iso_file = self.payload.ISO_image
else: # Installation from an expanded install tree
device_name = self._get_harddrive_partition_name()
self._show_autodetect_box(device_name, self.data.method.partition)
# Enable the SE/HMC option.
if self.payload.is_hmc_enabled:
gtk_call_once(self._hmc_button.set_no_show_all, False)
# Add the mirror manager URL in as the default for HTTP and HTTPS.
# We'll override this later in the refresh() method, if they've already
# provided a URL.
# FIXME
self._reset_repo_store()
self._ready = True
# Wait to make sure the other threads are done before sending ready, otherwise
# the spoke may not be set sensitive by _handleCompleteness in the hub.
while not self.ready:
time.sleep(1)
hubQ.send_ready(self.__class__.__name__, False)
# report that the source spoke has been initialized
self.initialize_done()
def _show_autodetect_box_with_device(self, device_name):
device_data = DeviceData.from_structure(
self._device_tree.GetDeviceData(device_name)
)
device_label = device_data.attrs.get("label", "")
self._show_autodetect_box(device_name, device_label)
def _show_autodetect_box(self, device_name, device_label):
fire_gtk_action(self._autodetect_device_label.set_text, _("Device: %s") % device_name)
fire_gtk_action(self._autodetect_label.set_text, _("Label: %s") % device_label)
gtk_call_once(self._autodetect_box.set_no_show_all, False)
gtk_call_once(self._autodetect_button.set_no_show_all, False)
def refresh(self):
NormalSpoke.refresh(self)
# Find all hard drive partitions that could hold an ISO and add each
# to the partitionStore. This has to be done here because if the user
# has done partitioning first, they may have blown away partitions
# found during _initialize on the partitioning spoke.
store = self.builder.get_object("partitionStore")
store.clear()
added = False
active = 0
idx = 0
if self.data.method.method == "harddrive":
method_dev_name = self._get_harddrive_partition_name()
for device_name in find_potential_hdiso_sources():
device_info = get_hdiso_source_info(self._device_tree, device_name)
# With the label in here, the combo box can appear really long thus pushing
# the "pick an image" and the "verify" buttons off the screen.
if device_info["label"] != "":
device_info["label"] = "\n" + device_info["label"]
device_desc = get_hdiso_source_description(device_info)
store.append([device_name, device_desc])
if self.data.method.method == "harddrive" and device_name == method_dev_name:
active = idx
added = True
idx += 1
# Again, only display these widgets if an HDISO source was found.
self._iso_box.set_no_show_all(not added)
self._iso_box.set_visible(added)
self._iso_button.set_no_show_all(not added)
self._iso_button.set_visible(added)
if added:
combo = self.builder.get_object("isoPartitionCombo")
combo.set_active(active)
# We default to the mirror list, and then if the method tells us
# something different later, we can change it.
self._protocol_combo_box.set_active_id(PROTOCOL_MIRROR)
if self.data.method.method == "url":
self._network_button.set_active(True)
proto = self.data.method.url or \
self.data.method.mirrorlist or \
self.data.method.metalink
if proto.startswith("http:"):
self._protocol_combo_box.set_active_id(PROTOCOL_HTTP)
length = 7
elif proto.startswith("https:"):
self._protocol_combo_box.set_active_id(PROTOCOL_HTTPS)
length = 8
elif proto.startswith("ftp:"):
self._protocol_combo_box.set_active_id(PROTOCOL_FTP)
length = 6
else:
self._protocol_combo_box.set_active_id(PROTOCOL_HTTP)
length = 0
self._url_entry.set_text(proto[length:])
self._update_url_entry_check()
self._update_url_type_combo_box()
self._proxy_url = self.data.method.proxy
elif self.data.method.method == "nfs":
self._network_button.set_active(True)
self._protocol_combo_box.set_active_id(PROTOCOL_NFS)
self._url_entry.set_text("%s:%s" % (self.data.method.server, self.data.method.dir))
self._update_url_entry_check()
self.builder.get_object("nfsOptsEntry").set_text(self.data.method.opts or "")
elif self.data.method.method == "harddrive":
if not self._current_iso_file:
self._autodetect_button.set_active(True)
else:
self._iso_button.set_active(True)
self._verify_iso_button.set_sensitive(True)
if self._current_iso_file:
self._iso_chooser_button.set_label(os.path.basename(self._current_iso_file))
else:
self._iso_chooser_button.set_label("")
self._iso_chooser_button.set_use_underline(False)
elif self.data.method.method == "hmc":
self._hmc_button.set_active(True)
else:
# No method was given in advance, so now we need to make a sensible