Ejemplo n.º 1
0
  def RunSimpleCommand(self, cmd_val, do_fork, call_procs=True):
    # type: (cmd_value__Argv, bool, bool) -> int

    arg0 = cmd_val.argv[0]

    builtin_id = consts.LookupSpecialBuiltin(arg0)
    if builtin_id != consts.NO_INDEX:
      return self.RunBuiltin(builtin_id, cmd_val)

    builtin_id = consts.LookupNormalBuiltin(arg0)
    if builtin_id != consts.NO_INDEX:
      return self.RunBuiltin(builtin_id, cmd_val)

    log('Unhandled SimpleCommand')

    f = mylib.Stdout()
    #ast_f = fmt.DetectConsoleOutput(f)
    # Stupid Eclipse debugger doesn't display ANSI
    ast_f = fmt.TextOutput(f)
    tree = cmd_val.PrettyTree()

    ast_f.FileHeader()
    fmt.PrintTree(tree, ast_f)
    ast_f.FileFooter()
    ast_f.write('\n')

    return 0
Ejemplo n.º 2
0
Archivo: py_meta.py Proyecto: silky/oil
 def __repr__(self):
     ast_f = fmt.TextOutput(util.Buffer())  # No color by default.
     #ast_f = fmt.AnsiOutput(io.StringIO())
     tree = fmt.MakeTree(self)
     fmt.PrintTree(tree, ast_f)
     s, _ = ast_f.GetRaw()
     return s
Ejemplo n.º 3
0
    def RunSimpleCommand(self, cmd_val, do_fork, call_procs=True):
        # type: (cmd_value__Argv, bool, bool) -> int
        argv = cmd_val.argv
        span_id = cmd_val.arg_spids[0] if len(
            cmd_val.arg_spids) else runtime.NO_SPID

        arg0 = argv[0]

        builtin_id = consts.LookupSpecialBuiltin(arg0)
        if builtin_id != consts.NO_INDEX:
            return self.RunBuiltin(builtin_id, cmd_val)

        # Copied from core/executor.py
        if call_procs:
            proc_node = self.procs.get(arg0)
            if proc_node is not None:
                if (self.exec_opts.strict_errexit()
                        and self.mutable_opts.ErrExitIsDisabled()):
                    # TODO: make errfmt a member
                    #self.errfmt.Print_('errexit was disabled for this construct',
                    #                   span_id=self.mutable_opts.errexit.spid_stack[0])
                    #stderr_line('')
                    e_die(
                        "Can't run a proc while errexit is disabled. "
                        "Use 'catch' or wrap it in a process with $0 myproc",
                        span_id=span_id)

                # NOTE: Functions could call 'exit 42' directly, etc.
                status = self.cmd_ev.RunProc(proc_node, argv[1:])
                return status

        builtin_id = consts.LookupNormalBuiltin(arg0)
        if builtin_id != consts.NO_INDEX:
            return self.RunBuiltin(builtin_id, cmd_val)

        # See how many tests will pass
        #if mylib.PYTHON:
        if 0:  # osh_eval.cc will pass 1078 rather than 872 by enabling
            import subprocess
            try:
                status = subprocess.call(cmd_val.argv)
            except OSError as e:
                log('Error running %s: %s', cmd_val.argv, e)
                return 1
            return status

        log('Unhandled SimpleCommand')
        f = mylib.Stdout()
        #ast_f = fmt.DetectConsoleOutput(f)
        # Stupid Eclipse debugger doesn't display ANSI
        ast_f = fmt.TextOutput(f)
        tree = cmd_val.PrettyTree()

        ast_f.FileHeader()
        fmt.PrintTree(tree, ast_f)
        ast_f.FileFooter()
        ast_f.write('\n')

        return 0
Ejemplo n.º 4
0
Archivo: runtime.py Proyecto: bsa3/oil
 def __repr__(self):
   # TODO: Break this circular dependency.
   from asdl import format as fmt
   ast_f = fmt.TextOutput(util.Buffer())  # No color by default.
   tree = fmt.MakeTree(self)
   fmt.PrintTree(tree, ast_f)
   s, _ = ast_f.GetRaw()
   return s
