'Construct path from object and parameters'

def _construct_path(self, obj, base_dir=None, dir_only=None, extra_dir=None, extra_dir_at_root=False, alt_name=None, obj_dir=False, **kwargs):

    if (extra_dir and (extra_dir != os.path.normpath(extra_dir))):
        log.warning('extra_dir    is    not    normalized:    {0}'.format(extra_dir))
        raise ObjectInvalid('The    requested    object    is    invalid')
    if alt_name:
        if (not safe_relpath(alt_name)):
            log.warning('alt_name    would    locate    path    outside    dir:    {0}'.format(alt_name))
            raise ObjectInvalid('The    requested    object    is    invalid')
        alt_name = os.path.normpath(alt_name)
    rel_path = os.path.join(*directory_hash_id(obj.id))
    if (extra_dir is not None):
        if extra_dir_at_root:
            rel_path = os.path.join(extra_dir, rel_path)
        else:
            rel_path = os.path.join(rel_path, extra_dir)
    if obj_dir:
        rel_path = os.path.join(rel_path, str(obj.id))
    if base_dir:
        base = self.extra_dirs.get(base_dir)
        return os.path.join(base, rel_path)
    rel_path = '{0}/'.format(rel_path)
    if (not dir_only):
        an = (alt_name if alt_name else 'dataset_{0}.dat'.format(obj.id))
        rel_path = os.path.join(rel_path, an)
    return rel_path
