From 208d98a820df3a56da86e801027f0e702e04c2fe 2010-09-01 03:32:35 From: Fernando Perez Date: 2010-09-01 03:32:35 Subject: [PATCH] Remove shell hook and system_verbose magic. This is the first step of a cleanup and rationalization of our subprocess management, so we can use a single, uniform interface for subprocess execution across our codebase. --- diff --git a/IPython/config/default/ipython_config.py b/IPython/config/default/ipython_config.py index 5a6c2eb..1dbdc26 100644 --- a/IPython/config/default/ipython_config.py +++ b/IPython/config/default/ipython_config.py @@ -120,10 +120,6 @@ c = get_config() # c.InteractiveShell.separate_out = '' # c.InteractiveShell.separate_out2 = '' -# c.InteractiveShell.system_header = "IPython system call: " - -# c.InteractiveShell.system_verbose = True - # c.TerminalInteractiveShell.term_title = False # c.InteractiveShell.wildcards_case_sensitive = True diff --git a/IPython/core/hooks.py b/IPython/core/hooks.py index 5d8a2ac..2dc377e 100644 --- a/IPython/core/hooks.py +++ b/IPython/core/hooks.py @@ -46,16 +46,14 @@ import sys from IPython.core.error import TryNext import IPython.utils.io -from IPython.utils.process import shell # List here all the default hooks. For now it's just the editor functions # but over time we'll move here all the public API for user-accessible things. __all__ = ['editor', 'fix_error_editor', 'synchronize_with_editor', 'input_prefilter', 'shutdown_hook', 'late_startup_hook', - 'generate_prompt','shell_hook', - 'show_in_pager','pre_prompt_hook', 'pre_runcode_hook', - 'clipboard_get'] + 'generate_prompt', 'show_in_pager','pre_prompt_hook', + 'pre_runcode_hook', 'clipboard_get'] def editor(self,filename, linenum=None): """Open the default editor at the given filename and linenumber. @@ -220,12 +218,6 @@ def generate_prompt(self, is_continuation): return str(self.displayhook.prompt1) -def shell_hook(self,cmd): - """ Run system/shell command a'la os.system() """ - - shell(cmd, header=self.system_header, verbose=self.system_verbose) - - def show_in_pager(self,s): """ Run a string through pager """ # raising TryNext here will use the default paging functionality diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index ed7fd32..64d52b3 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -57,7 +57,7 @@ from IPython.utils.doctestreload import doctest_reload from IPython.utils.io import ask_yes_no, rprint from IPython.utils.ipstruct import Struct from IPython.utils.path import get_home_dir, get_ipython_dir, HomeDirError -from IPython.utils.process import getoutput, getoutputerror +from IPython.utils.process import system, getoutput, getoutputerror from IPython.utils.strdispatch import StrDispatch from IPython.utils.syspathcontext import prepended_to_syspath from IPython.utils.text import num_ini_spaces @@ -197,8 +197,6 @@ class InteractiveShell(Configurable, Magic): separate_in = SeparateStr('\n', config=True) separate_out = SeparateStr('', config=True) separate_out2 = SeparateStr('', config=True) - system_header = Str('IPython system call: ', config=True) - system_verbose = CBool(False, config=True) wildcards_case_sensitive = CBool(True, config=True) xmode = CaselessStrEnum(('Context','Plain', 'Verbose'), default_value='Context', config=True) @@ -1654,8 +1652,26 @@ class InteractiveShell(Configurable, Magic): #------------------------------------------------------------------------- def system(self, cmd): - """Make a system call, using IPython.""" - return self.hooks.shell_hook(self.var_expand(cmd, depth=2)) + """Call the given cmd in a subprocess.""" + # We do not support backgrounding processes because we either use + # pexpect or pipes to read from. Users can always just call + # os.system() if they really want a background process. + if cmd.endswith('&'): + raise OSError("Background processes not supported.") + + return system(self.var_expand(cmd, depth=2)) + + def getoutput(self, cmd): + """Get output (possibly including stderr) from a subprocess.""" + if cmd.endswith('&'): + raise OSError("Background processes not supported.") + return getoutput(self.var_expand(cmd, depth=2)) + + def getoutputerror(self, cmd): + """Get stdout and stderr from a subprocess.""" + if cmd.endswith('&'): + raise OSError("Background processes not supported.") + return getoutputerror(self.var_expand(cmd, depth=2)) #------------------------------------------------------------------------- # Things related to aliases @@ -2056,16 +2072,6 @@ class InteractiveShell(Configurable, Magic): # Utilities #------------------------------------------------------------------------- - def getoutput(self, cmd): - return getoutput(self.var_expand(cmd,depth=2), - header=self.system_header, - verbose=self.system_verbose) - - def getoutputerror(self, cmd): - return getoutputerror(self.var_expand(cmd,depth=2), - header=self.system_header, - verbose=self.system_verbose) - def var_expand(self,cmd,depth=0): """Expand python variables in a string. diff --git a/IPython/core/magic.py b/IPython/core/magic.py index b954308..8ba1ba9 100644 --- a/IPython/core/magic.py +++ b/IPython/core/magic.py @@ -614,23 +614,6 @@ Currently the magic system has the following functions:\n""" print "Automatic calling is:",['OFF','Smart','Full'][self.shell.autocall] - def magic_system_verbose(self, parameter_s = ''): - """Set verbose printing of system calls. - - If called without an argument, act as a toggle""" - - if parameter_s: - val = bool(eval(parameter_s)) - else: - val = None - - if self.shell.system_verbose: - self.shell.system_verbose = False - else: - self.shell.system_verbose = True - print "System verbose printing is:",\ - ['OFF','ON'][self.shell.system_verbose] - def magic_page(self, parameter_s=''): """Pretty print the object and display it through a pager.