[PATCH 2/4] Add a way to run shell when exception appears
Vratislav Podzimek
vpodzime at redhat.com
Tue Oct 8 12:31:22 UTC 2013
There may not be a way to get to a shell in text mode so we should provide it.
Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
---
meh/__init__.py | 3 ++-
meh/handler.py | 23 ++++++++++++++++++++---
meh/ui/text.py | 1 +
3 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/meh/__init__.py b/meh/__init__.py
index 7848f32..c952527 100644
--- a/meh/__init__.py
+++ b/meh/__init__.py
@@ -28,7 +28,8 @@ from collections import namedtuple
MAIN_RESPONSE_DEBUG = 0
MAIN_RESPONSE_SAVE = 1
MAIN_RESPONSE_QUIT = 2
-MAIN_RESPONSE_NONE = 3
+MAIN_RESPONSE_SHELL = 3
+MAIN_RESPONSE_NONE = 4
class ConfigError(Exception):
"""Exception class for the configuration related errors."""
diff --git a/meh/handler.py b/meh/handler.py
index 7bc1f3c..622f7fa 100644
--- a/meh/handler.py
+++ b/meh/handler.py
@@ -24,6 +24,7 @@ import signal
import sys
import report
import traceback
+import subprocess
import gettext
_ = lambda x: gettext.ldgettext("python-meh", x)
@@ -85,9 +86,11 @@ class ExceptionHandler(object):
"""
- responseHash = {MAIN_RESPONSE_QUIT: self.runQuit,
- MAIN_RESPONSE_DEBUG: self.runDebug,
- MAIN_RESPONSE_SAVE: self.runSave}
+ responseHash = { MAIN_RESPONSE_QUIT: self.runQuit,
+ MAIN_RESPONSE_DEBUG: self.runDebug,
+ MAIN_RESPONSE_SAVE: self.runSave,
+ MAIN_RESPONSE_SHELL: self.runShell,
+ }
# Quit if we got an exception when running pdb.
if isinstance(dump_info.exc_info.value, bdb.BdbQuit):
@@ -195,6 +198,20 @@ class ExceptionHandler(object):
pdb.post_mortem(exc_info.stack)
#no need to quit here, let's just get back to the main dialog
+ def runShell(self, exc_info):
+ """This method is called when user requests to run a shell. It may
+ be overridden by a subclass if specialized behavior is required to
+ run shell (e.g. TTY switching).
+
+ :type exc_info: an instance of the meh.ExceptionInfo class
+
+ """
+
+ print
+ print "Exit the shell to get back to the main menu"
+ proc = subprocess.Popen(["bash", "--login"], shell=True, cwd="/")
+ proc.wait()
+
def runSave(self, exc_info):
"""This method is called when the "Save" button is clicked. It may
be overridden by a subclass, but that's going to be a lot of work.
diff --git a/meh/ui/text.py b/meh/ui/text.py
index 989f3dd..7a28b3e 100644
--- a/meh/ui/text.py
+++ b/meh/ui/text.py
@@ -155,6 +155,7 @@ class MainExceptionWindow(TextWindow, AbstractMainExceptionWindow):
self._short_traceback = shortTraceback
self._menu_items = [(_("Report Bug"), MAIN_RESPONSE_SAVE),
(_("Debug"), MAIN_RESPONSE_DEBUG),
+ (_("Run shell"), MAIN_RESPONSE_SHELL),
(_("Quit"), MAIN_RESPONSE_QUIT)]
def run(self, *args, **kwargs):
--
1.7.11.7
More information about the anaconda-patches
mailing list