This repository has been archived by the owner on Nov 9, 2020. It is now read-only.
/
installmedia_ui.py
854 lines (708 loc) · 25.5 KB
/
installmedia_ui.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
#!/usr/bin/env python
#-*- coding: utf-8 -*-
###############################################################################
# Copyright (c) 2008-2009 VMware, Inc.
#
# This file is part of Weasel.
#
# Weasel is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation version 2 and no later version.
#
# Weasel is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 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 St, Fifth Floor, Boston, MA 02110-1301 USA.
#
import re
import urllib
import userchoices
import remote_files
import media
import cdutil
import usbmedia
from log import log
from packages import checkMediaRootIsValid
import networking.utils as net_utils
import textengine # for dispatch symbols
from textrunner import TextRunner, SubstepTransitionMenu as TransMenu
import networking.utils as netutils
title = "Install Media Selection"
askMediaChoiceText = """\
Choose the install media where ESX is located:
1) CD-ROM or USB Storage
2) Network File System (NFS)
3) World Wide Web (HTTP)
4) File Server (FTP)
Other actions:
<) Back
?) Help
"""
usbDeviceText = """\
Select the ESX installation media:
%(medialist)s
Other action:
<) Back
?) Help
"""
promptNfsServPathText = """\
Specify the Network File System (NFS) server and directory path
(or enter '<' to go back).
"""
promptHttpServText = """\
Specify the URL for the location of the ESX packages
(or enter '<' to go back).
Examples:
http://myserver/path_to_packages_xml_dir
https://myserver/isoroot
"""
promptFtpServText = """\
Specify the FTP location of the ESX packages.
(or enter '<' to go back).
(Non-anonymous user name and password will be prompted separately.)
"""
askProxyText = """\
Is a proxy server needed to access the server where the ESX
packages reside?
"""
promptProxyText = """\
Specify the name of the proxy server.
For example, proxy.mydomain.com
(The next screen will ask for a port number.)
"""
promptProxyPortText = """\
Specify the port number for the proxy server.
"""
askProxyUserText = """\
Does the proxy server require a user name and password?
"""
askNonAnonUserText = """\
Does the server require a user name and password?
"""
promptUserNamePasswordText = """\
Provide user name and password.
"""
promptProxyPortText = """\
Specify the port number for the proxy server.
"""
helpInstallMediaText = """\
Select one of the following install media:
* CD-ROM (can be other than one currently in use)
* USB storage or local hard drive
* Network File System (NFS) - server and directory path
* World Wide Web (WWW) - HTTP or HTTPS
* File Server (FTP)
WWW or FTP can go through a proxy server.
FTP may use an non-anonymous user and password.
"""
helpProxyText = """\
You may need to access installation files through a proxy server.
In that case, you will need the hostname or IP address of the proxy
server, and a port number.
For example, proxy.mydomain.com and port 8080.
"""
helpProxyUserText = """\
In some cases, accessing installation files through a proxy server may also
require a proxy user name and password.
Although the password is not visible in the installer session, it may be
visible on the network, depending on the protocol used.
"""
helpNonAnonUserText = """\
A user name and password may be required in some cases.
Although the password is not visible in the installer session, it may be
visible on the network, depending on the protocol used.
"""
usbHelpText = """\
Select the media to use for installing ESX. Use 'rescan' to perform
another scan for packages and 'eject' with a number to eject the media.
"""
errNetConnectText = """\
Network Error
There was an error trying to connect to the network server.
"""
errNetLinkText = """\
Network Adapter Error
The network adapter must be connected in order to access
FTP, HTTP, or NFS sources.
"""
errMiscText = """\
Error
There was an error requesting a file from the remote server.
"""
confirmMediaChoice = """\
Is the following information correct?
URL: %(url)s
"""
proxyMediaChoice = """\
Proxy: %s"""
SCROLL_LIMIT = 20
# ================ InstallMediaWindow: The Top Class ================
class InstallMediaWindow(TextRunner):
"""Select an alternate installation media for ESX.
"""
def __init__(self):
super(InstallMediaWindow, self).__init__()
self.start = self.askMediaChoice
self.substep = self.start
self.mediaLocation = userchoices.getMediaLocation()
# TODO: populate existing state
def askMediaChoice(self):
"Initial step."
ui = {
'title': title,
'body': askMediaChoiceText,
'menu': {
'1': self.setupUsb,
'2': self.setupMedia,
'3': self.setupMedia,
'4': self.setupMedia,
'<': self.stepBack,
'?': self.help,
}
}
self.setSubstepEnv(ui)
def setupUsb(self):
engine = SetupUsb()
result = engine.run()
assert result in (textengine.DISPATCH_BACK, textengine.DISPATCH_NEXT)
if result == textengine.DISPATCH_NEXT:
self.setSubstepEnv({'next': self.stepForward})
else:
self.setSubstepEnv({'next': self.start}) # start of installmedia
def setupMedia(self):
"""Set-up for currently implemented media.
Includes: NFS, HTTP, FTP.
"""
setups = {
# engine is class for setup, tSuffix is title suffix.
'2': {'engine': SetupNfs, 'tSuffix': "NFS"},
'3': {'engine': SetupHttp, 'tSuffix': "HTTP"},
'4': {'engine': SetupFtp, 'tSuffix': "FTP"},
}
# TODO: add title as parameter
engineType = setups[self.userinput]['engine']
title = 'Install Using ' + setups[self.userinput]['tSuffix']
# check for network link
chosenNics = userchoices.getCosNICs()
assert len(chosenNics) == 1
physicalNic = chosenNics[0]['device']
if not physicalNic.isLinkUp:
body = "%s\n%s" % (errNetLinkText, TransMenu.Back)
self.errorPushPop(title, body)
return
engine = engineType(title)
result = engine.run()
assert result in (textengine.DISPATCH_BACK, textengine.DISPATCH_NEXT)
if result == textengine.DISPATCH_NEXT:
self.setSubstepEnv({'next': self.stepForward})
else:
self.setSubstepEnv({'next': self.start}) # start of installmedia
def help(self):
"Emit help text."
self.helpPushPop(title+' (Help)', helpInstallMediaText+TransMenu.Back)
# ================ USB ================
class SetupUsb(TextRunner):
"Set-up for install media using USB."
def __init__(self):
super(SetupUsb, self).__init__()
media.runtimeActionUnmountMedia()
self.title = 'CD-ROM or USB Media'
self.substep = self.start
self.mediaFound = []
self.rescan()
def rescan(self):
textengine.render({'body': 'Probing for installation media...'})
self.mediaFound = (cdutil.findCdMedia(showAll=True) +
usbmedia.findUSBMedia(showAll=True))
self.setSubstepEnv( {'next': self.start} )
def start(self):
mediaTextList = []
for num, installMedia in enumerate(self.mediaFound):
if not installMedia.hasPackages:
contents = "No packages"
elif installMedia.isoPath:
contents = installMedia.isoPath
else:
contents = "Installation packages"
mediaTextList.append("%2d) %s\n"
" Contents: %s\n"
" Version: %s" % (
num + 1,
installMedia.getName(),
contents,
installMedia.version))
self.setScrollEnv(mediaTextList, SCROLL_LIMIT)
self.setSubstepEnv({'next' : self.scrollDisplay})
def scrollDisplay(self):
self.buildScrollDisplay(self.scrollable,
self.title,
self.chooseDevice,
"<number>: media, 'rescan', 'eject <N>'",
allowStepBack=True,
allowStepRestart=True)
def help(self):
"Emit help text."
self.helpPushPop(title+' (Help)', usbHelpText + TransMenu.Back)
def chooseDevice(self):
doEject = False
textOption = self.userinput.strip().lower()
if textOption == "rescan":
self.setSubstepEnv( {'next': self.rescan} )
return
m = re.match(r'eject (\d+)', textOption)
if m:
self.userinput = m.group(1)
doEject = True
try:
selected = self.getScrollChoice()
except (IndexError, ValueError), msg:
body = '\n'.join(['Input error', msg[0], TransMenu.Back])
self.errorPushPop(self.title +' (Update)', body)
return
mediaDesc = self.mediaFound[selected]
if doEject:
mediaDesc.eject()
self.setSubstepEnv( {'next': self.start} )
return
if mediaDesc.diskName:
userchoices.addDriveUse(mediaDesc.diskName, 'media')
userchoices.setMediaDescriptor(mediaDesc)
userchoices.clearMediaLocation()
try:
mediaDesc.mount()
except Exception, e:
log.exception("unable to mount media")
body = '\n'.join(['Unable to mount media. '
'Rescan and select the media again',
TransMenu.Back])
self.errorPushPop(self.title, body)
return
if not mediaDesc.hasPackages:
body = '\n'.join(['Select a valid installation medium.',
TransMenu.Back])
self.errorPushPop(self.title, body)
return
self.setSubstepEnv( {'next': self.stepForward } )
# ================ NFS ================
class SetupNfs(TextRunner):
"Set-up for install media on Network File System (NFS)"
def __init__(self, title):
super(SetupNfs, self).__init__()
self.start = self.getServer
self.substep = self.start
self.title = title
self.serverName = None
self.serverDir = None
def getServer(self):
ui = {
'title': self.title,
'body': promptNfsServPathText,
'menu': {
'*': self.checkServer,
'<': self.stepBack, },
'prompt': 'Server: ',
}
self.setSubstepEnv(ui)
def checkServer(self):
self.serverName = self.userinput
try:
net_utils.sanityCheckIPorHostname(self.serverName)
except ValueError, msg:
log.error(msg[0])
body = '\n'.join(['NFS Server Name Error', msg[0], TransMenu.Back])
self.errorPushPop(self.title, body)
return
self.setSubstepEnv({'next': self.getPath})
def getPath(self):
ui = {
'title': self.title,
'body': promptNfsServPathText,
'menu': {
'*': self.checkPath,
'<': self.stepBack, },
'prompt': 'Directory: ',
}
self.setSubstepEnv(ui)
def checkPath(self):
self.serverDir = self.userinput
if not self.serverDir.startswith('/'):
self.serverDir = '/' + self.serverDir
self.setSubstepEnv({'next': self.confirmSettings})
def confirmSettings(self):
ui = {
'title': self.title,
'body': confirmMediaChoice % {'url': self.serverName + \
self.serverDir} \
+ TransMenu.YesNoBack,
'menu': {
'1': self.commit,
'2': self.stepBack,
'<': self.stepBack
}
}
self.setSubstepEnv(ui)
def commit(self):
url = 'nfs://%s%s' % (self.serverName, self.serverDir)
if not checkMediaRootIsValid(url):
log.error('NFS textui failed on %s' % url)
body = "%s\n%s" % (errNetConnectText, TransMenu.Back)
self.errorPushPop(self.title, body)
return
userchoices.setMediaDescriptor(None)
userchoices.setMediaLocation(url)
self.setSubstepEnv({'next': self.stepForward})
# WE'RE DONE
# ================ HTTP ================
class SetupHttp(TextRunner):
"""Set-up for install media on World Wide Web via
Hypertext Transfer Protocol (HTTP)
"""
def __init__(self, title):
super(SetupHttp, self).__init__()
self.start = self.getHostURL
self.substep = self.start
self.title = title
# -------- host --------
def getHostURL(self):
ui = {
'title': self.title,
'body': promptHttpServText,
'menu': {
'*': self.checkHostURL,
'<': self.stepBack, },
}
self.setSubstepEnv(ui)
def checkHostURL(self):
self.url = self.userinput
try:
net_utils.sanityCheckUrl(self.url,
expectedProtocols=['http', 'https'])
except ValueError, msg:
log.error(msg[0])
body = '\n'.join(['Invalid URL', msg[0], TransMenu.Back])
self.errorPushPop(self.title, body)
return
self.setSubstepEnv({'next': self.askProxy})
# -------- check for proxy --------
def askProxy(self):
userchoices.unsetMediaProxy()
ui = {
'title': self.title,
'body': askProxyText + TransMenu.YesNoBackHelp,
'menu': {
'1': self.doProxy,
'2': self.confirmSettings,
'<': self.start,
'?': self.helpProxy,
}
}
self.setSubstepEnv(ui)
def doProxy(self):
proxy = SetupProxy(self.title, 'HTTP')
result = proxy.run()
assert result in (textengine.DISPATCH_BACK, textengine.DISPATCH_NEXT)
if result == textengine.DISPATCH_NEXT:
self.setSubstepEnv({'next': self.confirmSettings})
else:
self.setSubstepEnv({'next': self.start}) # start of installmedia
# -------- general stuff + commit --------
def confirmSettings(self):
confirmText = confirmMediaChoice % {'url': self.url}
try:
mediaProxy = userchoices.getMediaProxy()
proxyURL = mediaProxy['server'] + ':' + mediaProxy['port'] + '\n'
proxyText = proxyMediaChoice % proxyURL
confirmText += proxyText
except KeyError:
pass
ui = {
'title': self.title,
'body': confirmText + TransMenu.YesNoBack,
'menu': {
'1': self.commit,
'2': self.stepBack,
'<': self.stepBack,
}
}
self.setSubstepEnv(ui)
def commit(self):
if not checkMediaRootIsValid(self.url):
log.error('HTTP textui failed on %s' % self.url)
body = "%s\n%s" % (errNetConnectText, TransMenu.Back)
self.errorPushPop(self.title, body)
return
userchoices.setMediaDescriptor(None)
userchoices.setMediaLocation(self.url)
self.setSubstepEnv({'next': self.stepForward})
def helpProxy(self):
"Emit help text."
self.helpPushPop(self.title+' (Help)', helpProxyText + TransMenu.Back)
# ================ FTP ================
class SetupFtp(TextRunner):
"Set-up for install media on FTP."
def __init__(self, title):
super(SetupFtp, self).__init__()
self.start = self.getHostURL
self.substep = self.start
self.title = title
self.nonanonUser = ''
self.nonanonPass = ''
def getHostURL(self):
ui = {
'title': self.title,
'body': promptFtpServText,
'menu': {
'*': self.checkHostURL,
'<': self.stepBack, },
'prompt': 'ftp://',
}
self.setSubstepEnv(ui)
def checkHostURL(self):
self.hostpath = self.userinput
self.url = "ftp://" + self.hostpath # if no non-anon user, this is it.
try:
net_utils.sanityCheckUrl(self.url, expectedProtocols=['ftp'])
except ValueError, msg:
log.error(msg[0])
body = '\n'.join(['Invalid URL', msg[0], TransMenu.Back])
self.errorPushPop(self.title, body)
return
self.setSubstepEnv({'next': self.askNonAnonUser})
# -------- non-anonymous user --------
def askNonAnonUser(self):
ui = {
'title': self.title,
'body': askNonAnonUserText + TransMenu.YesNoBackHelp,
'menu': {
'1': self.doNonAnonUser,
'2': self.askProxy,
'<': self.start,
'?': self.helpNonAnonUser,
}
}
self.setSubstepEnv(ui)
def doNonAnonUser(self):
userinfo = SetupUserInfo(self.title + ' (Non-Anonymous User)')
result = userinfo.run()
assert result in (textengine.DISPATCH_BACK, textengine.DISPATCH_NEXT)
if result == textengine.DISPATCH_BACK:
self.setSubstepEnv({'next': self.start})
return
self.nonanonUser, self.nonanonPass = userinfo.getInfo()
encodedUser = urllib.quote(self.nonanonUser, '')
encodedPass = urllib.quote(self.nonanonPass, '')
self.url = "ftp://%s:%s@%s" % (encodedUser, encodedPass, self.hostpath)
self.setSubstepEnv({'next': self.askProxy})
# -------- check for proxy --------
def askProxy(self):
userchoices.unsetMediaProxy()
ui = {
'title': self.title,
'body': askProxyText + TransMenu.YesNoBackHelp,
'menu': {
'1': self.doProxy,
'2': self.confirmSettings,
'<': self.start,
'?': self.helpProxy,
}
}
self.setSubstepEnv(ui)
def doProxy(self):
proxy = SetupProxy(self.title, 'FTP')
result = proxy.run()
assert result in (textengine.DISPATCH_BACK, textengine.DISPATCH_NEXT)
if result == textengine.DISPATCH_NEXT:
self.setSubstepEnv({'next': self.confirmSettings})
else:
self.setSubstepEnv({'next': self.start}) # start of installmedia
# -------- general stuff + commit --------
def confirmSettings(self):
confirmText = confirmMediaChoice % \
{'url': netutils.cookPasswordInFileResourceURL(self.url)}
try:
mediaProxy = userchoices.getMediaProxy()
proxyURL = mediaProxy['server'] + ':' + mediaProxy['port'] + '\n'
proxyText = proxyMediaChoice % proxyURL
confirmText += proxyText
except KeyError:
pass
ui = {
'title': self.title,
'body': confirmText + TransMenu.YesNoBack,
'menu': {
'1': self.commit,
'2': self.stepBack,
'<': self.stepBack,
}
}
self.setSubstepEnv(ui)
def commit(self):
if not checkMediaRootIsValid(self.url):
log.error('FTP textui failed on %s' % self.url)
body = "%s\n%s" % (errNetConnectText, TransMenu.Back)
self.errorPushPop(self.title, body)
return
userchoices.setMediaDescriptor(None)
userchoices.setMediaLocation(self.url)
self.setSubstepEnv({'next': self.stepForward})
def helpNonAnonUser(self):
"Emit help text for non-anonymous user."
self.helpPushPop(self.title+' (Help)',
helpNonAnonUserText + TransMenu.Back)
def helpProxy(self):
"Emit help text for proxy."
self.helpPushPop(self.title+' (Help)',
helpProxyText + TransMenu.Back)
# ================ User Info ================
class SetupUserInfo(TextRunner):
"""Query user name and password.
Used to get proxy user and FTP anonymous user info.
"""
def __init__(self, title):
super(SetupUserInfo, self).__init__()
self.start = self.getUserName
self.substep = self.start
self.title = title
def getInfo(self):
"""Allow parent to retrieve user info after dialog is
completed."""
return (self.userName, self.password)
def getUserName(self):
ui = {
'title': self.title,
'body': promptUserNamePasswordText,
'menu': {
'*': self.saveUserName,
'<': self.stepBack, },
'prompt': 'User name: '
}
self.setSubstepEnv(ui)
def saveUserName(self):
self.userName = self.userinput.strip()
self.setSubstepEnv({'next': self.getPassword})
def getPassword(self):
ui = {
'title': self.title,
'body': promptUserNamePasswordText,
'menu': {
'*': self.savePassword,
'<': self.stepBack, },
'input': 'passwords',
'short': ['<','?']
}
self.setSubstepEnv(ui)
def savePassword(self):
trial1, trial2 = self.userinput
try:
if trial1 != trial2:
raise ValueError, "The two passwords entered do not match."
except ValueError, msg:
body = '\n'.join(['Password Input Error', msg[0], TransMenu.Back])
self.errorPushPop(self.title, body)
return
self.password = trial1
self.setSubstepEnv({'next': self.checkUserNamePassword})
def checkUserNamePassword(self):
if not self.userName or not self.password:
msg = "User name or password was empty."
body = '\n'.join([msg, TransMenu.Back])
ui = {
'title': self.title,
'body': body,
'menu': {'*': self.getUserName},
}
self.setSubstepEnv(ui)
return
self.setSubstepEnv({'next': self.done})
def done(self):
self.setSubstepEnv({'next': self.stepForward})
# ================ Proxy Server ================
class SetupProxy(TextRunner):
"Setup for proxy server."
def __init__(self, parentTitle, parentWord):
super(SetupProxy, self).__init__()
self.start = self.getProxy
self.substep = self.start
self.title = parentTitle + ' (Proxy)'
self.parentWord = parentWord
self.proxyUser = ''
self.proxyPass = ''
self.proxy = None
self.port = None
def getProxy(self):
ui = {
'title': self.title,
'body': promptProxyText,
'menu': {
'*': self.checkProxy,
'<': self.stepBack,
}
}
self.setSubstepEnv(ui)
def checkProxy(self):
proxy = self.userinput
try:
net_utils.sanityCheckIPorHostname(proxy)
except ValueError, msg:
log.error(msg[0])
subtitle = "%s Proxy Name Error" % self.parentWord
body = '\n'.join([subtitle, msg[0], TransMenu.Back])
self.errorPushPop(self.title, body)
return
self.proxy = proxy
self.setSubstepEnv({'next': self.getProxyPort})
def getProxyPort(self):
ui = {
'title': self.title,
'body': promptProxyPortText,
'menu': {
'*': self.checkProxyPort,
'<': self.stepBack, },
}
self.setSubstepEnv(ui)
def checkProxyPort(self):
port = self.userinput
try:
net_utils.sanityCheckPortNumber(port)
except ValueError, msg:
log.error(msg[0])
body = msg[0] + '\n' + TransMenu.Back
subtitle = "%s Proxy Port Number Error" % self.parentWord
body = '\n'.join([subtitle, msg[0], TransMenu.Back])
self.errorPushPop(self.title, body)
return
self.port = port
self.setSubstepEnv({'next': self.askProxyUser})
def askProxyUser(self):
ui = {
'title': self.title,
'body': askProxyUserText + TransMenu.YesNoBackHelp,
'menu': {
'1': self.doProxyUser,
'2': self.commit,
'<': self.start,
'?': self.helpProxyUser,
}
}
self.setSubstepEnv(ui)
def doProxyUser(self):
userinfo = SetupUserInfo(self.title)
result = userinfo.run()
assert result in (textengine.DISPATCH_BACK, textengine.DISPATCH_NEXT)
if result == textengine.DISPATCH_BACK:
self.setSubstepEnv({'next': self.start})
return
self.proxyUser, self.proxyPass = userinfo.getInfo()
self.setSubstepEnv({'next': self.commit})
def commit(self):
"Commit proxy info to userchoices."
userchoices.setMediaProxy(self.proxy, self.port,
self.proxyUser, self.proxyPass)
self.setSubstepEnv({'next': self.stepForward})
def helpProxyUser(self):
self.helpPushPop(title+' (Help)', helpProxyUserText + TransMenu.Back)
# vim: set sw=4 tw=80 :