Commits

David McClosky committed 962a994

Add get_hostname(), first function in waterworks.Network

Comments (0)

Files changed (1)

waterworks/Network.py

+import os, socket
+
+def get_hostname():
+    """Returns the simple, unqualified version of a hostname."""
+    try:
+        name = socket.gethostbyaddr(socket.gethostname())[1][0]
+    except: # some network errors can cause the above to fail
+        fullname = os.uname()[1]
+        name = fullname.split('.')[0]
+    return name.lower()