diff options
author | Martin Sivak <msivak@redhat.com> | 2012-07-31 14:49:30 +0200 |
---|---|---|
committer | Martin Sivak <msivak@redhat.com> | 2012-08-06 13:32:21 +0200 |
commit | 7f96916bc05a1ed2ca4c1df8855762a3e6e4fd2f (patch) | |
tree | 0e969c0ec4aceea631fd80d6d4c658c8b162de8e /pyanaconda | |
parent | 1ddd40a0a01c5cffe519382cf5a9429bcedab7e0 (diff) | |
download | anaconda-7f96916bc05a1ed2ca4c1df8855762a3e6e4fd2f.tar.gz anaconda-7f96916bc05a1ed2ca4c1df8855762a3e6e4fd2f.tar.xz anaconda-7f96916bc05a1ed2ca4c1df8855762a3e6e4fd2f.zip |
Add the new Summary hub and Password TUI spokes + tools to test TUI stuff
Diffstat (limited to 'pyanaconda')
-rw-r--r-- | pyanaconda/ui/tui/hubs/summary.py | 5 | ||||
-rw-r--r-- | pyanaconda/ui/tui/spokes/password.py | 47 | ||||
l--------- | pyanaconda/ui/tui/tools/run-hub.py | 1 | ||||
-rwxr-xr-x | pyanaconda/ui/tui/tools/run-spoke.py | 105 |
4 files changed, 158 insertions, 0 deletions
diff --git a/pyanaconda/ui/tui/hubs/summary.py b/pyanaconda/ui/tui/hubs/summary.py new file mode 100644 index 000000000..9411e4ac7 --- /dev/null +++ b/pyanaconda/ui/tui/hubs/summary.py @@ -0,0 +1,5 @@ +from pyanaconda.ui.tui.hubs import TUIHub + +class SummaryHub(TUIHub): + title = "Install hub" + categories = ["source", "localization", "destination", "password"] diff --git a/pyanaconda/ui/tui/spokes/password.py b/pyanaconda/ui/tui/spokes/password.py new file mode 100644 index 000000000..db65b25e7 --- /dev/null +++ b/pyanaconda/ui/tui/spokes/password.py @@ -0,0 +1,47 @@ +from pyanaconda.ui.tui.spokes import NormalTUISpoke +from pyanaconda.ui.tui.simpleline import TextWidget +import getpass + +class PasswordSpoke(NormalTUISpoke): + title = "Set root password" + category = "password" + + def __init__(self, app, ksdata, storage, payload, instclass): + NormalTUISpoke.__init__(self, app, ksdata, storage, payload, instclass) + self._password = None + + @property + def completed(self): + return self._password is not None + + @property + def status(self): + if self._password is None: + return "Password is not set." + else: + return "Password is set." + + def refresh(self, args = None): + NormalTUISpoke.refresh(self, args) + + self._window += [TextWidget("Please select new root password. You will have to type it twice."), ""] + + return True + + def prompt(self): + """Overriden prompt as password typing is special.""" + p1 = getpass.getpass("Password: ") + p2 = getpass.getpass("Password (confirm): ") + + if p1 != p2: + print "Passwords do not match!" + else: + self._password = p1 + self.apply() + + self.close() + #return None + + def apply(self): + self.data.rootpw.password = self._password + self.data.rootpw.isCrypted = False diff --git a/pyanaconda/ui/tui/tools/run-hub.py b/pyanaconda/ui/tui/tools/run-hub.py new file mode 120000 index 000000000..4583bed4a --- /dev/null +++ b/pyanaconda/ui/tui/tools/run-hub.py @@ -0,0 +1 @@ +run-spoke.py
\ No newline at end of file diff --git a/pyanaconda/ui/tui/tools/run-spoke.py b/pyanaconda/ui/tui/tools/run-spoke.py new file mode 100755 index 000000000..d5e9c5730 --- /dev/null +++ b/pyanaconda/ui/tui/tools/run-spoke.py @@ -0,0 +1,105 @@ +#!/usr/bin/python + +import sys, os +import os.path + +# Check command line arguments +if len(sys.argv)<2: + print "Usage: $0 <spoke module name> [<spoke widget class>]" + sys.exit(1) + +# Logging always needs to be set up first thing, or there'll be tracebacks. +from pyanaconda import anaconda_log +anaconda_log.init() + +from pyanaconda.installclass import DefaultInstall +from pyanaconda.storage import Storage +from pyanaconda.threads import initThreading +from pyanaconda.packaging.yumpayload import YumPayload +from pyanaconda.platform import getPlatform +from pykickstart.version import makeVersion +from pyanaconda.ui.tui.simpleline import App +from pyanaconda.ui.tui import YesNoDialog + +# Don't worry with fcoe, iscsi, dasd, any of that crud. +from pyanaconda.flags import flags +flags.imageInstall = True +flags.testing = True + +initThreading() + +# Figure out the part we are about to show: hub/spoke? +# And get the name of the module which represents it +if os.path.basename(sys.argv[0]) == "run-spoke.py": + spokeModuleName = "pyanaconda.ui.tui.spokes.%s" % sys.argv[1] + from pyanaconda.ui.common import Spoke + spokeBaseClass = Spoke + spokeText = "spoke" + SpokeText = "Spoke" +elif os.path.basename(sys.argv[0]) == "run-hub.py": + spokeModuleName = "pyanaconda.ui.tui.hubs.%s" % sys.argv[1] + from pyanaconda.ui.common import Hub + spokeBaseClass = Hub + spokeText = "hub" + SpokeText = "Hub" +else: + print "You have to run this command as run-spoke.py or run-hub.py." + sys.exit(1) + +# Set default spoke class +spokeClass = None +spokeClassName = None + +# Load spoke specified on the command line +# If the spoke module was specified, but the spoke class was not, +# try to find it using class hierarchy +try: + spokeClassName = sys.argv[2] + __import__(spokeModuleName, fromlist = [spokeClassName]) + spokeModule = sys.modules[spokeModuleName] +except IndexError: + __import__(spokeModuleName) + spokeModule = sys.modules[spokeModuleName] + for k,v in vars(spokeModule).iteritems(): + try: + print k,v + if issubclass(v, spokeBaseClass) and v != spokeBaseClass: + spokeClassName = k + spokeClass = v + except TypeError: + pass + +if not spokeClass: + try: + spokeClass = getattr(spokeModule, spokeClassName) + except KeyError: + print "%s %s could not be found in %s" % (SpokeText, spokeClassName, spokeModuleName) + sys.exit(1) + + +print "Running %s %s from %s" % (spokeText, spokeClass, spokeModule) + +platform = getPlatform() +ksdata = makeVersion() +storage = Storage(data=ksdata, platform=platform) +storage.reset() +instclass = DefaultInstall() +app = App("TEST HARNESS", yes_or_no_question = YesNoDialog) + +payload = YumPayload(ksdata) +payload.setup(storage) +payload.install_log = sys.stdout + +spoke = spokeClass(app, ksdata, storage, payload, instclass) + +if not spoke.showable: + print "This %s is not showable, but I'll continue anyway." % spokeText + +app.schedule_screen(spoke) +app.run() + +if hasattr(spoke, "status"): + print "%s status:\n%s\n" % (SpokeText, spoke.status) +if hasattr(spoke, "completed"): + print "%s completed:\n%s\n" % (SpokeText, spoke.completed) +print "%s kickstart fragment:\n%s" % (SpokeText, ksdata) |