Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- Fix for issue where remote env changes weren't being used #122

Merged
merged 1 commit into from
May 2, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions plumbum/machines/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,18 @@ def getdelta(self):
"""Returns the difference between the this environment and the original environment of
the remote machine"""
self._curr["PATH"] = self.path.join()

delta = {}
for k, v in self._curr.items():
if k not in self._orig:
delta[k] = str(v)
for k, v in self._orig.items():
if k not in self._curr:
delta[k] = ""
else:
if v != self._curr[k]:
delta[k] = self._curr[k]

return delta


Expand Down Expand Up @@ -182,9 +187,10 @@ def which(self, progname):
alternatives.append(progname.replace("_", "-"))
alternatives.append(progname.replace("_", "."))
for name in alternatives:
rc, out, _ = self._session.run("which %s" % (shquote(name),), retcode = None)
if rc == 0:
return self.path(out.strip())
for p in self.env.path:
fn = p / progname
if fn.access("x"):
return fn

raise CommandNotFound(progname, self.env.path)

Expand Down
2 changes: 1 addition & 1 deletion plumbum/path/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def chmod(self, mode):
@_setdoc(Path)
def access(self, mode = 0):
mode = self._access_mode_to_flags(mode)
res = self._path_stat()
res = self.remote._path_stat(self)
if res is None:
return False
mask = res.st_mode & 0x1ff
Expand Down
11 changes: 9 additions & 2 deletions tests/test_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import time
import logging
from plumbum import RemotePath, SshMachine, ProcessExecutionError, local
from plumbum import CommandNotFound
from plumbum.lib import six


Expand Down Expand Up @@ -80,8 +81,7 @@ def test_basic(self):
r_grep = rem["grep"]

self.assertTrue(".bashrc" in r_ls("-a").splitlines())

with rem.cwd(os.path.dirname(__file__)):
with rem.cwd(os.path.dirname(os.path.abspath(__file__))):
cmd = r_ssh["localhost", "cd", rem.cwd, "&&", r_ls | r_grep["\\.py"]]
self.assertTrue("'|'" in str(cmd))
self.assertTrue("test_remote.py" in cmd())
Expand Down Expand Up @@ -115,6 +115,13 @@ def test_env(self):
out = rem.python("-c", "import os;print(os.environ['FOOBAR72'])")
self.assertEqual(out.strip(), "lala")

# path manipulation
self.assertRaises(CommandNotFound, rem.which, "dummy-executable")
with rem.cwd(os.path.dirname(os.path.abspath(__file__))):
rem.env.path.insert(0, rem.cwd / "not-in-path")
p = rem.which("dummy-executable")
self.assertEqual(p, rem.cwd / "not-in-path" / "dummy-executable")

def test_read_write(self):
with self._connect() as rem:
with rem.tempdir() as dir:
Expand Down