Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Work Files API to not shadow built-in open #449

Merged
merged 3 commits into from
Sep 17, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions avalon/fusion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
)

from .workio import (
open,
save,
open_file,
save_file,
current_file,
has_unsaved_changes,
file_extensions,
Expand All @@ -42,8 +42,8 @@
"comp_lock_and_undo_chunk",

# Workfiles API
"open",
"save",
"open_file",
"save_file",
"current_file",
"has_unsaved_changes",
"file_extensions",
Expand Down
4 changes: 2 additions & 2 deletions avalon/fusion/workio.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ def has_unsaved_changes():
return comp.GetAttrs()["COMPB_Modified"]


def save(filepath):
def save_file(filepath):
from avalon.fusion.pipeline import get_current_comp

comp = get_current_comp()
comp.Save(filepath)


def open(filepath):
def open_file(filepath):
# Hack to get fusion, see avalon.fusion.pipeline.get_current_comp()
fusion = getattr(sys.modules["__main__"], "fusion", None)

Expand Down
8 changes: 4 additions & 4 deletions avalon/houdini/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
)

from .workio import (
open,
save,
open_file,
save_file,
current_file,
has_unsaved_changes,
file_extensions,
Expand All @@ -38,8 +38,8 @@
"containerise",

# Workfiles API
"open",
"save",
"open_file",
"save_file",
"current_file",
"has_unsaved_changes",
"file_extensions",
Expand Down
4 changes: 2 additions & 2 deletions avalon/houdini/workio.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def has_unsaved_changes():
return hou.hipFile.hasUnsavedChanges()


def save(filepath):
def save_file(filepath):

# Force forwards slashes to avoid segfault
filepath = filepath.replace("\\", "/")
Expand All @@ -23,7 +23,7 @@ def save(filepath):
return filepath


def open(filepath):
def open_file(filepath):

# Force forwards slashes to avoid segfault
filepath = filepath.replace("\\", "/")
Expand Down
8 changes: 4 additions & 4 deletions avalon/maya/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
)

from .workio import (
open,
save,
open_file,
save_file,
current_file,
has_unsaved_changes,
file_extensions,
Expand Down Expand Up @@ -71,8 +71,8 @@
"lock_ignored",

# Workfiles API
"open",
"save",
"open_file",
"save_file",
"current_file",
"has_unsaved_changes",
"file_extensions",
Expand Down
4 changes: 2 additions & 2 deletions avalon/maya/workio.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ def has_unsaved_changes():
return cmds.file(query=True, modified=True)


def save(filepath):
def save_file(filepath):
cmds.file(rename=filepath)
cmds.file(save=True, type="mayaAscii")


def open(filepath):
def open_file(filepath):
return cmds.file(filepath, open=True, force=True)


Expand Down
8 changes: 4 additions & 4 deletions avalon/nuke/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
from .workio import (
file_extensions,
has_unsaved_changes,
save,
open,
save_file,
open_file,
current_file,
work_root,
)
Expand Down Expand Up @@ -50,8 +50,8 @@

"file_extensions",
"has_unsaved_changes",
"save",
"open",
"save_file",
"open_file",
"current_file",
"work_root",

Expand Down
4 changes: 2 additions & 2 deletions avalon/nuke/workio.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ def has_unsaved_changes():
return nuke.root().modified()


def save(filepath):
def save_file(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):
def open_file(filepath):
filepath = filepath.replace("\\", "/")

# To remain in the same window, we have to clear the script and read
Expand Down
8 changes: 4 additions & 4 deletions avalon/tools/workfiles/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ For the Work Files tool to work with a new host integration the host must
implement the following functions:

- `file_extensions()`: The files the host should allow to open and show in the Work Files view.
- `open(filepath)`: Open a file.
- `save(filepath)`: Save the current file. This should return None if it failed to save, and return the path if it succeeded
- `open_file(filepath)`: Open a file.
- `save_file(filepath)`: Save the current file. This should return None if it failed to save, and return the path if it succeeded
- `has_unsaved_changes()`: Return whether the current scene has unsaved changes.
- `current_file()`: The path to the current file. None if not saved.
- `work_root()`: The path to where the work files for this app should be saved.
Expand All @@ -88,7 +88,7 @@ def has_unsaved_changes():
"""Return whether current file has unsaved modifications."""


def save(filepath):
def save_file(filepath):
"""Save to filepath.

This should return None if it failed to save, and return the path if it
Expand All @@ -97,7 +97,7 @@ def save(filepath):
pass


def open(filepath):
def open_file(filepath):
"""Open file"""
pass

Expand Down
6 changes: 3 additions & 3 deletions avalon/tools/workfiles/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,13 +383,13 @@ def open(self, filepath):

if result:
# Save current scene, continue to open file
host.save(host.current_file())
host.save_file(host.current_file())

else:
# Don't save, continue to open file
pass

return host.open(filepath)
return host.open_file(filepath)

def on_duplicate_pressed(self):
work_file = self.get_name()
Expand Down Expand Up @@ -445,7 +445,7 @@ def on_save_as_pressed(self):
return

file_path = os.path.join(self.root, work_file)
self.host.save(file_path)
self.host.save_file(file_path)

self.close()

Expand Down