Ejemplo n.º 5
0
Archivo: pure.py Proyecto: drwilly/oil
    def RunSimpleCommand(self, cmd_val, do_fork, call_procs=True):
        # type: (cmd_value__Argv, bool, bool) -> int
        argv = cmd_val.argv
        span_id = cmd_val.arg_spids[0] if len(
            cmd_val.arg_spids) else runtime.NO_SPID

        arg0 = argv[0]

        builtin_id = consts.LookupSpecialBuiltin(arg0)
        if builtin_id != consts.NO_INDEX:
            return self.RunBuiltin(builtin_id, cmd_val)

        func_node = self.procs.get(arg0)
        if func_node is not None:
            if (self.exec_opts.strict_errexit()
                    and self.mutable_opts.errexit.SpidIfDisabled() !=
                    runtime.NO_SPID):
                # NOTE: This would be checked below, but this gives a better error
                # message.
                e_die(
                    "can't disable errexit running a function. "
                    "Maybe wrap the function in a process with the at-splice "
                    "pattern.",
                    span_id=span_id)

            # NOTE: Functions could call 'exit 42' directly, etc.
            status = self.cmd_ev.RunProc(func_node, argv[1:])
            return status

        builtin_id = consts.LookupNormalBuiltin(arg0)
        if builtin_id != consts.NO_INDEX:
            return self.RunBuiltin(builtin_id, cmd_val)

        # See how many tests will pass
        #if mylib.PYTHON:
        if 0:  # osh_eval.cc will pass 1078 rather than 872 by enabling
            import subprocess
            try:
                status = subprocess.call(cmd_val.argv)
            except OSError as e:
                log('Error running %s: %s', cmd_val.argv, e)
                return 1
            return status

        log('Unhandled SimpleCommand')
        f = mylib.Stdout()
        #ast_f = fmt.DetectConsoleOutput(f)
        # Stupid Eclipse debugger doesn't display ANSI
        ast_f = fmt.TextOutput(f)
        tree = cmd_val.PrettyTree()

        ast_f.FileHeader()
        fmt.PrintTree(tree, ast_f)
        ast_f.FileFooter()
        ast_f.write('\n')

        return 0
Ejemplo n.º 6
0
Archivo: runtime.py Proyecto: mrshu/oil
    def __repr__(self):
        # type: () -> str
        # TODO: Break this circular dependency.
        from asdl import format as fmt

        ast_f = fmt.TextOutput(StringIO())  # No color by default.
        tree = self.PrettyTree()
        fmt.PrintTree(tree, ast_f)
        s, _ = ast_f.GetRaw()
        return s
Ejemplo n.º 7
0
  def testRepeatedString(self):
    node = arith_ast.assign('declare', ['-r', '-x'])

    f = cStringIO.StringIO()
    ast_f = fmt.TextOutput(f)

    tree = fmt.MakeTree(node)
    #print(tree)

    fmt.PrintTree(tree, ast_f)
    pretty_str = f.getvalue()
    print(pretty_str)

    self.assertEqual('(assign name:declare flags:[-r -x])', pretty_str)
Ejemplo n.º 8
0
  def testSimpleSum(self):
    node = arith_ast.op_id_e.Plus
    print(node)

    f = cStringIO.StringIO()
    ast_f = fmt.TextOutput(f)

    tree = fmt.MakeTree(node)
    fmt.PrintTree(tree, ast_f)

    # Hm this prints 'Plus'.  Doesn't print the class or the number.
    # But those aren't intrinsic.  These are mostly used for ther IDENTITY.
    # I think the ASDL_TYPE field contains the relevant info.  Yes!
    pretty_str = f.getvalue()
    print(pretty_str)
Ejemplo n.º 9
0
  def testRepeatedString(self):
    node = demo_asdl.assign('declare', ['-r', '-x'])

    f = cStringIO.StringIO()
    f1 = fmt.TextOutput(f)
    f2 = fmt.HtmlOutput(f)

    for ast_f in [f1, f2]:
      tree = node.PrettyTree()

      fmt.PrintTree(tree, ast_f)
      pretty_str = f.getvalue()
      print(pretty_str)

      if ast_f is f1:
        self.assertEqual('(assign name:declare flags:[-r -x])', pretty_str)

      t2 = node.AbbreviatedTree()

      fmt.PrintTree(t2, ast_f)