Beispiel #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)
Beispiel #2
0
def ShowAppVersion(app_name):
    # type: (str) -> None
    """For Oil and OPy."""
    loader = GetResourceLoader()
    f = loader.open('oil-version.txt')
    version = f.readline().strip()
    f.close()

    try:
        f = loader.open('release-date.txt')
    except IOError:
        release_date = '-'  # in dev tree
    else:
        release_date = f.readline().strip()
    finally:
        f.close()

    try:
        f = loader.open('pyc-version.txt')
    except IOError:
        pyc_version = '-'  # in dev tree
    else:
        pyc_version = f.readline().strip()
    finally:
        f.close()

    # node is like 'hostname'
    # release is the kernel version
    system, unused_node, unused_release, platform_version, machine = posix.uname(
    )

    # The platform.py module has a big regex that parses sys.version, but we
    # don't want to depend on regular expressions.  So we will do our own parsing
    # here.
    version_line, py_compiler = sys.version.splitlines()

    # Pick off the first part of '2.7.12 (default, ...)'
    py_version = version_line.split()[0]

    assert py_compiler.startswith('['), py_compiler
    assert py_compiler.endswith(']'), py_compiler
    py_compiler = py_compiler[1:-1]

    # We removed sys.executable from sysmodule.c.
    py_impl = 'CPython' if hasattr(sys, 'executable') else 'OVM'

    # What C functions do these come from?
    print('%s version %s' % (app_name, version))
    print('Release Date: %s' % release_date)
    print('Arch: %s' % machine)
    print('OS: %s' % system)
    print('Platform: %s' % platform_version)
    print('Compiler: %s' % py_compiler)
    print('Interpreter: %s' % py_impl)
    print('Interpreter version: %s' % py_version)
    print('Bytecode: %s' % pyc_version)
Beispiel #3
0
def ShowAppVersion(app_name, loader):
    # type: (str, _ResourceLoader) -> None
    """Show version and platform information."""
    try:
        contents = loader.Get('release-date.txt')
        release_date, _ = mylib.split_once(contents, '\n')
    except IOError:
        release_date = '-'  # in dev tree

    try:
        contents = loader.Get('pyc-version.txt')
        pyc_version, _ = mylib.split_once(contents, '\n')
    except IOError:
        pyc_version = '-'  # in dev tree

    # node is like 'hostname'
    # release is the kernel version
    system, unused_node, unused_release, platform_version, machine = posix.uname(
    )

    # The platform.py module has a big regex that parses sys.version, but we
    # don't want to depend on regular expressions.  So we will do our own parsing
    # here.
    version_line, py_compiler = sys.version.splitlines()

    # Pick off the first part of '2.7.12 (default, ...)'
    py_version = version_line.split()[0]

    assert py_compiler.startswith('['), py_compiler
    assert py_compiler.endswith(']'), py_compiler
    py_compiler = py_compiler[1:-1]

    # We removed sys.executable from sysmodule.c.
    py_impl = 'CPython' if hasattr(sys, 'executable') else 'OVM'

    version_str = GetVersion(loader)

    # What C functions do these come from?
    print('%s version %s' % (app_name, version_str))
    print('Release Date: %s' % release_date)
    print('Arch: %s' % machine)
    print('OS: %s' % system)
    print('Platform: %s' % platform_version)
    print('Compiler: %s' % py_compiler)
    print('Interpreter: %s' % py_impl)
    print('Interpreter version: %s' % py_version)
    print('Bytecode: %s' % pyc_version)
Beispiel #4
0
def OsType():
    # type: () -> str
    """ Compute $OSTYPE variable """
    return posix.uname()[0].lower()