Skip to content

Commit

Permalink
Don't write weights file if old file fails to load
Browse files Browse the repository at this point in the history
Issue #13
  • Loading branch information
dbr committed Feb 4, 2016
1 parent bcbc79a commit f2a49fe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,7 @@ type "ax[3" or "ax 3" (ax-space-space-3) it will only match "Axis
* `v1.8` (wip)

* Installation instructions updated to support Nuke 9

* Weights file no longer overwritten if it fails to load for some
reason.
[Github issue #13](https://github.com/dbr/tabtabtab-nuke/issues/13)
9 changes: 9 additions & 0 deletions tabtabtab.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ class NodeWeights(object):
def __init__(self, fname = None):
self.fname = fname
self._weights = {}
self._successful_load = False

def load(self):
if self.fname is None:
Expand All @@ -165,16 +166,24 @@ def _load_internal():
# Catch any errors, print traceback and continue
try:
_load_internal()
self._successful_load = True
except Exception:
print "Error loading node weights"
import traceback
traceback.print_exc()
self._successful_load = False

def save(self):
if self.fname is None:
print "Not saving node weights, no file specified"
return

if self._successful_load:
# Avoid clobbering existing weights file on load error
print "Not writing weights file because %r previously failed to load" % (
self.fname)
return

def _save_internal():
import json
ndir = os.path.dirname(self.fname)
Expand Down

0 comments on commit f2a49fe

Please sign in to comment.