/
source.py
1417 lines (1156 loc) · 58.1 KB
/
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) 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>
# Martin Sivak <msivak@redhat.com>
#
import time
import logging
log = logging.getLogger("anaconda")
import os, signal, re
from gi.repository import GLib, Gtk
from pyanaconda.flags import flags
from pyanaconda.i18n import _, N_, CN_
from pyanaconda.image import opticalInstallMedia, potentialHdisoSources
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
from pyanaconda.iutil import ProxyString, ProxyStringError, cmp_obj_attrs
from pyanaconda.ui.gui.utils import gtk_call_once, really_hide, really_show, fancy_set_sensitive
from pyanaconda.threads import threadMgr, AnacondaThread
from pyanaconda.packaging import PackagePayload, payloadMgr
from pyanaconda.regexes import REPO_NAME_VALID, URL_PARSE, HOSTNAME_PATTERN_WITHOUT_ANCHORS
from pyanaconda import constants
from blivet.util import get_mount_device, get_mount_paths
__all__ = ["SourceSpoke"]
BASEREPO_SETUP_MESSAGE = N_("Setting up installation source...")
METADATA_DOWNLOAD_MESSAGE = N_("Downloading package metadata...")
# These need to match the IDs in protocolComboBox and repoProtocolComboBox in source.glade.
PROTOCOL_HTTP = 'http'
PROTOCOL_HTTPS = 'https'
PROTOCOL_FTP = 'ftp'
PROTOCOL_NFS = 'nfs'
PROTOCOL_MIRROR = 'Closest mirror'
# Repo Store Columns
REPO_ENABLED_COL = 0
REPO_NAME_COL = 1
REPO_OBJ = 2
REPO_PROTO = {PROTOCOL_HTTP: "http://",
PROTOCOL_HTTPS: "https://",
PROTOCOL_FTP: "ftp://",
PROTOCOL_NFS: "nfs://"
}
def _validateProxy(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
class ProxyDialog(GUIObject, GUIDialogInputCheckHandler):
builderObjects = ["proxyDialog"]
mainWidgetName = "proxyDialog"
uiFile = "spokes/source.glade"
def __init__(self, data, proxy_url):
GUIObject.__init__(self, data)
GUIDialogInputCheckHandler.__init__(self)
self.proxyUrl = proxy_url
self._proxyCheck = self.builder.get_object("enableProxyCheck")
self._proxyInfoBox = self.builder.get_object("proxyInfoBox")
self._authCheck = self.builder.get_object("enableAuthCheck")
self._proxyAuthBox = self.builder.get_object("proxyAuthBox")
self._proxyURLEntry = self.builder.get_object("proxyURLEntry")
self._proxyUsernameEntry = self.builder.get_object("proxyUsernameEntry")
self._proxyPasswordEntry = self.builder.get_object("proxyPasswordEntry")
self._proxyOkButton = self.builder.get_object("proxyOkButton")
self._proxyValidate = self.add_check(self._proxyURLEntry, self._checkProxyURL)
self._proxyValidate.update_check_status()
# Connect scroll events on the viewport with focus events on the box
mainViewport = self.builder.get_object("mainViewport")
mainBox = self.builder.get_object("mainBox")
mainBox.set_focus_vadjustment(mainViewport.get_vadjustment())
def _checkProxyURL(self, inputcheck):
proxy_string = self.get_input(inputcheck.input_obj)
# Don't set an error icon on empty input, but keep the add button insensitive.
if not proxy_string:
return InputCheck.CHECK_SILENT
username_set = self._proxyUsernameEntry.is_sensitive() and self._proxyUsernameEntry.get_text()
password_set = self._proxyPasswordEntry.is_sensitive() and self._proxyPasswordEntry.get_text()
return _validateProxy(proxy_string, username_set, password_set)
def set_status(self, inputcheck):
# Use the superclass set_status to set the error message
GUIDialogInputCheckHandler.set_status(self, inputcheck)
# Change the sensitivity of the Add button
self._proxyOkButton.set_sensitive(inputcheck.check_status == InputCheck.CHECK_OK)
# 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._proxyValidate.update_check_status()
def on_proxyPasswordEntry_changed(self, entry, user_data=None):
self._proxyValidate.update_check_status()
def on_proxy_cancel_clicked(self, *args):
self.window.destroy()
def on_proxy_ok_clicked(self, *args):
if self._proxyCheck.get_active():
url = self._proxyURLEntry.get_text()
if self._authCheck.get_active():
username = self._proxyUsernameEntry.get_text()
password = self._proxyPasswordEntry.get_text()
else:
username = None
password = None
proxy = ProxyString(url=url, username=username, password=password)
self.proxyUrl = proxy.url
else:
self.proxyUrl = ""
self.window.destroy()
def on_proxy_enable_toggled(self, button, *args):
self._proxyInfoBox.set_sensitive(button.get_active())
if button.get_active():
self.set_status(self._proxyValidate)
else:
self._proxyOkButton.set_sensitive(True)
def on_proxy_auth_toggled(self, button, *args):
self._proxyAuthBox.set_sensitive(button.get_active())
self._proxyValidate.update_check_status()
def refresh(self):
GUIObject.refresh(self)
if not self.proxyUrl:
self._proxyCheck.set_active(False)
self.on_proxy_enable_toggled(self._proxyCheck)
self._authCheck.set_active(False)
self.on_proxy_auth_toggled(self._authCheck)
return
try:
proxy = ProxyString(self.proxyUrl)
if proxy.username:
self._proxyUsernameEntry.set_text(proxy.username)
if proxy.password:
self._proxyPasswordEntry.set_text(proxy.password)
self._proxyURLEntry.set_text(proxy.noauth_url)
except ProxyStringError as e:
log.error("Failed to parse proxy for ProxyDialog.refresh %s: %s", self.proxyUrl, e)
return
self._proxyCheck.set_active(True)
self._authCheck.set_active(bool(proxy.username or proxy.password))
self.on_proxy_enable_toggled(self._proxyCheck)
self.on_proxy_auth_toggled(self._authCheck)
def run(self):
self.window.run()
class MediaCheckDialog(GUIObject):
builderObjects = ["mediaCheckDialog"]
mainWidgetName = "mediaCheckDialog"
uiFile = "spokes/source.glade"
def __init__(self, data):
GUIObject.__init__(self, data)
self.progressBar = self.builder.get_object("mediaCheck-progressBar")
self._pid = None
def _checkisoEndsCB(self, pid, status):
doneButton = self.builder.get_object("doneButton")
verifyLabel = self.builder.get_object("verifyLabel")
if os.WIFSIGNALED(status):
pass
elif status == 0:
verifyLabel.set_text(_("This media is good to install from."))
else:
verifyLabel.set_text(_("This media is not good to install from."))
self.progressBar.set_fraction(1.0)
doneButton.set_sensitive(True)
GLib.spawn_close_pid(pid)
self._pid = None
def _checkisoStdoutWatcher(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, devicePath):
(retval, self._pid, _stdin, stdout, _stderr) = \
GLib.spawn_async_with_pipes(None, ["checkisomd5", "--gauge", devicePath], [],
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.
GLib.child_watch_add(self._pid, self._checkisoEndsCB)
# This function watches the process's stdout.
GLib.io_add_watch(stdout, GLib.IOCondition.IN|GLib.IOCondition.HUP, self._checkisoStdoutWatcher)
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/source.glade"
def __init__(self, data):
GUIObject.__init__(self, data)
self._chooser = self.builder.get_object("isoChooserDialog")
# pylint: disable=arguments-differ
def refresh(self, currentFile=""):
GUIObject.refresh(self)
self._chooser.connect("current-folder-changed", self.on_folder_changed)
self._chooser.set_filename(constants.ISO_DIR + "/" + currentFile)
def run(self, dev):
retval = None
unmount = not dev.format.status
mounts = get_mount_paths(dev.path)
# 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
dev.format.mount(mountpoint=constants.ISO_DIR)
# If any directory was chosen, return that. Otherwise, return None.
rc = self.window.run()
if rc == 1:
f = self._chooser.get_filename()
if f:
retval = f.replace(constants.ISO_DIR, "")
if unmount:
dev.format.unmount()
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):
builderObjects = ["isoChooser", "isoFilter", "partitionStore", "sourceWindow", "dirImage", "repoStore"]
mainWidgetName = "sourceWindow"
uiFile = "spokes/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._currentIsoFile = None
self._ready = False
self._error = False
self._proxyUrl = ""
self._proxyChange = False
self._cdrom = None
def apply(self):
# If askmethod was provided on the command line, entering the source
# spoke wipes that out.
if flags.askmethod:
flags.askmethod = False
payloadMgr.restartThread(self.storage, self.data, self.payload, self.instclass,
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
"""
import copy
old_source = copy.deepcopy(self.data.method)
if self._autodetectButton.get_active():
if not self._cdrom:
return False
self.data.method.method = "cdrom"
self.payload.install_device = self._cdrom
if old_source.method == "cdrom":
# XXX maybe we should always redo it for cdrom in case they
# switched disks
return False
elif self._isoButton.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.
part = self._get_selected_partition()
if not part or not self._currentIsoFile:
return False
self.data.method.method = "harddrive"
self.data.method.partition = part.name
# The / gets stripped off by payload.ISOImage
self.data.method.dir = "/" + self._currentIsoFile
if (old_source.method == "harddrive" and
self.storage.devicetree.resolveDevice(old_source.partition) == part and
old_source.dir in [self._currentIsoFile, "/" + self._currentIsoFile]):
return False
# Make sure anaconda doesn't touch this device.
part.protected = True
self.storage.config.protectedDevSpecs.append(part.name)
elif self._mirror_active():
# this preserves the url for later editing
self.data.method.method = None
self.data.method.proxy = self._proxyUrl
if not old_source.method and self.payload.baseRepo and \
not self._proxyChange:
return False
elif self._http_active() or self._ftp_active():
url = self._urlEntry.get_text().strip()
mirrorlist = False
# 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. yum 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 self._ftp_active() and not url.startswith("ftp://"):
url = "ftp://" + url
elif self._protocolComboBox.get_active_id() == PROTOCOL_HTTP and not url.startswith("http://"):
url = "http://" + url
mirrorlist = self._mirrorlistCheckbox.get_active()
elif self._protocolComboBox.get_active_id() == PROTOCOL_HTTPS and not url.startswith("https://"):
url = "https://" + url
mirrorlist = self._mirrorlistCheckbox.get_active()
if old_source.method == "url" and not self._proxyChange and \
((not mirrorlist and old_source.url == url) or \
(mirrorlist and old_source.mirrorlist == url)):
return False
self.data.method.method = "url"
self.data.method.proxy = self._proxyUrl
if mirrorlist:
self.data.method.mirrorlist = url
self.data.method.url = ""
else:
self.data.method.url = url
self.data.method.mirrorlist = ""
elif self._nfs_active():
url = self._urlEntry.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)
gtk_call_once(self.set_warning, _("Failed to set up installation source; check the repo url"))
self._error = True
return
self.data.method.opts = self.builder.get_object("nfsOptsEntry").get_text() or ""
if (old_source.method == "nfs" and
old_source.server == self.data.method.server and
old_source.dir == self.data.method.dir and
old_source.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_source.method == "harddrive" and old_source.partition:
self._currentIsoFile = None
self._isoChooserButton.set_label(self._origIsoChooserButton)
self._isoChooserButton.set_use_underline(True)
if old_source.partition in self.storage.config.protectedDevSpecs:
self.storage.config.protectedDevSpecs.remove(old_source.partition)
dev = self.storage.devicetree.getDeviceByName(old_source.partition)
if dev:
dev.protected = False
self._proxyChange = False
return True
@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.baseRepo:
return False
else:
return not self._error and self.ready and (self.data.method.method or self.payload.baseRepo)
@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.baseRepo:
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
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 == "harddrive":
if not self._currentIsoFile:
return _("Error setting up ISO file")
return os.path.basename(self._currentIsoFile)
elif self.payload.baseRepo:
return _("Closest mirror")
else:
return _("Nothing selected")
def _grabObjects(self):
self._autodetectButton = self.builder.get_object("autodetectRadioButton")
self._autodetectBox = self.builder.get_object("autodetectBox")
self._autodetectDeviceLabel = self.builder.get_object("autodetectDeviceLabel")
self._autodetectLabel = self.builder.get_object("autodetectLabel")
self._isoButton = self.builder.get_object("isoRadioButton")
self._isoBox = self.builder.get_object("isoBox")
self._networkButton = self.builder.get_object("networkRadioButton")
self._networkBox = self.builder.get_object("networkBox")
self._urlEntry = self.builder.get_object("urlEntry")
self._protocolComboBox = self.builder.get_object("protocolComboBox")
self._isoChooserButton = self.builder.get_object("isoChooserButton")
self._origIsoChooserButton = self._isoChooserButton.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._urlCheck = self.add_check(self._urlEntry, self._checkURLEntry)
self._urlCheck.enabled = False
self._mirrorlistCheckbox = self.builder.get_object("mirrorlistCheckbox")
self._noUpdatesCheckbox = self.builder.get_object("noUpdatesCheckbox")
self._verifyIsoButton = self.builder.get_object("verifyIsoButton")
# addon repo objects
self._repoEntryBox = self.builder.get_object("repoEntryBox")
self._repoStore = self.builder.get_object("repoStore")
self._repoSelection = self.builder.get_object("repoSelection")
self._repoNameEntry = self.builder.get_object("repoNameEntry")
self._repoProtocolComboBox = self.builder.get_object("repoProtocolComboBox")
self._repoUrlEntry = self.builder.get_object("repoUrlEntry")
self._repoMirrorlistCheckbox = self.builder.get_object("repoMirrorlistCheckbox")
self._repoProxyUrlEntry = self.builder.get_object("repoProxyUrlEntry")
self._repoProxyUsernameEntry = self.builder.get_object("repoProxyUsernameEntry")
self._repoProxyPasswordEntry = self.builder.get_object("repoProxyPasswordEntry")
self._repoView = self.builder.get_object("repoTreeView")
# 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._duplicateRepoCheck = InputCheckHandler.add_check(self, self._repoStore, self._checkDuplicateRepos)
# Create dictionaries for the checks on fields in individual repos
# These checks will be added and removed as repos are added and removed from repoStore
self._repoNameChecks = {}
self._repoURLChecks = {}
self._repoProxyChecks = {}
# updates option container
self._updatesBox = self.builder.get_object("updatesBox")
self._proxyButton = self.builder.get_object("proxyButton")
self._nfsOptsBox = self.builder.get_object("nfsOptsBox")
def initialize(self):
NormalSpoke.initialize(self)
self._grabObjects()
# 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._autodetectButton.connect("toggled", self.on_source_toggled, self._autodetectBox)
self._isoButton.connect("toggled", self.on_source_toggled, self._isoBox)
self._networkButton.connect("toggled", self.on_source_toggled, self._networkBox)
self._networkButton.connect("toggled", self._updateURLEntryCheck)
# Show or hide the updates option based on the installclass
if self.instclass.installUpdates:
really_show(self._updatesBox)
else:
really_hide(self._updatesBox)
self._repoNameWarningBox = self.builder.get_object("repoNameWarningBox")
self._repoNameWarningLabel = self.builder.get_object("repoNameWarningLabel")
threadMgr.add(AnacondaThread(name=constants.THREAD_SOURCE_WATCHER, target=self._initialize))
# Register listeners for payload events
payloadMgr.addListener(payloadMgr.STATE_START, self._payload_refresh)
payloadMgr.addListener(payloadMgr.STATE_STORAGE, self._probing_storage)
payloadMgr.addListener(payloadMgr.STATE_GROUP_MD, self._downloading_package_md)
payloadMgr.addListener(payloadMgr.STATE_FINISHED, self._payload_finished)
payloadMgr.addListener(payloadMgr.STATE_ERROR, self._payload_error)
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__, _("Probing storage..."))
def _downloading_package_md(self):
# Reset the error state from previous payloads
self._error = False
hubQ.send_message(self.__class__.__name__, _(METADATA_DOWNLOAD_MESSAGE))
def _payload_finished(self):
hubQ.send_ready("SoftwareSelectionSpoke", False)
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):
gtk_call_once(self.set_warning, _("Failed to set up installation source; check the repo url"))
else:
gtk_call_once(self.set_warning, _("Failed to set up installation source; check the repo url and proxy settings"))
hubQ.send_ready(self.__class__.__name__, False)
def _initialize(self):
threadMgr.wait(constants.THREAD_PAYLOAD)
added = False
# If there's no fallback mirror to use, we should just disable that option
# in the UI.
if not self.payload.mirrorEnabled:
model = self._protocolComboBox.get_model()
itr = model.get_iter_first()
while itr and model[itr][self._protocolComboBox.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 = opticalInstallMedia(self.storage.devicetree)
if self._cdrom:
fire_gtk_action(self._autodetectDeviceLabel.set_text, _("Device: %s") % self._cdrom.name)
fire_gtk_action(self._autodetectLabel.set_text, _("Label: %s") % (getattr(self._cdrom.format, "label", "") or ""))
added = True
if self.data.method.method == "harddrive":
self._currentIsoFile = self.payload.ISOImage
# These UI elements default to not being showable. If optical install
# media were found, mark them to be shown.
if added:
gtk_call_once(self._autodetectBox.set_no_show_all, False)
gtk_call_once(self._autodetectButton.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_repoStore()
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)
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":
methodDev = self.storage.devicetree.resolveDevice(self.data.method.partition)
for dev in potentialHdisoSources(self.storage.devicetree):
# path model size format type uuid of format
dev_info = { "model" : self._sanitize_model(dev.disk.model),
"path" : dev.path,
"size" : dev.size,
"format": dev.format.name or "",
"label" : dev.format.label or dev.format.uuid or ""
}
# 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 dev_info["label"] != "":
dev_info["label"] = "\n" + dev_info["label"]
store.append([dev, "%(model)s %(path)s (%(size)s) %(format)s %(label)s" % dev_info])
if self.data.method.method == "harddrive" and dev == methodDev:
active = idx
added = True
idx += 1
# Again, only display these widgets if an HDISO source was found.
self._isoBox.set_no_show_all(not added)
self._isoBox.set_visible(added)
self._isoButton.set_no_show_all(not added)
self._isoButton.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._protocolComboBox.set_active_id(PROTOCOL_MIRROR)
self._urlEntry.set_sensitive(False)
self._updateURLEntryCheck()
# Set up the default state of UI elements.
if self.data.method.method == "url":
self._networkButton.set_active(True)
proto = self.data.method.url or self.data.method.mirrorlist
if proto.startswith("http:"):
self._protocolComboBox.set_active_id(PROTOCOL_HTTP)
l = 7
elif proto.startswith("https:"):
self._protocolComboBox.set_active_id(PROTOCOL_HTTPS)
l = 8
elif proto.startswith("ftp:"):
self._protocolComboBox.set_active_id(PROTOCOL_FTP)
l = 6
else:
self._protocolComboBox.set_active_id(PROTOCOL_HTTP)
l = 0
self._urlEntry.set_sensitive(True)
self._urlEntry.set_text(proto[l:])
self._updateURLEntryCheck()
self._mirrorlistCheckbox.set_active(bool(self.data.method.mirrorlist))
self._proxyUrl = self.data.method.proxy
elif self.data.method.method == "nfs":
self._networkButton.set_active(True)
self._protocolComboBox.set_active_id(PROTOCOL_NFS)
self._urlEntry.set_text("%s:%s" % (self.data.method.server, self.data.method.dir))
self._urlEntry.set_sensitive(True)
self._updateURLEntryCheck()
self.builder.get_object("nfsOptsEntry").set_text(self.data.method.opts or "")
elif self.data.method.method == "harddrive":
self._isoButton.set_active(True)
self._isoBox.set_sensitive(True)
self._verifyIsoButton.set_sensitive(True)
if self._currentIsoFile:
self._isoChooserButton.set_label(os.path.basename(self._currentIsoFile))
else:
self._isoChooserButton.set_label("")
self._isoChooserButton.set_use_underline(False)
else:
# No method was given in advance, so now we need to make a sensible
# guess. Go with autodetected media if that was provided, and then
# fall back to closest mirror.
if not self._autodetectButton.get_no_show_all():
self._autodetectButton.set_active(True)
self.data.method.method = "cdrom"
else:
self._networkButton.set_active(True)
self.data.method.method = None
self._proxyUrl = self.data.method.proxy
self._setup_no_updates()
# Setup the addon repos
self._reset_repoStore()
if self.data.method.method == "harddrive" and \
get_mount_device(constants.DRACUT_ISODIR) == get_mount_device(constants.DRACUT_REPODIR):
# If the stage2 image is mounted from an HDISO source, there's really
# no way we can tear down that source to allow the user to change it.
# Thus, this portion of the spoke should be insensitive.
for widget in [self._autodetectButton, self._autodetectBox, self._isoButton,
self._isoBox, self._networkButton, self._networkBox]:
widget.set_sensitive(False)
widget.set_tooltip_text(_("The installation source is in use by the installer and cannot be changed."))
else:
# Then, some widgets get enabled/disabled/greyed out depending on
# how others are set up. We can use the signal handlers to handle
# that condition here too.
self.on_protocol_changed(self._protocolComboBox)
def _setup_no_updates(self):
""" Setup the state of the No Updates checkbox.
If closest mirror is not selected, check it.
If closest mirror is selected, and "updates" repo is enabled,
uncheck it.
"""
self._updatesBox.set_sensitive(self._mirror_active())
active = not self._mirror_active() or not self.payload.isRepoEnabled("updates")
self._noUpdatesCheckbox.set_active(active)
@property
def showable(self):
return isinstance(self.payload, PackagePayload)
def _mirror_active(self):
return self._protocolComboBox.get_active_id() == PROTOCOL_MIRROR
def _http_active(self):
return self._protocolComboBox.get_active_id() in [PROTOCOL_HTTP, PROTOCOL_HTTPS]
def _ftp_active(self):
return self._protocolComboBox.get_active_id() == PROTOCOL_FTP
def _nfs_active(self):
return self._protocolComboBox.get_active_id() == PROTOCOL_NFS
def _get_selected_partition(self):
store = self.builder.get_object("partitionStore")
combo = self.builder.get_object("isoPartitionCombo")
selected = combo.get_active()
if selected == -1:
return None
else:
return store[selected][0]
def _sanitize_model(self, model):
return model.replace("_", " ")
# Input checks
# This method is shared by the checks on urlEntry and repoUrlEntry
def _checkURL(self, inputcheck, combo):
url_string = self.get_input(inputcheck.input_obj).strip()
# If this is HTTP/HTTPS/FTP, use the URL_PARSE regex
combo_protocol = combo.get_active_id()
if combo_protocol in (PROTOCOL_HTTP, PROTOCOL_HTTPS, PROTOCOL_FTP):
if not url_string:
return _("URL is empty")
m = URL_PARSE.match(url_string)
if not m:
return _("Invalid URL")
# If there is a protocol in the URL, and the protocol matches the
# combo box, just remove it. This makes it more convenient to paste
# in URLs. It'll probably freak out people who are typing out http://
# in the box themselves, but why would you do that? Don't do that.
# If the protocols don't match, complain.
url_protocol = m.group('protocol')
if url_protocol:
if (url_protocol == 'http://' and combo_protocol == PROTOCOL_HTTP) or \
(url_protocol == 'https://' and combo_protocol == PROTOCOL_HTTPS) or \
(url_protocol == 'ftp://' and combo_protocol == PROTOCOL_FTP):
# Disable the check to block a recursive check call
inputcheck.enabled = False
inputcheck.input_obj.set_text(url_string[len(url_protocol):])
inputcheck.enabled = True
else:
return _("Protocol in URL does not match selected protocol")
elif combo_protocol == PROTOCOL_NFS:
if not url_string:
return _("NFS server is empty")
# Make sure the part before the colon looks like a hostname,
# and that the path is not empty
host, _colon, path = url_string.partition(':')
if not re.match('^' + HOSTNAME_PATTERN_WITHOUT_ANCHORS + '$', host):
return _("Invalid host name")
if not path:
return _("Remote directory is required")
return InputCheck.CHECK_OK
def _checkURLEntry(self, inputcheck):
return self._checkURL(inputcheck, self._protocolComboBox)
def _checkRepoURL(self, inputcheck):
return self._checkURL(inputcheck, self._repoProtocolComboBox)
# Update the check on urlEntry when the sensitity or selected protocol changes
def _updateURLEntryCheck(self, *args):
self._urlCheck.enabled = self._urlEntry.is_sensitive()
self._urlCheck.update_check_status()
# Force a status update to clear any disabled errors
self.set_status(self._urlCheck)
def _checkDuplicateRepos(self, inputcheck):
repo_names = [r[REPO_OBJ].name for r in inputcheck.input_obj]
if len(repo_names) != len(frozenset(repo_names)):
return _("Duplicate repository names.")
return InputCheck.CHECK_OK
def _checkRepoName(self, inputcheck):
repo_name = self.get_input(inputcheck.input_obj).strip()
if not repo_name:
return _("Empty repository name")
if not REPO_NAME_VALID.match(repo_name):
return _("Invalid repository name")
cnames = [constants.BASE_REPO_NAME] + \
self.payload.DEFAULT_REPOS + \
[r for r in self.payload.repos if r not in self.payload.addOns]
if repo_name in cnames:
return _("Repository name conflicts with internal repository name.")
return InputCheck.CHECK_OK
def _checkRepoProxy(self, inputcheck):
# If nfs is selected as the protocol, skip the proxy check
if self._repoProtocolComboBox.get_active_id() == PROTOCOL_NFS:
return InputCheck.CHECK_OK
# Empty proxies are OK, as long as the username and password are empty too
proxy_string = self.get_input(inputcheck.input_obj).strip()
username_set = self._repoProxyUsernameEntry.is_sensitive() and self._repoProxyUsernameEntry.get_text().strip()
password_set = self._repoProxyPasswordEntry.is_sensitive() and self._repoProxyPasswordEntry.get_text().strip()
if not (proxy_string or username_set or password_set):
return InputCheck.CHECK_OK
return _validateProxy(proxy_string, username_set, password_set)
# Signal handlers.
def on_source_toggled(self, button, relatedBox):
# When a radio button is clicked, this handler gets called for both
# the newly enabled button as well as the previously enabled (now