fab-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Fab-user] put() and command line args


From: Jeff Forcier
Subject: Re: [Fab-user] put() and command line args
Date: Mon, 20 Oct 2008 16:26:24 -0400

On Mon, Oct 20, 2008 at 12:35 PM, Philip Jacob <address@hidden> wrote:
> I'm trying to do the following, which I think will be clear from this
> example:
>
>        fab upload path/to/file.html another/file.html yet/another/file.html
>
> ... such that my upload() method will basically take a list of files on the
> command line and then put() each of them onto the fab_hosts.  However, fab
> assumes that path/to/file.html is a command that I want to execute.

It's been a while since I looked at this part of the code, but you
*can* pass arguments to Fab commands -- however, it's not space
delimited, because otherwise Fabric wouldn't be able to tell the
difference between command names and arguments (as you've found).

The format looks something like this:

    fab upload:arg1=val1,arg2=val2,...,argN=valN

So in your case, you probably want to do:

    fab 
upload:f1=path/to/file.html,f2=another/file.html,f3=yet/another/file.html

Then, your command can expect to get the arguments as keyword
arguments as is normal in Python:

    def upload(f1, f2, f3):
        put(f1)
        put(f2)
        ...

And, of course, you can do the usual ** trick to take any arbitrary
number of files to upload:

    def upload(**kwargs):
        for filename in kwargs.values():
            put(filename)

(Note that I am probably not using the right call signature for
'put()' here, as it's one part of Fabric I haven't used much yet :))

> I think there are two basic use cases when uploading a list of files:
>
> 1) you want to upload a few files (i.e. 5 or so)
>
> 2) you want to upload a ton of files (hundreds, etc.)
>
> In case #2, it makes more sense to create a file containing the list of
> files to upload and just iterate over that.  In case #1, convenience rules.

As in my above example, you can set up your commands to take any
arbitrary keyword-argument signature. Case #1 is well served by my
above example; case #2, you would just define a single argument and
expect it to be a filename, which you'd read and parse with the normal
Python tools for such things.

Hope this helps,
Jeff




reply via email to

[Prev in Thread] Current Thread [Next in Thread]