"""
Various Condor-IPP helpers
"""
import os
import socket

#################################################################
def mkdir(directory_name):
    """From http://code.activestate.com/recipes/82465-a-friendly-mkdir/

    Works the way a good mkdir should :)
        - already exists, silently complete
        - regular file in the way, raise an exception
        - parent directory(ies) does not exist, make them as well
    """
    print 'Creating directory [%s]' % directory_name
    if os.path.isdir(directory_name):
        pass
    elif os.path.isfile(directory_name):
        raise OSError("a file with the same name as the desired " \
                      "dir, '%s', already exists." % directory_name)
    else:
        head, tail = os.path.split(directory_name)
        if head and not os.path.isdir(head):
            mkdir(head)
        if tail:
            os.mkdir(directory_name)

#################################################################
def hostname():
    """
    Get the host name
    >>> print hostname()
    neverland
    """
    return socket.gethostbyaddr(socket.gethostname())[0].split('.')[0]

#################################################################
if __name__ == '__main__':
    print 'Host is [%s]' % hostname()
    print 'Not intended to be used independently'
    import sys
    sys.exit(1)
