Topic: The Python and the Dead Cow
I recently had to write some rather involved nWare python scripts, and I immediately ran into the problems that makes any serious scripting next to impossible using the built in editor.
However, I figured out it would be rather easy to 'simulate' running a python script the way it is run into nWare, but outside of nWare. Using a normal shell, editor and so on.
So, at the risk of beating a dead cow, I'll explain how I did it.
The idea is to prepends some python that sets up 'variables' that simulate the extensions defined by nWare. Typically, inputs/outputs/message and event.wait().
Once you have that, you can enter a set of input values yourself, in code, then run the script into the shell (cygwyn, linux, or whatever command line you fancy), and watch the outputs.
When you are happy with the logic, copy/paste your script (minus the simulator glue) back into nWare editor and test 'live'. It's surprisingly painless once it gets going, and you get the advantage of being able to choose your editor, and have proper error messages with line numbers (wheee!) etc. Oh and you can use the best debugger of them all : 'print' !
Here is the prefix I used. It's easily extensible to handle numerical values and so on..
import sys
import time
# this allows the script to do "event.wait(xxxx)"
class Event:
def wait(self,long):
time.sleep(long/1000)
global event
event = Event()
# this simulates inputs, outputs and message.Extends to implement the other methods
class nWare:
def __init__(self, what,value):
self.what = what
self.value = value
def string_get(self):
return str(self.value)
def string_set(self,value):
self.value = str(value)
print ">>%s = %s" % (self.what, self.value)
# declares this particular script input and outputs. You can set whatever values you fancy.
global inputs, outputs, message
inputs = [ \
nWare("inputs[0]", "reserved"), \
nWare("inputs[1]","10.18.10.45|1|1|0|0|0"), \
nWare("inputs[2]","10.10.0.44|1|0|0|0|0") \
];
outputs = [ \
nWare("logger","logger"), \
nWare("outputs[1]",""), \
nWare("outputs[2]","") ];
message = nWare("message","")
# your own script starts here !