[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Fab-user] List of files in directory
From: |
Jeff Forcier |
Subject: |
Re: [Fab-user] List of files in directory |
Date: |
Sun, 10 Jul 2011 18:39:06 -0700 |
Hi Ricklef,
On Fri, Jul 8, 2011 at 10:45 AM, Ricklef Wohlers
<address@hidden> wrote:
> I seem unable to find a good way of retrieving a filelist for a certain
> directory. Currently, I'm using run("ls dir") and am manually splitting the
> return string, which seems horrendous and very much architecture dependent.
Fabric is really just a pass-through for shell commands and a way to
inspect the return value/stdout/stderr. Thus, Fabric scripts typically
have to marry a moderate amount of shell manipulation with appropriate
local Python string manipulation.
So how would you be doing this in a shell script run on the remote
end? How would you do it in a Python script run on the remote end, if
all it had access to was subprocess (i.e. no os.listdir)?
Re: your specific example/question, GNU 'ls' takes a -1 flag (note:
one, not L) causing it to list files one per line; if your remote end
is a GNU userland, you can thus be pretty sure that run("ls -1
<directory>").splitlines() will always give you a Python iterable of
filenames, regardless of whether those filenames contain spaces.
If your target system's 'ls' lacks the -1 flag, you could use the
'find' tool, which also by default prints filenames separated by a
newline character. Etc.
Hope that helps some!
Best,
Jeff
--
Jeff Forcier
Unix sysadmin; Python/Ruby engineer
http://bitprophet.org