[PATCH 1/2] Add a script mode that exits instead of looping

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "Brian C. Lane" <bcl@xxxxxxxxxx>

Instead of falling into an infinite loop like cmdline raise an error
with a useful description of the problem. Select it with -S or --script

This removes the infinite loops from cmdline mode, allowing it to
be subclassed for use with either cmdline or script mode.
---
 anaconda               |   16 +++++++--
 pyanaconda/__init__.py |    3 ++
 pyanaconda/cmdline.py  |   75 ++++++++++++++++++++----------------------------
 pyanaconda/script.py   |   52 +++++++++++++++++++++++++++++++++
 4 files changed, 98 insertions(+), 48 deletions(-)
 create mode 100644 pyanaconda/script.py

diff --git a/anaconda b/anaconda
index d8e9de5..4118471 100755
--- a/anaconda
+++ b/anaconda
@@ -197,6 +197,7 @@ def parseOptions(argv = None):
                   default="g")
     op.add_option("-G", "--graphical", dest="display_mode", action="store_const", const="g")
     op.add_option("-T", "--text", dest="display_mode", action="store_const", const="t")
+    op.add_option("-S", "--script", dest="display_mode", action="store_const", const="s")
 
     # Network
     op.add_option("--noipv4", action="store_true", default=False)
@@ -381,7 +382,7 @@ def check_memory(anaconda, opts, display_mode=None):
         sys.exit(1)
 
     # override display mode if machine cannot nicely run X
-    if display_mode not in ('t', 'c') and not flags.usevnc:
+    if display_mode not in ('t', 'c', 's') and not flags.usevnc:
         needed_ram += int(isys.GUI_INSTALL_EXTRA_RAM / 1024)
         reason = reason_graphical
 
@@ -489,8 +490,9 @@ def setupDisplay(anaconda, opts):
         # now determine if we're going to run in GUI or TUI mode
         #
         # if no X server, we have to use text mode
-        if not flags.livecdInstall and not iutil.isS390() and \
-           not os.access("/usr/bin/Xorg", os.X_OK):
+        if anaconda.displayMode == 'g' and not flags.livecdInstall \
+           and not iutil.isS390() \
+           and not os.access("/usr/bin/Xorg", os.X_OK):
              stdoutLog.warning(_("Graphical installation is not available. "
                                  "Starting text mode."))
              time.sleep(2)
@@ -812,7 +814,13 @@ if __name__ == "__main__":
 
     try:
         anaconda.dispatch.run()
-    except SystemExit, code:
+    except SystemExit as code:
         exitHandler(anaconda, code)
+    except RuntimeError as errtxt:
+        if anaconda.displayMode == 'c':
+            print errtxt
+            while True:
+                time.sleep(10000)
+        raise
 
 # vim:tw=78:ts=4:et:sw=4
diff --git a/pyanaconda/__init__.py b/pyanaconda/__init__.py
index 2e06346..2e88899 100644
--- a/pyanaconda/__init__.py
+++ b/pyanaconda/__init__.py
@@ -254,6 +254,9 @@ class Anaconda(object):
         if self.displayMode == 'c':
             from cmdline import InstallInterface
 
+        if self.displayMode == 's':
+            from script import InstallInterface
+
         self._intf = InstallInterface()
         return self._intf
 
diff --git a/pyanaconda/cmdline.py b/pyanaconda/cmdline.py
index f45ea93..eb05e98 100644
--- a/pyanaconda/cmdline.py
+++ b/pyanaconda/cmdline.py
@@ -84,13 +84,9 @@ class InstallInterface(InstallInterfaceBase):
         pass
 
     def reinitializeWindow(self, title, path, size, description):
-        print(_("Command line mode requires all choices to be specified in a "
-                "kickstart configuration file."))
-        print(title)
-
-        # don't exit
-        while 1:
-            time.sleep(5)
+        errtxt = _("(%s)\nCommand line mode requires all choices to be specified in a "
+                   "kickstart configuration file." % (title,))
+        raise RuntimeError(errtxt)
 
     def shutdown(self):
         pass
@@ -105,26 +101,17 @@ class InstallInterface(InstallInterfaceBase):
         return ProgressWindow(title, text, total, updpct, pulse)
 
     def kickstartErrorWindow(self, text):
-        s = _("The following error was found while parsing the "
-              "kickstart configuration file:\n\n%s") %(text,)
-        print(s)
-
-        while 1:
-            time.sleep(5)
+        errtxt = _("The following error was found while parsing the "
+                   "kickstart configuration file:\n\n%s") % (text,)
+        raise RuntimeError(errtxt)
 
     def messageWindow(self, title, text, type="ok", default = None,
                       custom_icon = None, custom_buttons = []):
         if type == "ok":
             print(text)
         else:
