Esempio n. 1
0
#!/usr/bin/env python2
"""
builtin_assign.py
"""
from __future__ import print_function

from _devbuild.gen.runtime_asdl import (
    value, value_e, lvalue, scope_e, var_flags_e, builtin_e
)
#from core.util import log
from frontend import args
from frontend import match
from osh.builtin import _Register


EXPORT_SPEC = _Register('export')
EXPORT_SPEC.ShortFlag('-n')
EXPORT_SPEC.ShortFlag('-f')  # stubbed


class Export(object):
  def __init__(self, mem, errfmt):
    self.mem = mem
    self.errfmt = errfmt

  def __call__(self, cmd_val):
    arg_r = args.Reader(cmd_val.argv, spids=cmd_val.arg_spids)
    arg_r.Next()
    arg, arg_index = EXPORT_SPEC.Parse(arg_r)

    if arg.f:
Esempio n. 2
0
builtin_process.py - Builtins that deal with processes or modify process state.

This is sort of the opposite of builtin_pure.py.
"""
from __future__ import print_function

import signal  # for calculating numbers

from core import ui
from core.util import log
from frontend import args
from osh.builtin import _Register  # TODO: Remove this

import posix_ as posix

WAIT_SPEC = _Register('wait')
WAIT_SPEC.ShortFlag('-n')


class Wait(object):
    """
  wait: wait [-n] [id ...]
      Wait for job completion and return exit status.

      Waits for each process identified by an ID, which may be a process ID or a
      job specification, and reports its termination status.  If ID is not
      given, waits for all currently active child processes, and the return
      status is zero.  If ID is a a job specification, waits for all processes
      in that job's pipeline.

      If the -n option is supplied, waits for the next job to terminate and
Esempio n. 3
0
from frontend import match
from osh.builtin import Resolve, ResolveSpecial, ResolveAssign
from osh.builtin import _Register  # TODO: Remove this
from osh import state
from osh import string_ops
from osh import word_compile

from typing import Dict, TYPE_CHECKING
if TYPE_CHECKING:
  from osh.cmd_exec import Executor
  from osh.state import SearchPath
  from _devbuild.gen.syntax_asdl import command__ShFunction
  from _devbuild.gen.runtime_asdl import cmd_value__Argv


ALIAS_SPEC = _Register('alias')


class Alias(object):
  def __init__(self, aliases, errfmt):
    self.aliases = aliases
    self.errfmt = errfmt

  def __call__(self, cmd_val):
    # type: (cmd_value__Argv) -> int
    argv = cmd_val.argv
    if len(argv) == 1:
      for name in sorted(self.aliases):
        alias_exp = self.aliases[name]
        # This is somewhat like bash, except we use %r for ''.
        print('alias %s=%r' % (name, alias_exp))
Esempio n. 4
0
import sys

from asdl import runtime
from core import error
from core.util import p_die, e_die
from frontend import args
from frontend import lookup
from frontend import match
from frontend import reader
from osh import builtin
from osh import state
from osh import string_ops
from osh import word_compile

PRINTF_SPEC = builtin._Register('printf')  # TODO: Don't need this?
PRINTF_SPEC.ShortFlag('-v', args.Str)


class _FormatStringParser(object):
    """
  Grammar:

    fmt           = Format_Percent Flag? Num? (Dot Num)? Type
    part          = Char_* | Format_EscapedPercent | fmt
    printf_format = part* Eof_Real   # we're using the main lexer

  Maybe: bash also supports %(strftime)T
  """
    def __init__(self, lexer):
        self.lexer = lexer