Permalink
Browse files

finishing touches

  • Loading branch information...
1 parent 85e96c4 commit 79b42a8c882152676e6b818f46d89b84354b4ad2 @tomerfiliba committed Dec 14, 2012
Showing with 50 additions and 21 deletions.
  1. +2 −2 docs/local_commands.rst
  2. +14 −0 docs/remote.rst
  3. +18 −19 plumbum/paramiko_machine.py
  4. +16 −0 tests/_test_paramiko.py
View
@@ -33,8 +33,8 @@ With just a touch of magic, you can *import* commands from the mock module ``cmd
.. note::
There's no real module named ``plumbum.cmd``; it's a dynamically-created "module", injected
- into ``sys.modules`` to enable the use of ``from plumbum.cmd import foo``. Attempting to
- ``import plumbum.cmd`` is bound to fail.
+ into ``sys.modules`` to enable the use of ``from plumbum.cmd import foo``. As of version 1.1,
+ you can actually ``import plumbum.cmd``, for consistency, but it's not recommended.
It is important to stress that ``from plumbum.cmd import foo`` translates to ``local["foo"]``
behind the scenes.
View
@@ -187,6 +187,20 @@ can simply create an extra *channel* on top of the same underlying connection wi
exposed by ``connect_sock()``, which creates a tunneled TCP connection and returns a socket-like
object
+.. warning::
+ Piping and input/output redirection don't really work with ``ParamikoMachine`` commands.
+ You'll get all kinds of errors, like ``'ChannelFile' object has no attribute 'fileno'`` or
+ ``I/O operation on closed file`` -- this is due to the fact that Paramiko's channels are not
+ real, OS-level files, so they can't interact with ``subprocess.Popen``.
+
+ This will be solved in a later release; in the meanwhile, you can use the machine's
+ ``.session()`` method, like so ::
+
+ >>> s = mach.session()
+ >>> s.run("ls | grep b")
+ (0, u'bin\nPublic\n', u'')
+
+
Tunneling Example
^^^^^^^^^^^^^^^^^
@@ -57,7 +57,11 @@ def communicate(self):
i = 0
while sources:
if infile:
- line = infile.readline()
+ try:
+ line = infile.readline()
+ except (ValueError, IOError):
+ line = None
+ print "!!", repr(line)
if not line:
infile.close()
infile = None
@@ -271,24 +275,19 @@ def _path_write(self, fn, data):
# Make paramiko.Channel adhere to the socket protocol, namely, send and recv should fail
# when the socket has been closed
###################################################################################################
-if paramiko.__version__.split(".") <= ('1', '9', '0'):
- class SocketCompatibleChannel(object):
- def __init__(self, chan):
- self._chan = chan
- def __getattr__(self, name):
- return getattr(self._chan, name)
- def send(self, s):
- if self._chan.closed:
- raise socket.error(errno.EBADF, 'Bad file descriptor')
- return self._chan.send(s)
- def recv(self, count):
- if self._chan.closed:
- raise socket.error(errno.EBADF, 'Bad file descriptor')
- return self._chan.recv(count)
-else:
- SocketCompatibleChannel = lambda x: x
-
-
+class SocketCompatibleChannel(object):
+ def __init__(self, chan):
+ self._chan = chan
+ def __getattr__(self, name):
+ return getattr(self._chan, name)
+ def send(self, s):
+ if self._chan.closed:
+ raise socket.error(errno.EBADF, 'Bad file descriptor')
+ return self._chan.send(s)
+ def recv(self, count):
+ if self._chan.closed:
+ raise socket.error(errno.EBADF, 'Bad file descriptor')
+ return self._chan.recv(count)
View
@@ -0,0 +1,16 @@
+from plumbum.paramiko_machine import ParamikoMachine as PM
+from plumbum import local
+local.env.path.append("c:\\progra~1\\git\\bin")
+from plumbum.cmd import ls, grep
+
+
+m=PM("192.168.1.143")
+mls=m["ls"]
+mgrep=m["grep"]
+#(mls | mgrep["b"])()
+
+(mls | grep["\\."])()
+
+(ls | mgrep["\\."])()
+
+

0 comments on commit 79b42a8

Please sign in to comment.