aboutsummaryrefslogtreecommitdiff
path: root/examples/customization/pwd-cd-and-system/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'examples/customization/pwd-cd-and-system/utils.py')
-rw-r--r--examples/customization/pwd-cd-and-system/utils.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/examples/customization/pwd-cd-and-system/utils.py b/examples/customization/pwd-cd-and-system/utils.py
index e975e8869773..6e3462e1c863 100644
--- a/examples/customization/pwd-cd-and-system/utils.py
+++ b/examples/customization/pwd-cd-and-system/utils.py
@@ -1,8 +1,12 @@
"""Utility for changing directories and execution of commands in a subshell."""
-import os, shlex, subprocess
+import os
+import shlex
+import subprocess
# Store the previous working directory for the 'cd -' command.
+
+
class Holder:
"""Holds the _prev_dir_ class attribute for chdir() function."""
_prev_dir_ = None
@@ -15,6 +19,7 @@ class Holder:
def swap(cls, dir):
cls._prev_dir_ = dir
+
def chdir(debugger, args, result, dict):
"""Change the working directory, or cd to ${HOME}.
You can also issue 'cd -' to change to the previous working directory."""
@@ -33,10 +38,14 @@ def chdir(debugger, args, result, dict):
os.chdir(new_dir)
print "Current working directory: %s" % os.getcwd()
+
def system(debugger, command_line, result, dict):
"""Execute the command (a string) in a subshell."""
args = shlex.split(command_line)
- process = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ process = subprocess.Popen(
+ args,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
output, error = process.communicate()
retcode = process.poll()
if output and error: