示例#1
0
文件: pifi.py 项目: ihelal/pifi
def set_hostname(new_hostname):
    old_hostname = etc_io.get_hostname()
    print("Changing hostname from %s to %s" % (old_hostname, new_hostname))

    try:
        etc_io.set_hostname(old_hostname, new_hostname)
        socket.sethostname(new_hostname)
    except PermissionError:
        print(
            "Error writing to /etc/hosts or /etc/hostname, make sure you are running with sudo"
        )
    except OSError:
        print(
            "Error writing to /etc/hosts or /etc/hostname, make sure you are running with sudo"
        )
示例#2
0
文件: pifi.py 项目: MoffKalast/pifi
def set_hostname(argv):
    parser = argparse.ArgumentParser(description="Set a new hostname")
    parser.add_argument("hostname")
    args = parser.parse_args(argv)
    new_hostname = args.hostname

    old_hostname = etc_io.get_hostname()
    print("Changing hostname from %s to %s" % (old_hostname, new_hostname))

    try:
        etc_io.set_hostname(old_hostname, new_hostname)
        socket.sethostname(new_hostname)
    except PermissionError:
        print(
            "Error writing to /etc/hosts or /etc/hostname, make sure you are running with sudo"
        )
    except OSError:
        print(
            "Error writing to /etc/hosts or /etc/hostname, make sure you are running with sudo"
        )