예제 #1
0
  def _InitDefaults(self):
    # For some reason this is one of few variables EXPORTED.  bash and dash
    # both do it.  (e.g. env -i -- dash -c env)
    ExportGlobalString(self, 'PWD', posix.getcwd())

    # Default value; user may unset it.
    # $ echo -n "$IFS" | python -c 'import sys;print repr(sys.stdin.read())'
    # ' \t\n'
    SetGlobalString(self, 'IFS', split.DEFAULT_IFS)

    # NOTE: Should we put these in a namespace for Oil?
    SetGlobalString(self, 'UID', str(posix.getuid()))
    SetGlobalString(self, 'EUID', str(posix.geteuid()))

    SetGlobalString(self, 'HOSTNAME', str(libc.gethostname()))

    # In bash, this looks like 'linux-gnu', 'linux-musl', etc.  Scripts test
    # for 'darwin' and 'freebsd' too.  They generally don't like at 'gnu' or
    # 'musl'.  We don't have that info, so just make it 'linux'.
    SetGlobalString(self, 'OSTYPE', str(posix.uname()[0].lower()))

    # For getopts builtin
    SetGlobalString(self, 'OPTIND', '1')

    # For xtrace
    SetGlobalString(self, 'PS4', '+ ')

    # bash-completion uses this.  Value copied from bash.  It doesn't integrate
    # with 'readline' yet.
    SetGlobalString(self, 'COMP_WORDBREAKS', _READLINE_DELIMS)
예제 #2
0
파일: prompt.py 프로젝트: tekknolagi/oil
  def Get(self, name):
    # type: (str) -> Any
    if name in self.cache:
      return self.cache[name]

    if name == 'euid':  # for \$ and \u
      value = posix.geteuid()
    elif name == 'hostname':  # for \h and \H
      value = libc.gethostname()
    elif name == 'user':  # for \u
      value = _GetUserName(self.Get('euid'))  # recursive call for caching
    else:
      raise AssertionError(name)

    self.cache[name] = value
    return value
예제 #3
0
    def Get(self, name):
        # type: (str) -> str
        if name in self.cache:
            return self.cache[name]

        if name == '$':  # \$
            value = '#' if self._GetEuid() == 0 else '$'
        elif name == 'hostname':  # for \h and \H
            value = libc.gethostname()
        elif name == 'user':  # for \u
            value = pyos.GetUserName(
                self._GetEuid())  # recursive call for caching
        else:
            raise AssertionError(name)

        self.cache[name] = value
        return value
예제 #4
0
파일: libc_test.py 프로젝트: tekknolagi/oil
 def testGethostname(self):
     print(libc.gethostname())