Gerard Petersen wrote: > Guido, > > Thanx for the code snippet. Initially I wanted to keep the code that goes > remote as clean as possible (somebody told me ... ;-) but > the code you came up with does seem good. > > The actual issue is somewhat more elaborate. I also have remote functions > that > read files, and a predicatble situation is that a file might not be there > remotely. Since this is a possibiltity and not an exception as such, (next to > a "permission denied" which is). There is also the possibility to return an > error value along all the time. You then would still need some error handling > remotely but the last line in your function would be something like "return > contents, error". > "Error" containing a level from zero upwards. I'll see if I can combine a > setup like that with the "isinstance" function. > > More on the way, Thanx guys!!
You might take a look at the ll.url module which is part of XIST (available from: http://www.livinglogic.de/Python/Download.html ll.url implements an ssh URL scheme which supports all file operations remotely: >>> from ll import url >>> u = url.URL("ssh://[EMAIL PROTECTED]/~/") >>> u.listdir(context=url.Context()) [URL('.bash_history'), URL('.profile'), URL('.bashrc'), ... >>> u = url.URL("ssh://[EMAIL PROTECTED]/~/.bash_history") >>> f = u.open("rb", context=url.Context()) >>> f.readline() '/etc/init.d/tomcat stop\n' >>> f.readline() 'ps waux | grep tomcat\n' It mirrors exceptions locally: >>> u = url.URL("ssh://[EMAIL PROTECTED]/~/does-not-exist") >>> f = u.open("rb", context=url.Context()) [...] IOError: [Errno 2] No such file or directory: '/root/does-not-exist' (of course this only works for builtin exceptions) And of course ll.url uses py.execnet for communicating with the remote host. Hope that helps! Servus, Walter _______________________________________________ py-dev mailing list py-dev@codespeak.net http://codespeak.net/mailman/listinfo/py-dev