def __enter__ (self): self.client= paramiko.SSHClient () self.client.load_host_keys (bash ('~/.ssh/known_hosts')[0]) self.client.connect (self.hostname, *self.args, **self.kwargs) # get the locals from the runtime # we can't really export the globals: it's full of unpicklable things # so send an empty environment global_env= pickle.dumps ({}) # for solving the import problem: # _pickle.PicklingError: Can't pickle <class 'module'>: attribute lookup builtins.module failed # there are two solutions. either we setup a complex system that intercepts # the imports and hold them in another ayrton.Environment attribute # or we just weed them out here. so far this is the simpler option # but forces the user to reimport what's going to be used in the remote l= dict ([ (k, v) for (k, v) in ayrton.runner.environ.locals.items () if type (v)!=types.ModuleType ]) # special treatment for argv l['argv']= ayrton.runner.environ.ayrton_builtins['argv'] local_env= pickle.dumps (l) if self.python_only: command= '''python3 -c "import pickle # names needed for unpickling from ast import Module, Assign, Name, Store, Call, Load, Expr import sys ast= pickle.loads (sys.stdin.buffer.read (%d)) code= compile (ast, 'remote', 'exec') g= pickle.loads (sys.stdin.buffer.read (%d)) l= pickle.loads (sys.stdin.buffer.read (%d)) exec (code, g, l)"''' % (len (self.ast), len (global_env), len (local_env)) else: command= '''python3 -c "import pickle # names needed for unpickling from ast import Module, Assign, Name, Store, Call, Load, Expr import sys import ayrton ast= pickle.loads (sys.stdin.buffer.read (%d)) g= pickle.loads (sys.stdin.buffer.read (%d)) l= pickle.loads (sys.stdin.buffer.read (%d)) ayrton.run (ast, g, l)"''' % (len (self.ast), len (global_env), len (local_env)) (i, o, e)= self.client.exec_command (command) i.write (self.ast) i.write (global_env) i.write (local_env) return (i, o, e)
def test_tilde (self): self.assertEqual (bash ('~'), [ os.environ['HOME'] ])
def test_escaped_brace (self): self.assertEqual (bash ('\{a,b}'), [ '{a,b}' ])
def test_simple5_brace(self): self.assertEqual(bash("a{bfgh,{ci,djkl}e"), ["a{bfgh,cie", "a{bfgh,djkle"])
def test_nested2_brace (self): self.assertEqual (bash ('{c{a,b}d,e{f,g}h}'), [ 'cad', 'cbd', 'efh', 'egh' ])
def test_simple5_brace (self): self.assertEqual (bash ('a{bfgh,{ci,djkl}e'), [ 'a{bfgh,cie', 'a{bfgh,djkle' ])
def test_simple2_brace (self): self.assertEqual (bash ('a{b,ce}d'), [ 'abd', 'aced' ])
def test_glob2 (self): self.assertEqual (sorted (bash ([ '*.py', '*.txt' ])), [ 'LICENSE.txt', 'requirements.txt', 'setup.py', ])
def test_escaped_brace_single(self): self.assertEqual(bash("\{a,b}", single=True), "{a,b}")
def test_escaped_brace(self): self.assertEqual(bash("\{a,b}"), ["{a,b}"])
def test_nested2_brace(self): self.assertEqual(bash("{c{a,b}d,e{f,g}h}"), ["cad", "cbd", "efh", "egh"])
def test_nested1_brace(self): # note how this is equivalent to a{b,c,d}e! self.assertEqual(bash("a{b,{c,d}}e"), ["abe", "ace", "ade"])
def test_simple7_brace(self): self.assertEqual(bash("foo{,bar}"), ["foo", "foobar"])
def test_simple6_brace(self): self.assertEqual(bash("{a,{b,c}d}"), ["a", "bd", "cd"])
def test_simple_string (self): self.assertEqual (bash ('s'), [ 's' ])
def test_glob1 (self): self.assertEqual (bash ('*.py'), [ 'setup.py' ])
def test_glob_brace2 (self): self.assertEqual (sorted (bash ('ayrton/tests/data/{a,*.py}')), [ 'ayrton/tests/data/a', 'ayrton/tests/data/test.me.py' ])
def test_tilde_single (self): self.assertEqual (bash ('~', single=True), os.environ['HOME'])
def test_simple4_brace (self): self.assertEqual (bash ('a}'), [ 'a}' ])
def test_simple7_brace (self): self.assertEqual (bash ('foo{,bar}'), [ 'foo', 'foobar' ])
def test_simple_string_single (self): self.assertEqual (bash ('s', single=True), 's')
def test_escaped_brace_single (self): self.assertEqual (bash ('\{a,b}', single=True), '{a,b}')
def test_glob1_single (self): self.assertEqual (bash ('*.py', single=True), 'setup.py')
def test_glob_brace1 (self): self.assertEqual (sorted (bash ('s{a,*.py}')), [ 'sa', 'setup.py' ])
def test_simple1_brace (self): self.assertEqual (bash ('{acde,b}'), [ 'acde', 'b' ])
def test_simple3_brace (self): self.assertEqual (bash ('{a}'), [ '{a}' ])
def test_simple4_brace_single (self): self.assertEqual (bash ('a}', single=True), 'a}')
def test_simple6_brace (self): self.assertEqual (bash ('{a,{b,c}d}'), [ 'a', 'bd', 'cd' ])
def test_nested1_brace (self): # note how this is equivalent to a{b,c,d}e! self.assertEqual (bash ('a{b,{c,d}}e'), [ 'abe', 'ace', 'ade' ])
def test_simple4_brace_single(self): self.assertEqual(bash("a}", single=True), "a}")