[PATCH v02] Clean up code for input handling in TUI spokes.
Samantha N. Bueno
sbueno+anaconda at redhat.com
Wed Sep 4 16:41:29 UTC 2013
Based on bcl/vpodzime's suggestions.
This is just some clean-up that needed to get done:
-- removes some unnecessary error catching
-- fixes up some typos
-- fixes some inconsistency with variable naming
---
pyanaconda/ui/tui/spokes/askvnc.py | 12 +++--
pyanaconda/ui/tui/spokes/software.py | 19 ++++----
pyanaconda/ui/tui/spokes/source.py | 77 ++++++++++++++---------------
pyanaconda/ui/tui/spokes/storage.py | 88 +++++++++++++++++-----------------
pyanaconda/ui/tui/spokes/time_spoke.py | 52 ++++++++++----------
5 files changed, 126 insertions(+), 122 deletions(-)
diff --git a/pyanaconda/ui/tui/spokes/askvnc.py b/pyanaconda/ui/tui/spokes/askvnc.py
index 9847874..36637bf 100644
--- a/pyanaconda/ui/tui/spokes/askvnc.py
+++ b/pyanaconda/ui/tui/spokes/askvnc.py
@@ -68,11 +68,15 @@ class AskVNCSpoke(NormalTUISpoke):
"""Override input so that we can launch the VNC password spoke"""
try:
- number = int(key)
- choice = self._choices[number -1]
- except (ValueError, KeyError, IndexError):
+ keyid = int(key) - 1
+ except ValueError:
return key
+ if 0 <= keyid < len(self._choices):
+ choice = self._choices[keyid]
+ else:
+ return None
+
if choice == USETEXT:
self._usevnc = False
else:
@@ -83,7 +87,7 @@ class AskVNCSpoke(NormalTUISpoke):
self.apply()
self.close()
- return None
+ return True
def apply(self):
self.data.vnc.enabled = self._usevnc
diff --git a/pyanaconda/ui/tui/spokes/software.py b/pyanaconda/ui/tui/spokes/software.py
index fc0298e..2462c4d 100644
--- a/pyanaconda/ui/tui/spokes/software.py
+++ b/pyanaconda/ui/tui/spokes/software.py
@@ -140,16 +140,19 @@ class SoftwareSpoke(NormalTUISpoke):
def input(self, args, key):
""" Handle the input; this chooses the desktop environment. """
- if key.lower() == "c" and self._selection in range(len(self.payload.environments)):
- self.apply()
-
try:
keyid = int(key) - 1
- if keyid in range(len(self.payload.environments)):
- self._selection = keyid
- return None
- except (ValueError, IndexError):
- return key
+ except ValueError:
+ if key.lower() == "c" and 0 <= self._selection < len(self.payload.environments):
+ self.apply()
+ self.close()
+ return True
+ else:
+ return key
+
+ if 0 <= keyid < len(self.payload.environments):
+ self._selection = keyid
+ return None
@property
def ready(self):
diff --git a/pyanaconda/ui/tui/spokes/source.py b/pyanaconda/ui/tui/spokes/source.py
index 776d179..48c32bd 100644
--- a/pyanaconda/ui/tui/spokes/source.py
+++ b/pyanaconda/ui/tui/spokes/source.py
@@ -143,46 +143,47 @@ class SourceSpoke(EditTUISpoke):
""" Handle the input; this decides the repo protocol. """
try:
num = int(key)
- if args == 2:
- # network install
- self._selection = num
- if self._selection == 1:
- # closest mirror
- self.data.method.method = None
- self.apply()
- self.close()
- return True
- elif self._selection in range(2, 5):
- self.data.method.method = "url"
- newspoke = SpecifyRepoSpoke(self.app, self.data, self.storage,
- self.payload, self.instclass, self._selection)
- self.app.switch_screen_modal(newspoke)
- self.apply()
- self.close()
- return True
- elif self._selection == 5:
- # nfs
- self.data.method.method = "nfs"
- newspoke = SpecifyNFSRepoSpoke(self.app, self.data, self.storage,
- self.payload, self.instclass, self._selection, self.errors)
- self.app.switch_screen_modal(newspoke)
- self.apply()
- self.close()
- return True
- else:
- if num == 1:
- # iso selected, just set some vars and return to main hub
- self.data.method.method = "cdrom"
- self.payload.install_device = self._cdrom
- self.apply()
- self.close()
- return True
- else:
- self.app.switch_screen(self, num)
- return None
- except (ValueError, IndexError):
+ except ValueError:
return key
+ if args == 2:
+ # network install
+ self._selection = num
+ if self._selection == 1:
+ # closest mirror
+ self.data.method.method = None
+ self.apply()
+ self.close()
+ return True
+ elif self._selection in range(2, 5):
+ self.data.method.method = "url"
+ newspoke = SpecifyRepoSpoke(self.app, self.data, self.storage,
+ self.payload, self.instclass, self._selection)
+ self.app.switch_screen_modal(newspoke)
+ self.apply()
+ self.close()
+ return True
+ elif self._selection == 5:
+ # nfs
+ self.data.method.method = "nfs"
+ newspoke = SpecifyNFSRepoSpoke(self.app, self.data, self.storage,
+ self.payload, self.instclass, self._selection, self.errors)
+ self.app.switch_screen_modal(newspoke)
+ self.apply()
+ self.close()
+ return True
+ else:
+ if num == 1:
+ # iso selected, just set some vars and return to main hub
+ self.data.method.method = "cdrom"
+ self.payload.install_device = self._cdrom
+ self.apply()
+ self.close()
+ return True
+ else:
+ self.app.switch_screen(self, num)
+ return None
+
def getRepoMetadata(self):
""" Pull down yum repo metadata """
try:
diff --git a/pyanaconda/ui/tui/spokes/storage.py b/pyanaconda/ui/tui/spokes/storage.py
index 51ce0ab..c12cfff 100644
--- a/pyanaconda/ui/tui/spokes/storage.py
+++ b/pyanaconda/ui/tui/spokes/storage.py
@@ -197,23 +197,22 @@ class StorageSpoke(NormalTUISpoke):
def input(self, args, key):
"""Grab the disk choice and update things"""
- if key == "c":
- if self.selected_disks:
- newspoke = AutoPartSpoke(self.app, self.data, self.storage,
- self.payload, self.instclass)
- self.app.switch_screen_modal(newspoke)
- self.apply()
- self.execute()
- self.close()
- return None
-
try:
- number = int(key)
- self._update_disk_list(self.disks[number -1])
+ keyid = int(key) - 1
+ self._update_disk_list(self.disks[keyid])
return None
-
- except (ValueError, KeyError, IndexError):
- return key
+ except (ValueError, IndexError):
+ if key.lower() == "c":
+ if self.selected_disks:
+ newspoke = AutoPartSpoke(self.app, self.data, self.storage,
+ self.payload, self.instclass)
+ self.app.switch_screen_modal(newspoke)
+ self.apply()
+ self.execute()
+ self.close()
+ return None
+ else:
+ return key
def apply(self):
if not flags.automatedInstall:
@@ -347,31 +346,31 @@ class AutoPartSpoke(NormalTUISpoke):
def input(self, args, key):
"""Grab the choice and update things"""
- if key == "c":
- newspoke = PartitionSchemeSpoke(self.app, self.data, self.storage,
- self.payload, self.instclass)
- self.app.switch_screen_modal(newspoke)
- self.apply()
- self.close()
- return False
-
try:
- number = int(key)
- self.clearPartType = PARTTYPES[self.parttypelist[number -1]]
- self.apply()
- self.close()
- return False
+ keyid = int(key) - 1
+ except ValueError:
+ if key.lower() == "c":
+ newspoke = PartitionSchemeSpoke(self.app, self.data, self.storage,
+ self.payload, self.instclass)
+ self.app.switch_screen_modal(newspoke)
+ self.apply()
+ self.close()
+ return True
+ else:
+ return key
- except (ValueError, KeyError, IndexError):
- return key
+ if 0 <= keyid < len(self.parttypelist):
+ self.clearPartType = PARTTYPES[self.parttypelist[keyid]]
+ self.apply()
+ return None
class PartitionSchemeSpoke(NormalTUISpoke):
- """ SPoke to select what partitioning scheme to use on disk(s). """
+ """ Spoke to select what partitioning scheme to use on disk(s). """
title = _("Partition Scheme Options")
category = "destination"
# set default FS to LVM, for consistency with graphical behavior
- _selection = 2
+ _selection = 1
def __init__(self, app, data, storage, payload, instclass):
NormalTUISpoke.__init__(self, app, data, storage, payload, instclass)
@@ -389,7 +388,7 @@ class PartitionSchemeSpoke(NormalTUISpoke):
for sch in schemelist:
box = CheckboxWidget(title="%i) %s" %(schemelist.index(sch) \
+ 1, sch), completed=(schemelist.index(sch) \
- + 1 == self._selection))
+ == self._selection))
self._window += [box, ""]
message = _("Select a partition scheme configuration.")
@@ -399,18 +398,19 @@ class PartitionSchemeSpoke(NormalTUISpoke):
def input(self, args, key):
""" Grab the choice and update things. """
- if key == "c" and self._selection:
- self.apply()
- self.close()
- return None
-
try:
- keyid = int(key)
- if keyid in range(0, 4):
- self._selection = keyid
- return None
- except (ValueError, IndexError, KeyError):
- return key
+ keyid = int(key) - 1
+ except ValueError:
+ if key.lower() == "c" and self._selection:
+ self.apply()
+ self.close()
+ return True
+ else:
+ return key
+
+ if 0 <= keyid < len(self.partschemes):
+ self._selection = keyid
+ return None
def apply(self):
""" Apply our selections. """
diff --git a/pyanaconda/ui/tui/spokes/time_spoke.py b/pyanaconda/ui/tui/spokes/time_spoke.py
index 7e3467b..24d5863 100644
--- a/pyanaconda/ui/tui/spokes/time_spoke.py
+++ b/pyanaconda/ui/tui/spokes/time_spoke.py
@@ -87,47 +87,43 @@ class TimeZoneSpoke(FirstbootSpokeMixIn, NormalTUISpoke):
def input(self, args, key):
try:
keyid = int(key) - 1
- if args:
- self._selection = "%s/%s" % (args, self._timezones[args][keyid])
+ except ValueError:
+ if key.lower().replace("_", " ") in self._lower_zones:
+ index = self._lower_zones.index(key.lower().replace("_", " "))
+ self._selection = self._zones[index]
self.apply()
self.close()
- else:
- if len(self._timezones[self._regions[keyid]]) == 1:
- self._selection = "%s/%s" % (self._regions[keyid],
- self._timezones[self._regions[keyid]][0])
+ return True
+ elif key.lower() in self._lower_regions:
+ index = self._lower_regions.index(key.lower())
+ if len(self._timezones[self._regions[index]]) == 1:
+ self._selection = "%s/%s" % (self._regions[index],
+ self._timezones[self._regions[index]][0])
self.apply()
self.close()
else:
- self.app.switch_screen(self, self._regions[keyid])
- return True
- except (ValueError, IndexError):
- pass
+ self.app.switch_screen(self, self._regions[id])
+ return True
+ elif key.lower() == "b":
+ self.app.switch_screen(self, None)
+ return True
+ else:
+ return key
- if key.lower().replace("_", " ") in self._lower_zones:
- index = self._lower_zones.index(key.lower().replace("_", " "))
- self._selection = self._zones[index]
+ if args:
+ self._selection = "%s/%s" % (args, self._timezones[args][keyid])
self.apply()
self.close()
- return True
-
- elif key.lower() in self._lower_regions:
- index = self._lower_regions.index(key.lower())
- if len(self._timezones[self._regions[index]]) == 1:
- self._selection = "%s/%s" % (self._regions[index],
- self._timezones[self._regions[index]][0])
+ else:
+ if len(self._timezones[self._regions[keyid]]) == 1:
+ self._selection = "%s/%s" % (self._regions[keyid],
+ self._timezones[self._regions[keyid]][0])
self.apply()
self.close()
else:
- self.app.switch_screen(self, self._regions[id])
- return True
-
- elif key.lower() == "b":
- self.app.switch_screen(self, None)
+ self.app.switch_screen(self, self._regions[keyid])
return True
- else:
- return key
-
def prompt(self, args = None):
return _("Please select the timezone.\nUse numbers or type names directly [b to region list, q to quit]: ")
--
1.7.11.7
More information about the anaconda-patches
mailing list