"""Host API required by Work Files tool"""
import os
import nuke


def file_extensions():
    return [".nk"]


def has_unsaved_changes():
    return nuke.Root().modified()


def save(filepath):
    nuke.scriptSaveAs(filepath)


def open(filepath):
    nuke.scriptClear()
    nuke.scriptOpen(filepath)
    return True


def current_file():
    current_file = nuke.root().name()
    normalised = os.path.normpath(current_file)

    # Unsaved current file
    if nuke.Root().name() == 'Root':
        return "NOT SAVED"

    return normalised


def work_root():
    from avalon import Session

    work_dir = Session["AVALON_WORKDIR"]
    scene_dir = Session.get("AVALON_SCENEDIR")

    if scene_dir:
        return os.path.join(work_dir, scene_dir)
    else:
        return work_dir

"""Host API required Work Files tool"""
import os
import nuke


def file_extensions():
    return [".nk"]


def has_unsaved_changes():
    return nuke.root().modified()


def save(filepath):
    path = filepath.replace("\\", "/")
    nuke.scriptSaveAs(path)
    nuke.Root()["name"].setValue(path)
    nuke.Root()["project_directory"].setValue(os.path.dirname(path))
    nuke.Root().setModified(False)


def open(filepath):
    filepath = filepath.replace("\\", "/")

    # To remain in the same window, we have to clear the script and read
    # in the contents of the workfile.
    nuke.scriptClear()
    nuke.scriptReadFile(filepath)
    nuke.Root()["name"].setValue(filepath)
    nuke.Root()["project_directory"].setValue(os.path.dirname(filepath))
    nuke.Root().setModified(False)
    return True


def current_file():
    current_file = nuke.root().name()

    # Unsaved current file
    if current_file == 'Root':
        return None

    return os.path.normpath(current_file).replace("\\", "/")


def work_root():
    from avalon import Session
    return os.path.normpath(Session["AVALON_WORKDIR"]).replace("\\", "/")

Repair nuke.workio From https://github.com/pypeclub/avalon-core/blob/555a291bc85607f54e6eee50100126b55de44f6f/avalon/nuke/workio.py