def get_dir_relpath(base, relpath):
    """Returns the absolute path to the 'relpath' taken relative to the base
    directory.

    :arg base: the base directory to take the path relative to.
    :arg relpath: the path relative to 'base' in terms of '.' and '..'.
    """
    from os import path
    xbase = path.abspath(path.expanduser(base))
    if not path.isdir(xbase):
        return path.join(xbase, relpath)
    if relpath[0:2] == './':
        return path.join(xbase, relpath[2:])
    else:
        from os import chdir, getcwd
        cd = getcwd()
        chdir(xbase)
        result = path.abspath(relpath)
        chdir(cd)
        return result
