Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.
Originally posted by: xathrasHi,
Below is an example node I have:
import braininfo
import gzip
def setup(brainNodeControlObj, BrainNodeClass):
''' Must return a class that inherits from BrainNodeClass. '''
class BrainNode(BrainNodeClass):
def initialize(self):
''' Called at node initialization, before first pump.'''
super(BrainNode, self).initialize()
def finalize(self, val):
''' Called at node end, after last pump call. '''
super(BrainNode, self).finalize(val)
def pump(self, quant):
''' Will continue to be called until False is returned.
Only a small amount of work should be done in pump without checking
quant.permitsRunning. When that returns False, return from pump
with a True value to be called again, a False value when finished.'''
while quant.permitsRunning(self):
# your code here
import zipfile
import glob, os
# open the zip file for writing, and write stuff to it
file = zipfile.ZipFile("{{^OutputDirectory^}}/File.zip", "w")
for name in glob.glob("{{^OutputDirectory^}}/*csv"):
file.write(name, os.path.basename(name), zipfile.ZIP_DEFLATED)
file.close()
# when complete
return False
# finished your quantum, you want pump called again
return True
# If you implement your logic here, you don't need code below. If you want
# to inherit, and add more logic at next level, uncomment below code
# py3File = brainNodeControlObj.properties.getString("ls.brain .node.BrainPython.python3ImplementationFile")
# braininfo.loadModule(py3File, "py3", brainNodeControlObj)
# import py3
# BrainNodeImpl = py3.setup(brainNodeControlObj, BrainNode)
# return BrainNodeImpl
return BrainNode