Hi, Thanks for the answer. I think it would be fair to state that using bash commands aren't the most pythonic way of doing this. >From what I understand, fabric uses paramiko. Would it make sense to extend >fabric.contrib.files with some wrappers for paramiko.sftpclient functions? >Alternatively it would make sense to allow access to the sftp functions.. I was thinking of writing a patch to add the wrapper functions, but would only do so if it would actually have a chance of being added to fabric. Would it have a chance?
Cheers, Rick Ps: fabric is awesome! On 11 Jul 2011, at 02:39, Jeff Forcier wrote: > Hi Ricklef, > > On Fri, Jul 8, 2011 at 10:45 AM, Ricklef Wohlers > <[email protected]> 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 _______________________________________________ Fab-user mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/fab-user
