Skip to content
Permalink
Browse files

add parameter --raw-output to many magic commands

  • Loading branch information...
sdpython committed Nov 1, 2015
1 parent 3a933b9 commit c26fb0a8102cefd100d72803093e841194a72838
@@ -149,7 +149,8 @@ def jsdf(self, line):

if not hasattr(self, "first_jsdf_call") or self.first_jsdf_call:
qgrid.nbinstall(overwrite=False)
qgrid.set_defaults(remote_js=args.remote_slick, precision=args.precision)
qgrid.set_defaults(remote_js=args.remote_slick,
precision=args.precision)
self.first_jsdf_call = False

if args is not None:
@@ -790,6 +790,11 @@ def hd_tail_stderr_parser():
type=int,
default=20,
help='number of lines to display')
parser.add_argument(
'--raw-output',
default=False,
action='store_true',
help='display raw text instead of HTML')
return parser

@line_magic
@@ -824,13 +829,21 @@ def hd_tail_stderr(self, line):
"ERROR",
'<b><font color="#DD0000">ERROR</font></b>')

if len(out) > 0:
lineo = out.split("\n")
shoo = "\n".join(_.strip("\n\r") for _ in lineo[-nbline:])
return HTML(
"<pre>\n%s\n</pre><br /><b>OUT:</b><br /><pre>\n%s\n</pre>" % (show, shoo))
if args.raw_output:
if len(out) > 0:
lieno = out.split("\n")
shoo = "\n".join(_.strip("\n\r") for _ in lineo[-nbline:])
return shoo
else:
return show
else:
return HTML("<pre>\n%s\n</pre><br />" % show)
if len(out) > 0:
lineo = out.split("\n")
shoo = "\n".join(_.strip("\n\r") for _ in lineo[-nbline:])
return HTML(
"<pre>\n%s\n</pre><br /><b>OUT:</b><br /><pre>\n%s\n</pre>" % (show, shoo))
else:
return HTML("<pre>\n%s\n</pre><br />" % show)

