fab-user
[Top][All Lists]
Advanced

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

Re: [Fab-user] Reading a remote file into memory


From: Jeff Forcier
Subject: Re: [Fab-user] Reading a remote file into memory
Date: Thu, 10 Oct 2013 18:09:48 -0700

Hi Jon,

Depends on the file. You certainly can use run('cat') and then
interact with the stdout value (run()'s return acts like a string
containing stdout, by default).

For anything that doesn't play nice with that (e.g. funky nonprinting
characters) the put/get functions can take StringIO arguments for the
'local' side of things, so you should be able to do e.g.:

    contents = StringIO()
    get('/path/to/file', contents)
    # operate on 'contents' like a file object here, e.g. 'print
contents.getvalue()'

-Jeff

On Thu, Oct 10, 2013 at 4:16 AM, Jon Dufresne <address@hidden> wrote:
> Hi,
>
> What is considered the best way to read a remote file into memory to
> be used by Python or Fabric? Should I shell out to cat on the server
> "contents = run('cat /path/to/file')" or is there a better way?
>
> My Fabric file requires parsing a file to continue other operations on
> the server.
>
> Thanks,
> Jon
>
> _______________________________________________
> Fab-user mailing list
> address@hidden
> https://lists.nongnu.org/mailman/listinfo/fab-user



-- 
Jeff Forcier
Unix sysadmin; Python/Ruby engineer
http://bitprophet.org



reply via email to

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