-
Notifications
You must be signed in to change notification settings - Fork 348
/
askvnc.py
171 lines (141 loc) · 6.02 KB
/
askvnc.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
# Ask vnc text spoke
#
# Copyright (C) 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.
#
import sys
from pyanaconda.core.configuration.anaconda import conf
from pyanaconda.ui.tui.spokes import NormalTUISpoke
from pyanaconda.core.constants import USEVNC, USETEXT, QUIT_MESSAGE
from pyanaconda.core.i18n import N_, _, C_
from pyanaconda.ui.tui import exception_msg_handler
from pyanaconda.core.util import execWithRedirect, ipmi_abort
from simpleline import App
from simpleline.event_loop.signals import ExceptionSignal
from simpleline.render.containers import ListColumnContainer
from simpleline.render.screen import InputState
from simpleline.render.screen_handler import ScreenHandler
from simpleline.render.adv_widgets import YesNoDialog
from simpleline.render.widgets import TextWidget
def exception_msg_handler_and_exit(signal, data):
"""Display an exception and exit so that we don't end up in a loop."""
exception_msg_handler(signal, data)
sys.exit(1)
class AskVNCSpoke(NormalTUISpoke):
"""
.. inheritance-diagram:: AskVNCSpoke
:parts: 3
"""
title = N_("VNC")
# This spoke is kinda standalone, not meant to be used with a hub
# We pass in some fake data just to make our parents happy
def __init__(self, data, storage=None, payload=None, message=""):
super().__init__(data, storage, payload)
self.input_required = True
self.initialize_start()
self._container = None
# The TUI hasn't been initialized with the message handlers yet. Add an
# exception message handler so that the TUI exits if anything goes wrong
# at this stage.
loop = App.get_event_loop()
loop.register_signal_handler(ExceptionSignal, exception_msg_handler_and_exit)
self._message = message
self._usevnc = False
self.initialize_done()
@property
def indirect(self):
return True
def refresh(self, args=None):
super().refresh(args)
self.window.add_with_separator(TextWidget(self._message))
self._container = ListColumnContainer(1, spacing=1)
# choices are
# USE VNC
self._container.add(TextWidget(_(USEVNC)), self._use_vnc_callback)
# USE TEXT
self._container.add(TextWidget(_(USETEXT)), self._use_text_callback)
self.window.add_with_separator(self._container)
def _use_vnc_callback(self, data):
self._usevnc = True
new_spoke = VNCPassSpoke(self.data, self.storage, self.payload)
ScreenHandler.push_screen_modal(new_spoke)
def _use_text_callback(self, data):
self._usevnc = False
def input(self, args, key):
"""Override input so that we can launch the VNC password spoke"""
if self._container.process_user_input(key):
self.apply()
return InputState.PROCESSED_AND_CLOSE
else:
# TRANSLATORS: 'q' to quit
if key.lower() == C_('TUI|Spoke Navigation', 'q'):
d = YesNoDialog(_(QUIT_MESSAGE))
ScreenHandler.push_screen_modal(d)
if d.answer:
ipmi_abort(scripts=self.data.scripts)
if conf.system.can_reboot:
execWithRedirect("systemctl", ["--no-wall", "reboot"])
else:
sys.exit(1)
else:
return super().input(args, key)
def apply(self):
self.data.vnc.enabled = self._usevnc
class VNCPassSpoke(NormalTUISpoke):
"""
.. inheritance-diagram:: VNCPassSpoke
:parts: 3
"""
def __init__(self, data, storage, payload, message=None):
super().__init__(data, storage, payload)
self.title = N_("VNC Password")
self._password = ""
if message:
self._message = message
else:
self._message = _("Please provide VNC password (must be six to eight characters long).\n"
"You will have to type it twice. Leave blank for no password")
@property
def indirect(self):
return True
@property
def completed(self):
return True # We're always complete
def refresh(self, args=None):
super().refresh(args)
self.window.add_with_separator(TextWidget(self._message))
def prompt(self, args=None):
"""Override prompt as password typing is special."""
p1 = self.get_user_input(_("Password: "), True)
p2 = self.get_user_input(_("Password (confirm): "), True)
if p1 != p2:
self._print_error_and_redraw(_("Passwords do not match!"))
elif 0 < len(p1) < 6:
self._print_error_and_redraw((_("The password must be at least "
"six characters long.")))
elif len(p1) > 8:
self._print_error_and_redraw(_("The password cannot be more than "
"eight characters long."))
else:
self._password = p1
self.apply()
self.close()
return None
def _print_error_and_redraw(self, msg):
print(msg)
self.redraw()
def apply(self):
self.data.vnc.password = self._password