def _run_jython(self, cell, filename, func_name, args, true_jython=None):
"""
@@ -899,6 +912,11 @@ def runjython_parser():
'function_name',
type=str,
help='function name')
parser.add_argument(
'--raw-output',
default=False,
action='store_true',
help='display raw text instead of HTML')
parser.add_argument(
'args',
type=list,
@@ -930,11 +948,17 @@ def runjpython(self, line, cell=None):
func_name = args.function_name
args = args.args
out, err = self._run_jython(cell, filename, func_name, args, False)
if len(err) > 0:
return HTML(
'<font color="#DD0000">Error</font><br /><pre>\n%s\n</pre>' % err)
if args.raw_output:
if len(err) > 0:
return err
else:
return out
else:
return HTML('<pre>\n%s\n</pre>' % out)
if len(err) > 0:
return HTML(
'<font color="#DD0000">Error</font><br /><pre>\n%s\n</pre>' % err)
else:
return HTML('<pre>\n%s\n</pre>' % out)

@staticmethod
def jython_parser():
@@ -951,6 +975,11 @@ def jython_parser():
'function_name',
type=str,
help='function name')
parser.add_argument(
'--raw-output',
default=False,
action='store_true',
help='display raw text instead of HTML')
parser.add_argument(
'args',
type=list,
@@ -982,11 +1011,17 @@ def jython(self, line, cell=None):
func_name = args.function_name
args = args.args
out, err = self._run_jython(cell, filename, func_name, args, True)
if len(err) > 0:
return HTML(
'<font color="#DD0000">Error</font><br /><pre>\n%s\n</pre>' % err)
if args.raw_output:
if len(err) > 0:
return err
else:
return out
else:
return HTML('<pre>\n%s\n</pre>' % out)
if len(err) > 0:
return HTML(
'<font color="#DD0000">Error</font><br /><pre>\n%s\n</pre>' % err)
else:
return HTML('<pre>\n%s\n</pre>' % out)


def register_azure_magics(ip=None):
@@ -129,6 +129,11 @@ def pig_submit_parser():
type=str,
default="redirection.pig",
help='list of options for the job')
parser.add_argument(
'--raw-output',
default=False,
action='store_true',
help='display raw text instead of HTML')
parser.add_argument(
'-s',
'--stop_on_failure',
@@ -163,11 +168,18 @@ def pig_submit(self, line):
out, err = ssh.pig_submit(
pig, dependencies=pys, redirection=redirection, local=args.local, stop_on_failure=args.stop_on_failure)

if len(err) > 0 and (
len(out) == 0 or "ERROR" in err or "FATAL" in err or "Exception" in err):
return HTML("<pre>\n%s\n</pre>" % err)
if args.raw_output:
if len(err) > 0 and (
len(out) == 0 or "ERROR" in err or "FATAL" in err or "Exception" in err):
return err
else:
return out
else:
return HTML("<pre>\n%s\n</pre>" % out)
if len(err) > 0 and (
len(out) == 0 or "ERROR" in err or "FATAL" in err or "Exception" in err):
return HTML("<pre>\n%s\n</pre>" % err)
else:
return HTML("<pre>\n%s\n</pre>" % out)

@staticmethod
def hive_submit_parser():
@@ -186,6 +198,11 @@ def hive_submit_parser():
type=str,
default="redirection",
help='list of options for the job')
parser.add_argument(
'--raw-output',
default=False,
action='store_true',
help='display raw text instead of HTML')
return parser

@line_magic
@@ -203,11 +220,18 @@ def hive_submit(self, line):
out, err = ssh.hive_submit(
pig, redirection=args.redirection, local=args.local)

if len(err) > 0 and (
len(out) == 0 or "ERROR" in err or "FATAL" in err or "Exception" in err):
return HTML("<pre>\n%s\n</pre>" % err)
if args.raw_output:
if len(err) > 0 and (
len(out) == 0 or "ERROR" in err or "FATAL" in err or "Exception" in err):
return err
else:
return out
else:
return HTML("<pre>\n%s\n</pre>" % out)
if len(err) > 0 and (
len(out) == 0 or "ERROR" in err or "FATAL" in err or "Exception" in err):
return HTML("<pre>\n%s\n</pre>" % err)
else:
return HTML("<pre>\n%s\n</pre>" % out)

@staticmethod
def remote_py_parser():
@@ -231,6 +255,11 @@ def remote_py_parser():
type=str,
default='python',
help='change the interpreter, python by default')
parser.add_argument(
'--raw-output',
default=False,
action='store_true',
help='display raw text instead of HTML')
return parser

@line_magic
@@ -255,11 +284,17 @@ def remote_py(self, line):
cmd = exe + " " + dest + " " + args

out, err = ssh.execute_command(cmd, no_exception=True)
if len(err) > 0:
return HTML(
"<b>ERR:</b><br /><pre>\n%s\n</pre><b>OUT:</b><br /><pre>\n%s\n</pre>" % (err, out))
if args.raw_output:
if len(err) > 0:
return err
else:
return out
else:
return HTML("<pre>\n%s\n</pre>" % out)
if len(err) > 0:
return HTML(
"<b>ERR:</b><br /><pre>\n%s\n</pre><b>OUT:</b><br /><pre>\n%s\n</pre>" % (err, out))
else:
return HTML("<pre>\n%s\n</pre>" % out)

@staticmethod
def job_syntax_parser():
@@ -272,6 +307,11 @@ def job_syntax_parser():
'file',
type=str,
help='file name')
parser.add_argument(
'--raw-output',
default=False,
action='store_true',
help='display raw text instead of HTML')
return parser

@line_magic
@@ -290,11 +330,18 @@ def job_syntax(self, line):

ssh = self.get_connection()
out, err = ssh.pig_submit(filename, check=True, no_exception=True)
if len(err) > 0 and (
len(out) == 0 or "ERROR" in err or "FATAL" in err or "Exception" in err):
return HTML("<pre>\n%s\n</pre>" % err)
if args.raw_output:
if len(err) > 0 and (
len(out) == 0 or "ERROR" in err or "FATAL" in err or "Exception" in err):
return err
else:
return out
else:
return HTML("<pre>\n%s\n</pre>" % out)
if len(err) > 0 and (
len(out) == 0 or "ERROR" in err or "FATAL" in err or "Exception" in err):
return HTML("<pre>\n%s\n</pre>" % err)
else:
return HTML("<pre>\n%s\n</pre>" % out)

@staticmethod
def remote_open_parser():
@@ -385,6 +432,39 @@ def remote_cmd(self, line, cell=None):
else:
return HTML("<pre>\n%s\n</pre>" % out)

@line_cell_magic
def remote_cmd_text(self, line, cell=None):
"""
run a command on the remote machine and returns raw text (not HTML)
Example::
%remote_cmd_text ls
Or::
%%remote_cmd_text <something>
anything going to stdin
In the second case, if __PASSWORD__ is found, it will be replaced by the password stored in
workspace.
"""
if "--help" in line:
print("Usage: %remote_cmd_text <cmd>")
else:
ssh = self.get_connection()

if isinstance(cell, str):
cell = self._replace_params(cell)

out, err = ssh.execute_command(
line, no_exception=True, fill_stdin=cell)
if len(err) > 0 and (
len(out) == 0 or "ERROR" in err or "FATAL" in err or "Exception" in err):
return err
else:
return out

@staticmethod
def remote_up_parser():
"""
@@ -617,13 +697,20 @@ def shell_remote(self, line, cell=None):
"""
Defines ``%shell_remote`` and ``%%shell_remote``
"""
return HTML(self.shell_remote_text(line, cell))

@line_cell_magic
def shell_remote_text(self, line, cell=None):
"""
Defines ``%shell_remote_text`` and ``%%shell_remote_text``
"""
ssh = self.get_connection()
if cell is None:
out = ssh.send_recv_session(line)
else:
out = ssh.send_recv_session(cell)

return HTML(out)
return out

@staticmethod
def remote_ls_parser():

0 comments on commit c26fb0a

Please sign in to comment.
You can’t perform that action at this time.