#!/usr/bin/python3

import socket
import subprocess
from subprocess import PIPE
from sys import stdin

from sysversion import fmt_sysversion

ENCODING = stdin.encoding  # most likely 'utf-8'


def fmt_welcome(encoding=ENCODING):
    welcome = "Welcome to {}".format(socket.gethostname().capitalize())

    sysversion = fmt_sysversion(encoding=ENCODING)
    if sysversion:
        welcome += ", " + sysversion

    return welcome  # returns string obj


def indent(level, s, encoding=ENCODING):
    return "\n".join([(" " * level + line) for line in s.splitlines()])


def main(encoding=ENCODING):
    print(fmt_welcome(encoding=ENCODING))

    turnkey_sysinfo = subprocess.run(["turnkey-sysinfo"],
                                     stdout=PIPE, encoding=ENCODING).stdout
    print()
    print(indent(2, turnkey_sysinfo))
    print()


if __name__ == "__main__":
    main()
