def get_target_path(destination, origname):
    """ Implements the directory/path semantics of linux mv/cp etc.

    Examples:
        >>> import os
        >>> os.makedirs('./a')
        >>> get_target_path('./a', '/tmp/myfile')
        './myfile'
        >>> get_target_path('./a/b', '/tmp/myfile')
        './a/b'

    Raises:
        OSError: if neither destination NOR destination's parent exists OR it already exists
    """
    if os.path.exists(destination):
        if not os.path.isdir(destination):
            raise OSError('Cannot write to requested destination %s - file exists' % destination)
        return os.path.join(destination, os.path.basename(origname))
    else:
        destdir = os.path.abspath(os.path.join(destination, os.path.pardir))
        if not os.path.isdir(destdir):
            raise OSError(
                    'Cannot write to requested destination %s - parent directory does not exist' %
                    destination)
        return os.path.join(destination)