annotate light9/effecteval/effect.py @ 1179:65405b3311f6

dead code Ignore-this: 19fc9344a2ffe34598ccccd5738bd1a6
author Drew Perttula <drewp@bigasterisk.com>
date Sun, 15 Jun 2014 07:42:51 +0000
parents da006651b531
children 92ffad96fd8a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1103
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
1 import re, logging
1108
4b542d321c8f effectnode runs multiple lines of code in dependency order
Drew Perttula <drewp@bigasterisk.com>
parents: 1107
diff changeset
2 import toposort
1052
b370618ce723 split EffectNode out of effecteval
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
3 from rdflib import URIRef
1103
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
4 from light9.namespaces import L9, RDF
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
5 from light9.curvecalc.curve import CurveResource
1154
1e97f96ee00c faster effect reload
drewp@bigasterisk.com
parents: 1136
diff changeset
6 from light9 import prof
1125
57eb333e6a4c reload Effects.py when graph changes. quieter logging
Drew Perttula <drewp@bigasterisk.com>
parents: 1113
diff changeset
7 from light9 import Submaster
57eb333e6a4c reload Effects.py when graph changes. quieter logging
Drew Perttula <drewp@bigasterisk.com>
parents: 1113
diff changeset
8 from light9 import Effects # gets reload() later
1103
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
9 log = logging.getLogger('effect')
1052
b370618ce723 split EffectNode out of effecteval
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
10
1103
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
11 # consider http://waxeye.org/ for a parser that can be used in py and js
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
12
1136
f48be3d18387 Strip can be scaled.
drewp@bigasterisk.com
parents: 1125
diff changeset
13 class CouldNotConvert(TypeError):
f48be3d18387 Strip can be scaled.
drewp@bigasterisk.com
parents: 1125
diff changeset
14 pass
f48be3d18387 Strip can be scaled.
drewp@bigasterisk.com
parents: 1125
diff changeset
15
1103
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
16 class CodeLine(object):
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
17 """code string is immutable"""
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
18 def __init__(self, graph, code):
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
19 self.graph, self.code = graph, code
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
20
1108
4b542d321c8f effectnode runs multiple lines of code in dependency order
Drew Perttula <drewp@bigasterisk.com>
parents: 1107
diff changeset
21 self.outName, self.inExpr, self.expr, self.resources = self._asPython()
1107
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
22 self.pyResources = self._resourcesAsPython(self.resources)
1108
4b542d321c8f effectnode runs multiple lines of code in dependency order
Drew Perttula <drewp@bigasterisk.com>
parents: 1107
diff changeset
23 self.possibleVars = self.findVars(self.inExpr)
1103
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
24
1158
da006651b531 more timing logs in EE
drewp@bigasterisk.com
parents: 1154
diff changeset
25 @prof.logTime
1103
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
26 def _asPython(self):
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
27 """
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
28 out = sub(<uri1>, intensity=<curveuri2>)
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
29 becomes
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
30 'out',
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
31 'sub(_u1, intensity=curve(_u2, t))',
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
32 {'_u1': URIRef('uri1'), '_u2': URIRef('uri2')}
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
33 """
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
34 lname, expr = [s.strip() for s in self.code.split('=', 1)]
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
35 self.uriCounter = 0
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
36 resources = {}
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
37
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
38 def alreadyInCurveFunc(s, i):
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
39 prefix = 'curve('
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
40 return i >= len(prefix) and s[i-len(prefix):i] == prefix
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
41
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
42 def repl(m):
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
43 v = '_res%s' % self.uriCounter
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
44 self.uriCounter += 1
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
45 r = resources[v] = URIRef(m.group(1))
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
46 if self._uriIsCurve(r):
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
47 if not alreadyInCurveFunc(m.string, m.start()):
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
48 return 'curve(%s, t)' % v
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
49 return v
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
50 outExpr = re.sub(r'<(http\S*?)>', repl, expr)
1108
4b542d321c8f effectnode runs multiple lines of code in dependency order
Drew Perttula <drewp@bigasterisk.com>
parents: 1107
diff changeset
51 return lname, expr, outExpr, resources
1103
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
52
1108
4b542d321c8f effectnode runs multiple lines of code in dependency order
Drew Perttula <drewp@bigasterisk.com>
parents: 1107
diff changeset
53 def findVars(self, expr):
4b542d321c8f effectnode runs multiple lines of code in dependency order
Drew Perttula <drewp@bigasterisk.com>
parents: 1107
diff changeset
54 """may return some more strings than just the vars"""
4b542d321c8f effectnode runs multiple lines of code in dependency order
Drew Perttula <drewp@bigasterisk.com>
parents: 1107
diff changeset
55 withoutUris = re.sub(r'<(http\S*?)>', 'None', expr)
4b542d321c8f effectnode runs multiple lines of code in dependency order
Drew Perttula <drewp@bigasterisk.com>
parents: 1107
diff changeset
56 tokens = set(re.findall(r'\b([a-zA-Z_]\w*)\b', withoutUris))
4b542d321c8f effectnode runs multiple lines of code in dependency order
Drew Perttula <drewp@bigasterisk.com>
parents: 1107
diff changeset
57 tokens.discard('None')
4b542d321c8f effectnode runs multiple lines of code in dependency order
Drew Perttula <drewp@bigasterisk.com>
parents: 1107
diff changeset
58 return tokens
4b542d321c8f effectnode runs multiple lines of code in dependency order
Drew Perttula <drewp@bigasterisk.com>
parents: 1107
diff changeset
59
1103
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
60 def _uriIsCurve(self, uri):
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
61 # this result could vary with graph changes (rare)
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
62 return self.graph.contains((uri, RDF.type, L9['Curve']))
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
63
1158
da006651b531 more timing logs in EE
drewp@bigasterisk.com
parents: 1154
diff changeset
64 @prof.logTime
1107
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
65 def _resourcesAsPython(self, resources):
1103
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
66 """
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
67 mapping of the local names for uris in the code to high-level
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
68 objects (Submaster, Curve)
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
69 """
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
70 out = {}
1158
da006651b531 more timing logs in EE
drewp@bigasterisk.com
parents: 1154
diff changeset
71 subs = prof.logTime(Submaster.get_global_submasters)(self.graph)
1107
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
72 for localVar, uri in resources.items():
1136
f48be3d18387 Strip can be scaled.
drewp@bigasterisk.com
parents: 1125
diff changeset
73
1103
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
74 for rdfClass in self.graph.objects(uri, RDF.type):
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
75 if rdfClass == L9['Curve']:
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
76 cr = CurveResource(self.graph, uri)
1158
da006651b531 more timing logs in EE
drewp@bigasterisk.com
parents: 1154
diff changeset
77 # this is slow- pool these curves somewhere, maybe just with curveset
da006651b531 more timing logs in EE
drewp@bigasterisk.com
parents: 1154
diff changeset
78 prof.logTime(cr.loadCurve)()
1103
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
79 out[localVar] = cr.curve
1136
f48be3d18387 Strip can be scaled.
drewp@bigasterisk.com
parents: 1125
diff changeset
80 break
1103
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
81 elif rdfClass == L9['Submaster']:
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
82 out[localVar] = subs.get_sub_by_uri(uri)
1136
f48be3d18387 Strip can be scaled.
drewp@bigasterisk.com
parents: 1125
diff changeset
83 break
1103
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
84 else:
1136
f48be3d18387 Strip can be scaled.
drewp@bigasterisk.com
parents: 1125
diff changeset
85 out[localVar] = CouldNotConvert(uri)
f48be3d18387 Strip can be scaled.
drewp@bigasterisk.com
parents: 1125
diff changeset
86 break
f48be3d18387 Strip can be scaled.
drewp@bigasterisk.com
parents: 1125
diff changeset
87 else:
f48be3d18387 Strip can be scaled.
drewp@bigasterisk.com
parents: 1125
diff changeset
88 out[localVar] = CouldNotConvert(uri)
1052
b370618ce723 split EffectNode out of effecteval
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
89
1103
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
90 return out
1136
f48be3d18387 Strip can be scaled.
drewp@bigasterisk.com
parents: 1125
diff changeset
91
1107
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
92 class EffectNode(object):
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
93 def __init__(self, graph, uri):
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
94 self.graph, self.uri = graph, uri
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
95 # this is not expiring at the right time, when an effect goes away
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
96 self.graph.addHandler(self.prepare)
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
97
1154
1e97f96ee00c faster effect reload
drewp@bigasterisk.com
parents: 1136
diff changeset
98 @prof.logTime
1107
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
99 def prepare(self):
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
100 log.info("prepare effect %s", self.uri)
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
101 # maybe there can be multiple lines of code as multiple
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
102 # objects here, and we sort them by dependencies
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
103 codeStrs = list(self.graph.objects(self.uri, L9['code']))
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
104 if not codeStrs:
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
105 raise ValueError("effect %s has no code" % self.uri)
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
106
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
107 self.codes = [CodeLine(self.graph, s) for s in codeStrs]
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
108
1108
4b542d321c8f effectnode runs multiple lines of code in dependency order
Drew Perttula <drewp@bigasterisk.com>
parents: 1107
diff changeset
109 self.sortCodes()
1125
57eb333e6a4c reload Effects.py when graph changes. quieter logging
Drew Perttula <drewp@bigasterisk.com>
parents: 1113
diff changeset
110
1154
1e97f96ee00c faster effect reload
drewp@bigasterisk.com
parents: 1136
diff changeset
111 #reload(Effects)
1e97f96ee00c faster effect reload
drewp@bigasterisk.com
parents: 1136
diff changeset
112 self.otherFuncs = prof.logTime(Effects.configExprGlobals)()
1108
4b542d321c8f effectnode runs multiple lines of code in dependency order
Drew Perttula <drewp@bigasterisk.com>
parents: 1107
diff changeset
113
4b542d321c8f effectnode runs multiple lines of code in dependency order
Drew Perttula <drewp@bigasterisk.com>
parents: 1107
diff changeset
114 def sortCodes(self):
4b542d321c8f effectnode runs multiple lines of code in dependency order
Drew Perttula <drewp@bigasterisk.com>
parents: 1107
diff changeset
115 """put self.codes in a working evaluation order"""
4b542d321c8f effectnode runs multiple lines of code in dependency order
Drew Perttula <drewp@bigasterisk.com>
parents: 1107
diff changeset
116 codeFromOutput = dict((c.outName, c) for c in self.codes)
4b542d321c8f effectnode runs multiple lines of code in dependency order
Drew Perttula <drewp@bigasterisk.com>
parents: 1107
diff changeset
117 deps = {}
4b542d321c8f effectnode runs multiple lines of code in dependency order
Drew Perttula <drewp@bigasterisk.com>
parents: 1107
diff changeset
118 for c in self.codes:
4b542d321c8f effectnode runs multiple lines of code in dependency order
Drew Perttula <drewp@bigasterisk.com>
parents: 1107
diff changeset
119 outName = c.outName
4b542d321c8f effectnode runs multiple lines of code in dependency order
Drew Perttula <drewp@bigasterisk.com>
parents: 1107
diff changeset
120 inNames = c.possibleVars.intersection(codeFromOutput.keys())
4b542d321c8f effectnode runs multiple lines of code in dependency order
Drew Perttula <drewp@bigasterisk.com>
parents: 1107
diff changeset
121 inNames.discard(outName)
4b542d321c8f effectnode runs multiple lines of code in dependency order
Drew Perttula <drewp@bigasterisk.com>
parents: 1107
diff changeset
122 deps[outName] = inNames
4b542d321c8f effectnode runs multiple lines of code in dependency order
Drew Perttula <drewp@bigasterisk.com>
parents: 1107
diff changeset
123 self.codes = [codeFromOutput[n] for n in toposort.toposort_flatten(deps)]
4b542d321c8f effectnode runs multiple lines of code in dependency order
Drew Perttula <drewp@bigasterisk.com>
parents: 1107
diff changeset
124
1052
b370618ce723 split EffectNode out of effecteval
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
125 def eval(self, songTime):
1103
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
126 ns = {'t': songTime}
1107
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
127 ns.update(self.otherFuncs)
1103
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
128
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
129 ns.update(dict(
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
130 curve=lambda c, t: c.eval(t),
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
131 ))
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
132
1107
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
133 for c in self.codes:
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
134 codeNs = ns.copy()
512381de45bd effectclasss in subserver. multiline code suppport (except for evaulation). add some old effect funcs to the new evaluator
Drew Perttula <drewp@bigasterisk.com>
parents: 1103
diff changeset
135 codeNs.update(c.pyResources)
1108
4b542d321c8f effectnode runs multiple lines of code in dependency order
Drew Perttula <drewp@bigasterisk.com>
parents: 1107
diff changeset
136 lineOut = eval(c.expr, codeNs)
4b542d321c8f effectnode runs multiple lines of code in dependency order
Drew Perttula <drewp@bigasterisk.com>
parents: 1107
diff changeset
137 ns[c.outName] = lineOut
4b542d321c8f effectnode runs multiple lines of code in dependency order
Drew Perttula <drewp@bigasterisk.com>
parents: 1107
diff changeset
138 if 'out' not in ns:
4b542d321c8f effectnode runs multiple lines of code in dependency order
Drew Perttula <drewp@bigasterisk.com>
parents: 1107
diff changeset
139 log.error("ran code for %s, didn't make an 'out' value", self.uri)
4b542d321c8f effectnode runs multiple lines of code in dependency order
Drew Perttula <drewp@bigasterisk.com>
parents: 1107
diff changeset
140 return ns['out']
1103
771f50f19b4b single-line effect code now evals by changing <uri> into a suitable python object
Drew Perttula <drewp@bigasterisk.com>
parents: 1076
diff changeset
141