-            print(_("Command line mode requires all choices to be specified in a kickstart configuration file."))
-            print(title)
-            print(text)
-            print(type, custom_buttons)
-
-            # don't exit
-            while 1:
-                time.sleep(5)
+            errtxt = _("(%s)\n%s" % (title, text))
+            raise RuntimeError(errtxt)
 
     def detailedMessageWindow(self, title, text, longText=None, type="ok",
                               default=None, custom_buttons=None,
@@ -136,32 +123,24 @@ class InstallInterface(InstallInterfaceBase):
                            custom_buttons=custom_buttons, custom_icon=custom_icon)
 
     def passphraseEntryWindow(self, device):
-        print(_("Can't have a question in command line mode!"))
-        print("(passphraseEntryWindow: '%s')" % device)
-        # don't exit
-        while 1:
-            time.sleep(5)
+        errtxt = _("Can't have a question in command line mode!")
+        errtxt += "\n(passphraseEntryWindow: '%s')" % (device,)
+        raise RuntimeError(errtxt)
 
     def getLUKSPassphrase(self, passphrase = "", isglobal = False):
-        print(_("Can't have a question in command line mode!"))
-        print("(getLUKSPassphrase)")
-        # don't exit
-        while 1:
-            time.sleep(5)
+        errtxt = _("Can't have a question in command line mode!")
+        errtxt += "\n(getLUKSPassphrase)"
+        raise RuntimeError(errtxt)
 
     def enableNetwork(self):
-        print(_("Can't have a question in command line mode!"))
-        print("(enableNetwork)")
-        # don't exit
-        while 1:
-            time.sleep(5)
+        errtxt = "(enableNetwork)\n"
+        errtxt += _("Can't have a question in command line mode!")
+        raise RuntimeError(errtxt)
 
     def questionInitializeDASD(self, c, devs):
-        print(_("Can't have a question in command line mode!"))
-        print("questionInitializeDASD")
-        # don't exit
-        while 1:
-            time.sleep(5)
+        errtxt = "(questionInitializeDASD)\n"
+        errtxt += _("Can't have a question in command line mode!")
+        raise RuntimeError(errtxt)
 
     def mainExceptionWindow(self, shortText, longTextFile):
         print(shortText)
@@ -180,9 +159,8 @@ class InstallInterface(InstallInterfaceBase):
         if stepToClasses.has_key(step):
             stepToClasses[step](self.anaconda)
         else:
-            print("In interactive step %s, can't continue" %(step,))
-            while 1:
-                time.sleep(1)
+            errtxt = _("In interactive step can't continue. (%s)" %(step,))
+            raise RuntimeError(errtxt)
 
     def setInstallProgressClass(self, c):
         self.instProgress = c
@@ -210,3 +188,12 @@ class progressDisplay:
         if stripped != self.display:
             self.display = stripped
             print(self.display)
+
+def setupProgressDisplay(anaconda):
+    if anaconda.dir == DISPATCH_BACK:
+        anaconda.intf.setInstallProgressClass(None)
+        return DISPATCH_BACK
+    else:
+        anaconda.intf.setInstallProgressClass(progressDisplay())
+
+    return DISPATCH_FORWARD
diff --git a/pyanaconda/script.py b/pyanaconda/script.py
new file mode 100644
index 0000000..1775a2f
--- /dev/null
+++ b/pyanaconda/script.py
@@ -0,0 +1,52 @@
+#
+# script.py - non-interactive, script based anaconda interface
+#
+# Copyright (C) 2011
+# Red Hat, Inc.  All rights reserved.
+#
+# This program 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; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program 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 for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+# Author(s): Brian C. Lane <bcl@xxxxxxxxxx>
+#
+
+from installinterfacebase import InstallInterfaceBase
+import cmdline
+from cmdline import setupProgressDisplay
+
+import logging
+log = logging.getLogger("anaconda")
+
+stepToClasses = { "install" : "setupProgressDisplay",
+                  "complete": "Finished" }
+
+class InstallInterface(cmdline.InstallInterface):
+    def enableNetwork(self):
+        # Assume we want networking
+        return True
+
+    def display_step(self, step):
+        if stepToClasses.has_key(step):
+            s = "nextWin = %s" % (stepToClasses[step],)
+            exec s
+            nextWin(self.anaconda)
+        else:
+            errtxt = _("In interactive step can't continue. (%s)" % (step,))
+            print(errtxt)
+            raise RuntimeError(errtxt)
+
+def Finished(anaconda):
+    """ Install is finished. Lets just exit.
+    """
+    return 0
+
-- 
1.7.6.4

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list


[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux