@contextfilter
def ext_filter(ctx, value, splitter='.', all=False):
    """Cut away the last file extension splitted by `splitter`.
    The default splitter is ``.``

    :param ctx: the context
    :param value: the file path
    :param splitter: the splitter
    :param all: if set to True the left-mose occurence of the split character
                is used
    """
    try:
        if isinstance(value, JipUndefined):
            return "${%s|ext('%s')}" % (value._undefined_name, splitter)
        if not isinstance(value, Option):
            script = ctx.get('tool', None)
            if script:
                v = script.options[value]
                if v is not None:
                    value = v

        if not isinstance(value, Option):
            v = str(value)
        else:
            v = value.get()
        try:
            if not all:
                i = str(v).rindex(splitter)
            else:
                i = str(v).index(splitter)
            if i > 0:
                return str(v)[:i]
        except:
            pass
        return v
    except:
        return value
dataset/ETHPy150Open thasso/pyjip/jip/templates.py/ext_filter/original