[svn r37985] make sure that host.initgateway() will always

have the other side chdir()ed to home,
thus generalizing 37971 with respect to platform
support and making it independent from gateway
implementation details.

--HG--
branch : trunk
This commit is contained in:
hpk 2007-02-05 23:46:31 +01:00
parent 102409a846
commit 4af00f6682
2 changed files with 28 additions and 9 deletions

View File

@ -6,7 +6,6 @@ from py.__.test.rsession.master import MasterNode
from py.__.test.rsession.slave import setup_slave from py.__.test.rsession.slave import setup_slave
from py.__.test.rsession import repevent from py.__.test.rsession import repevent
from py.__.execnet.register import PopenCmdGateway
class HostInfo(object): class HostInfo(object):
""" Class trying to store all necessary attributes """ Class trying to store all necessary attributes
@ -33,24 +32,22 @@ class HostInfo(object):
def initgateway(self, python="python"): def initgateway(self, python="python"):
assert not hasattr(self, 'gw') assert not hasattr(self, 'gw')
if self.hostname == "localhost": if self.hostname == "localhost":
cmd = 'cd ~; %s -u -c "exec input()"' % python gw = py.execnet.PopenGateway(python=python)
gw = PopenCmdGateway(cmd)
else: else:
gw = py.execnet.SshGateway(self.hostname, gw = py.execnet.SshGateway(self.hostname,
remotepython=python) remotepython=python)
self.gw = gw self.gw = gw
channel = gw.remote_exec(""" channel = gw.remote_exec(py.code.Source(gethomedir, """
import os import os
targetdir = %r targetdir = %r
homedir = gethomedir()
if not os.path.isabs(targetdir): if not os.path.isabs(targetdir):
homedir = os.environ.get('HOME', '')
if not homedir:
homedir = os.environ.get('HOMEPATH', '.')
targetdir = os.path.join(homedir, targetdir) targetdir = os.path.join(homedir, targetdir)
if not os.path.exists(targetdir): if not os.path.exists(targetdir):
os.makedirs(targetdir) os.makedirs(targetdir)
channel.send(os.path.abspath(targetdir)) os.chdir(homedir)
""" % self.relpath) channel.send(targetdir)
""" % self.relpath))
self.gw_remotepath = channel.receive() self.gw_remotepath = channel.receive()
#print "initialized", gw, "with remotepath", self.gw_remotepath #print "initialized", gw, "with remotepath", self.gw_remotepath
if self.hostname == "localhost": if self.hostname == "localhost":
@ -177,3 +174,10 @@ class HostManager(object):
except: except:
pass pass
channel.gateway.exit() channel.gateway.exit()
def gethomedir():
import os
homedir = os.environ.get('HOME', '')
if not homedir:
homedir = os.environ.get('HOMEPATH', '.')
return homedir

View File

@ -37,6 +37,20 @@ class TestHostInfo:
py.test.raises((py.process.cmdexec.Error, IOError, EOFError), py.test.raises((py.process.cmdexec.Error, IOError, EOFError),
host.initgateway) host.initgateway)
def test_remote_has_homedir_as_currentdir(self):
host = HostInfo("localhost")
old = py.path.local.get_temproot().chdir()
try:
host.initgateway()
channel = host.gw.remote_exec("""
import os
channel.send(os.getcwd())
""")
dir = channel.receive()
assert dir == py.path.local._gethomedir()
finally:
old.chdir()
def test_initgateway_localhost_relpath(self): def test_initgateway_localhost_relpath(self):
name = "pytestcache-localhost" name = "pytestcache-localhost"
x = HostInfo("localhost:%s" % name) x = HostInfo("localhost:%s" % name)
@ -160,3 +174,4 @@ class TestHostManager(DirSetup):
assert not self.dest.join("dir1", "dir2").check() assert not self.dest.join("dir1", "dir2").check()
assert self.dest.join("dir5","file").check() assert self.dest.join("dir5","file").check()
assert not self.dest.join("dir6").check() assert not self.dest.join("dir6").check()