Is it possible to define tasks inside a class (so that variables can be shared between tasks)?

33 views
Skip to first unread message

gustavs...@gmail.com

unread,
May 28, 2013, 8:14:39 PM5/28/13
to pa...@googlegroups.com
An idea (that doesn't seem to work):

class Spark():
    @task
    def launch():
        print "launched cluster"
        self.ssh = "sshconnected"

    @task
    @needs('launch')
    def s3import():
        print "imported data from s3 to hdfs"
        print self.ssh


The reason I want to be able to do this is that I open an ssh connection in the first task, and I want the following tasks to be able to re-use the same ssh connection.

Is something like this possible?

Randy Syring

unread,
May 29, 2013, 9:11:18 AM5/29/13
to pa...@googlegroups.com, gustavs...@gmail.com
Does paver instantiate Spark?  If so, then creating your ssh connection in def __init__(...): should work:

http://docs.python.org/2/reference/datamodel.html#object.__init__

Randy Syring
Development | Executive Director
Direct: 502.276.0459
Office: 812.285.8766

Level 12
            Technologies
Principled People | Technology that Works

--
You received this message because you are subscribed to the Google Groups "paver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to paver+un...@googlegroups.com.
To post to this group, send email to pa...@googlegroups.com.
Visit this group at http://groups.google.com/group/paver?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

gustavs...@gmail.com

unread,
May 29, 2013, 2:54:19 PM5/29/13
to pa...@googlegroups.com
Thanks for the reply. I ended up using a global variable for ssh, as it was the cleanest way I could see to share variables between separate paver tasks.

Gregory Nicholas

unread,
Jun 12, 2013, 4:33:46 PM6/12/13
to pa...@googlegroups.com
since i believe you're not referring to command line options, but environ options, you can use the environment options. ex:

spark.py:

    from paver.easy import options, Bunch
    spark_config = {"abs": "trics", "gluts": "calves"}
    options(
        spark=Bunch(**spark_config)
    )


pavement.py:

    import spark
    from paver.easy import task, options
    
    @task
    def s3_put():
        print options.spark.
        
    @task
    def s3_get():
        print options.spark.
Reply all
Reply to author
Forward
0 new messages