Permalink
Browse files

Refactoring for pure-dict

  • Loading branch information...
mottosso committed Oct 22, 2015
1 parent 464a739 commit d8d69ecccfe67e0f84221b1c052c7b7ded1ac6bd
View
@@ -103,7 +103,7 @@ def _load_data(context):
with open(DATA_PATH) as f:
data = yaml.load(f)
for key, value in data.iteritems():
context.set_data(key, value)
context.data[key] = value
return True
@@ -222,7 +222,7 @@ def main(ctx,
"--data %s %s" % (key, value))
ctx.obj["error"] = err
else:
context.set_data(str(key), yaml_loaded)
context.data[str(key)] = yaml_loaded
# Load user data
data_loaded = _load_data(context)
@@ -327,21 +327,21 @@ def publish(ctx,
context = ctx.obj["context"]
if os.path.isdir(path):
context.set_data("current_dir", path) # backwards compatibility
context.set_data("currentDir", path)
context.data["current_dir"] = path # backwards compatibility
context.data["currentDir"] = path
else:
context.set_data("current_file", path) # backwards compatibility
context.set_data("currentFile", path)
context.data["current_file"] = path # backwards compatibility
context.data["currentFile"] = path
# Begin processing
plugins = list(p for p in pyblish.api.discover(
paths=ctx.obj["plugin_paths"]) if p.active)
context = pyblish.util.publish(context=context, plugins=plugins)
if any(result["error"] for result in context.data("results")):
if any(result["error"] for result in context.data["results"]):
click.echo("There were errors.")
for result in context.data("results"):
for result in context.data["results"]:
if result["error"] is not None:
click.echo(result["error"])
View
@@ -122,7 +122,7 @@ def gen(plugin, instances):
args = inspect.getargspec(plugin.process).args
# Forwards compatibility with `asset`
# Backwards compatibility with `asset`
if "asset" in args:
args.append("instance")
@@ -242,7 +242,7 @@ def plugins_by_instance(plugins, instance):
"""
return plugins_by_family(plugins, instance.data("family"))
return plugins_by_family(plugins, instance.data["family"])
def plugins_by_host(plugins, host):
@@ -288,7 +288,7 @@ def instances_by_plugin(instances, plugin):
compatible = list()
for instance in instances:
family = instance.data("family")
family = instance.data["family"]
if any(x in plugin.families for x in (family, "*")):
compatible.append(instance)
View
@@ -490,10 +490,10 @@ def process(plugin, context, instance=None, action=None):
result["duration"] = (__end - __start) * 1000 # ms
if "results" not in context.data():
context.set_data("results", list())
if "results" not in context.data:
context.data["results"] = list()
context.data("results").append(result)
context.data["results"].append(result)
# Backwards compatibility
result["asset"] = instance # Deprecated key
@@ -506,8 +506,8 @@ def repair(plugin, context, instance=None):
import time
if "results" not in context.data():
context.set_data("results", list())
if "results" not in context.data:
context.data["results"] = list()
result = {
"success": False,
@@ -544,7 +544,7 @@ def repair(plugin, context, instance=None):
result["duration"] = (__end - __start) * 1000 # ms
context.data("results").append(result)
context.data["results"].append(result)
return result
@@ -733,6 +733,9 @@ def __init__(self, name, parent=None):
self.name = name
self.parent = parent
self.data["name"] = name
self.data["family"] = "default"
if parent is not None:
parent.append(self)
@@ -9,4 +9,4 @@ class CollectCurrentDate(pyblish.api.Collector):
def process(self, context):
"""Formatting is coming from configuration"""
date = pyblish.lib.time()
context.set_data('date', value=date)
context.data['date'] = date
@@ -7,4 +7,4 @@ class CollectCurrentWorkingDirectory(pyblish.api.Collector):
"""Inject the current working directory into Context"""
def process(self, context):
context.set_data('cwd', value=os.getcwd())
context.data['cwd'] = os.getcwd()
View
@@ -355,9 +355,6 @@ def test_data_dict():
context.data["key"] = "value"
assert context.data["key"] == "value"
# The actual dict doesn't have this convenience feature.
assert instance.data.get("name") == None
instance.data["key"] = "value"
assert instance.data["key"] == "value"

0 comments on commit d8d69ec

Please sign in to comment.