Skip to content

Commit

Permalink
add PuttyMachine. closes #37
Browse files Browse the repository at this point in the history
  • Loading branch information
tomerfiliba committed Oct 20, 2012
1 parent 2d34afe commit 8863dcd
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 8 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
1.0.1
=====
* Windows: path are no longer converted to lower-case, but ``__eq__`` and ``__hash__`` operate on
the lower-cased result `#38 <https://github.com/tomerfiliba/plumbum/issues/38>`_
* Properly handle empty strings in the argument list `#41 <https://github.com/tomerfiliba/plumbum/issues/41>`_
* Relaxed type-checking of ``LocalPath`` and ``RemotePath`` `#35 <https://github.com/tomerfiliba/plumbum/issues/35>`_
* Added ``PuttyMachine`` for Windows users that relies on ``plink`` and ``pscp``
(instead of ``ssh`` and ``scp``) `#37 <https://github.com/tomerfiliba/plumbum/issues/37>`_

1.0.0
=====
* Rename ``cli.CountingAttr`` to ``cli.CountOf``
Expand Down
2 changes: 1 addition & 1 deletion plumbum/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
from plumbum.commands import ProcessExecutionError, CommandNotFound, ProcessTimedOut
from plumbum.path import Path
from plumbum.local_machine import local, LocalPath
from plumbum.remote_machine import SshMachine, RemotePath
from plumbum.remote_machine import SshMachine, RemotePath, PuttyMachine
from plumbum.version import version as __version__

__author__ = "Tomer Filiba ([email protected])"
Expand Down
16 changes: 11 additions & 5 deletions plumbum/local_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,17 @@ def _set_home(self, p):
@property
def user(self):
"""Return the user name, or ``None`` if it is not set"""
if "USER" in self:
return self["USER"]
elif "USERNAME" in self:
return self["USERNAME"]
return None
# adapted from getpass.getuser()
for name in ('LOGNAME', 'USER', 'LNAME', 'USERNAME'):
if name in self:
return self[name]
try:
# POSIX only
import pwd
except ImportError:
return None
else:
return pwd.getpwuid(os.getuid())[0] #@UndefinedVariable


class LocalEnv(BaseEnv):
Expand Down
36 changes: 34 additions & 2 deletions plumbum/remote_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ def __init__(self, host, user = None, port = None, keyfile = None, ssh_command =
scp_args.extend(scp_opts)
self._ssh_command = ssh_command[tuple(ssh_args)]
self._scp_command = scp_command[tuple(scp_args)]
BaseRemoteMachine.__init__(self)
BaseRemoteMachine.__init__(self, encoding)

def __str__(self):
return "ssh://%s" % (self._fqhost,)
Expand All @@ -378,7 +378,7 @@ def popen(self, args, ssh_opts = (), **kwargs):

@_setdoc(BaseRemoteMachine)
def session(self, isatty = False):
return ShellSession(self.popen((), ["-tt"] if isatty else []), self.encoding, isatty)
return ShellSession(self.popen((), ["-tt"] if isatty else ["-T"]), self.encoding, isatty)

def tunnel(self, lport, dport, lhost = "localhost", dhost = "localhost"):
r"""Creates an SSH tunnel from the TCP port (``lport``) of the local machine
Expand Down Expand Up @@ -450,3 +450,35 @@ def upload(self, src, dst):
raise TypeError("dst %r points to a different remote machine" % (dst,))
self._scp_command(src, "%s:%s" % (self._fqhost, shquote(dst)))


class PuttyMachine(SshMachine):
"""
PuTTY-flavored SSH connection. The programs ``plink`` and ``pscp`` are expected to
be in the path (or you may supply
"""
def __init__(self, host, user = None, port = None, keyfile = None, ssh_command = None,
scp_command = None, ssh_opts = (), scp_opts = (), encoding = "utf8"):
if ssh_command is None:
ssh_command = local["plink"]
if scp_command is None:
scp_command = local["pscp"]
if not ssh_opts:
ssh_opts = ["-ssh"]
if user is None:
user = local.env.user
SshMachine.__init__(self, host, user, port, keyfile, ssh_command, scp_command,
ssh_opts, scp_opts)

def __str__(self):
return "ssh(putty)://%s" % (self._fqhost,)

@_setdoc(BaseRemoteMachine)
def session(self, isatty = False):
return ShellSession(self.popen((), ["-t"] if isatty else ["-T"]), self.encoding, isatty)







0 comments on commit 8863dcd

Please sign in to comment.