Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Commit

Permalink
fix clashing namespace js function calls
Browse files Browse the repository at this point in the history
  • Loading branch information
antirotor committed Sep 30, 2020
1 parent 9a3e6ba commit d7cacb3
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 37 deletions.
6 changes: 3 additions & 3 deletions avalon/harmony/TB_sceneOpened.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ function Client()
{
try
{
var func = eval.call( null, request["function"]);
var _func = eval.call( null, request["function"]);

if (request.args == null)
{
result = func();
result = _func();
}else
{
result = func(request.args);
result = _func(request.args);
}
}

Expand Down
39 changes: 21 additions & 18 deletions avalon/harmony/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import json
import signal
import time
from uuid import uuid4

from .server import Server
from ..vendor.Qt import QtWidgets
Expand All @@ -30,6 +31,8 @@
self.log = logging.getLogger(__name__)
self.log.setLevel(logging.DEBUG)

signature = str(uuid4())


class _ZipFile(zipfile.ZipFile):
"""Extended check for windows invalid characters."""
Expand Down Expand Up @@ -237,7 +240,7 @@ def show(module_name):


def get_scene_data():
func = """function func(args)
func = """function %s_func(args)
{
var metadata = scene.metadata("avalon");
if (metadata){
Expand All @@ -246,8 +249,8 @@ def get_scene_data():
return {};
}
}
func
"""
%s_func
""" % (signature, signature)
try:
return self.send({"function": func})["result"]
except json.decoder.JSONDecodeError:
Expand All @@ -260,7 +263,7 @@ def get_scene_data():

def set_scene_data(data):
# Write scene data.
func = """function func(args)
func = """function %s_func(args)
{
scene.setMetadata({
"name" : "avalon",
Expand All @@ -270,8 +273,8 @@ def set_scene_data(data):
"value" : JSON.stringify(args[0])
});
}
func
"""
%s_func
""" % (signature, signature)
self.send({"function": func, "args": [data]})


Expand Down Expand Up @@ -378,19 +381,19 @@ def maintained_nodes_state(nodes):
)

# Disable all nodes.
func = """function func(nodes)
func = """function %s_func(nodes)
{
for (var i = 0 ; i < nodes.length; i++)
{
node.setEnable(nodes[i], false);
}
}
func
"""
%s_func
""" % (signature, signature)
self.send({"function": func, "args": [nodes]})

# Restore state after yield.
func = """function func(args)
func = """function %s_func(args)
{
var nodes = args[0];
var states = args[1];
Expand All @@ -399,8 +402,8 @@ def maintained_nodes_state(nodes):
node.setEnable(nodes[i], states[i]);
}
}
func
"""
%s_func
""" % (signature, signature)

try:
yield
Expand All @@ -418,7 +421,7 @@ def save_scene():
"""
# Need to turn off the backgound watcher else the communication with
# the server gets spammed with two requests at the same time.
func = """function func()
func = """function %s_func()
{
var app = QCoreApplication.instance();
app.avalon_on_file_changed = false;
Expand All @@ -428,21 +431,21 @@ def save_scene():
scene.currentVersionName() + ".xstage"
);
}
func
"""
%s_func
""" % (signature, signature)
scene_path = self.send({"function": func})["result"]

# Manually update the remote file.
self.on_file_changed(scene_path, threaded=False)

# Re-enable the background watcher.
func = """function func()
func = """function %s_func()
{
var app = QCoreApplication.instance();
app.avalon_on_file_changed = true;
}
func
"""
%s_func
""" % (signature, signature)
self.send({"function": func})


Expand Down
24 changes: 14 additions & 10 deletions avalon/harmony/pipeline.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from .. import api, pipeline
from . import lib
from ..vendor import Qt
from uuid import uuid4

import pyblish.api


signature = str(uuid4())


def install():
"""Install Harmony-specific functionality of avalon-core.
Expand Down Expand Up @@ -49,18 +53,18 @@ class Creator(api.Creator):
node_type = "COMPOSITE"

def setup_node(self, node):
func = """function func(args)
func = """function %s_func(args)
{
node.setTextAttr(args[0], "COMPOSITE_MODE", 1, "Pass Through");
}
func
"""
%s_func
""" % (signature, signature)
lib.send(
{"function": func, "args": [node]}
)

def process(self):
func = """function func(args)
func = """function %s_func(args)
{
var nodes = node.getNodes([args[0]]);
var node_names = [];
Expand All @@ -70,8 +74,8 @@ def process(self):
}
return node_names
}
func
"""
%s_func
""" % (signature, signature)

existing_node_names = lib.send(
{"function": func, "args": [self.node_type]}
Expand All @@ -87,7 +91,7 @@ def process(self):
message_box.exec_()
return False

func = """function func(args)
func = """function %s_func(args)
{
var result_node = node.add("Top", args[0], args[1], 0, 0, 0);
Expand All @@ -103,8 +107,8 @@ def process(self):
}
return result_node
}
func
"""
%s_func
""" % (signature, signature)

with lib.maintained_selection() as selection:
node = None
Expand Down Expand Up @@ -161,7 +165,7 @@ def containerise(name,
"loader": str(loader),
"representation": str(context["representation"]["_id"]),
"nodes": nodes
}
}

lib.imprint(node, data)

Expand Down
15 changes: 9 additions & 6 deletions avalon/toonboom/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import importlib
import logging
import filecmp
from uuid import uuid4

from .server import Server
from ..tools import workfiles
Expand All @@ -29,6 +30,8 @@
self.log = logging.getLogger(__name__)
self.log.setLevel(logging.DEBUG)

signature = str(uuid4())


def execute_in_main_thread(func_to_call_from_main_thread):
self.callback_queue.put(func_to_call_from_main_thread)
Expand Down Expand Up @@ -294,7 +297,7 @@ def save_scene():
"""
# Need to turn off the backgound watcher else the communication with
# the server gets spammed with two requests at the same time.
func = """function func()
func = """function %s_func()
{
var app = QCoreApplication.instance();
app.avalon_on_file_changed = false;
Expand All @@ -303,19 +306,19 @@ def save_scene():
scene.currentProjectPath() + "/" + scene.currentVersionName()
);
}
func
"""
%s_func
""" % (signature, signature)
scene_path = self.send({"function": func})["result"] + "." + self.extension

# Manually update the remote file.
self.on_file_changed(scene_path)

# Re-enable the background watcher.
func = """function func()
func = """function %s_func()
{
var app = QCoreApplication.instance();
app.avalon_on_file_changed = true;
}
func
"""
%s_func
""" % (signature, signature)
self.send({"function": func})

0 comments on commit d7cacb3

Please sign in to comment.