LAE

Welcome to the LAE community!  Please feel free to start a discussion in the discussion tab or join in a conversation.

Discussions

Members

Resources

Events

 View Only
  • 1.  Zip?

    Employee
    Posted 08-03-2010 23:15

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: PGeee

    I assume there is no node to zip files?


  • 2.  RE: Zip?

    Employee
    Posted 08-04-2010 02:45

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: xathras

    Hi,
    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


  • 3.  RE: Zip?

    Employee
    Posted 08-04-2010 05:40

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Tim Meagher

    As implied by the above post, there are no built-in zip/unzip nodes at the moment in the LAE, and the best way to perform these operations is with a custom python node.

    There are, however plans to introduce zip/unzip nodes in future releases.

    From the looks of that code, the node posted is specifically for zipping all csv files in a given directory into a zip file with the name "File.zip" in the same directory, however it should be relatively straightforward to customize this code for your own purposes.