示例#1
0
    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)
示例#2
0
 def test_tilde (self):
     self.assertEqual (bash ('~'), [ os.environ['HOME'] ])
示例#3
0
 def test_escaped_brace (self):
     self.assertEqual (bash ('\{a,b}'), [ '{a,b}' ])
示例#4
0
 def test_simple5_brace(self):
     self.assertEqual(bash("a{bfgh,{ci,djkl}e"), ["a{bfgh,cie", "a{bfgh,djkle"])
示例#5
0
 def test_nested2_brace (self):
     self.assertEqual (bash ('{c{a,b}d,e{f,g}h}'), [ 'cad', 'cbd', 'efh', 'egh' ])
示例#6
0
 def test_simple5_brace (self):
     self.assertEqual (bash ('a{bfgh,{ci,djkl}e'), [ 'a{bfgh,cie', 'a{bfgh,djkle' ])
示例#7
0
 def test_simple2_brace (self):
     self.assertEqual (bash ('a{b,ce}d'), [ 'abd', 'aced' ])
示例#8
0
 def test_glob2 (self):
     self.assertEqual (sorted (bash ([ '*.py', '*.txt' ])), [ 'LICENSE.txt', 'requirements.txt', 'setup.py', ])
示例#9
0
 def test_escaped_brace_single(self):
     self.assertEqual(bash("\{a,b}", single=True), "{a,b}")
示例#10
0
 def test_escaped_brace(self):
     self.assertEqual(bash("\{a,b}"), ["{a,b}"])
示例#11
0
 def test_nested2_brace(self):
     self.assertEqual(bash("{c{a,b}d,e{f,g}h}"), ["cad", "cbd", "efh", "egh"])
示例#12
0
 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"])
示例#13
0
 def test_simple7_brace(self):
     self.assertEqual(bash("foo{,bar}"), ["foo", "foobar"])
示例#14
0
 def test_simple6_brace(self):
     self.assertEqual(bash("{a,{b,c}d}"), ["a", "bd", "cd"])
示例#15
0
 def test_simple_string (self):
     self.assertEqual (bash ('s'), [ 's' ])
示例#16
0
 def test_glob1 (self):
     self.assertEqual (bash ('*.py'), [ 'setup.py' ])
示例#17
0
 def test_tilde (self):
     self.assertEqual (bash ('~'), [ os.environ['HOME'] ])
示例#18
0
 def test_glob_brace2 (self):
     self.assertEqual (sorted (bash ('ayrton/tests/data/{a,*.py}')), [ 'ayrton/tests/data/a', 'ayrton/tests/data/test.me.py' ])
示例#19
0
 def test_tilde_single (self):
     self.assertEqual (bash ('~', single=True), os.environ['HOME'])
示例#20
0
 def test_simple4_brace (self):
     self.assertEqual (bash ('a}'), [ 'a}' ])
示例#21
0
 def test_simple_string (self):
     self.assertEqual (bash ('s'), [ 's' ])
示例#22
0
 def test_simple7_brace (self):
     self.assertEqual (bash ('foo{,bar}'), [ 'foo', 'foobar' ])
示例#23
0
 def test_simple_string_single (self):
     self.assertEqual (bash ('s', single=True), 's')
示例#24
0
 def test_escaped_brace_single (self):
     self.assertEqual (bash ('\{a,b}', single=True), '{a,b}')
示例#25
0
 def test_glob1 (self):
     self.assertEqual (bash ('*.py'), [ 'setup.py' ])
示例#26
0
 def test_nested2_brace (self):
     self.assertEqual (bash ('{c{a,b}d,e{f,g}h}'), [ 'cad', 'cbd', 'efh', 'egh' ])
示例#27
0
 def test_glob1_single (self):
     self.assertEqual (bash ('*.py', single=True), 'setup.py')
示例#28
0
 def test_escaped_brace_single (self):
     self.assertEqual (bash ('\{a,b}', single=True), '{a,b}')
示例#29
0
 def test_glob2 (self):
     self.assertEqual (sorted (bash ([ '*.py', '*.txt' ])), [ 'LICENSE.txt', 'requirements.txt', 'setup.py', ])
示例#30
0
 def test_tilde_single (self):
     self.assertEqual (bash ('~', single=True), os.environ['HOME'])
示例#31
0
 def test_glob_brace1 (self):
     self.assertEqual (sorted (bash ('s{a,*.py}')), [ 'sa', 'setup.py' ])
示例#32
0
 def test_simple_string_single (self):
     self.assertEqual (bash ('s', single=True), 's')
示例#33
0
 def test_glob_brace2 (self):
     self.assertEqual (sorted (bash ('ayrton/tests/data/{a,*.py}')), [ 'ayrton/tests/data/a', 'ayrton/tests/data/test.me.py' ])
示例#34
0
 def test_glob1_single (self):
     self.assertEqual (bash ('*.py', single=True), 'setup.py')
示例#35
0
 def test_simple1_brace (self):
     self.assertEqual (bash ('{acde,b}'), [ 'acde', 'b' ])
示例#36
0
 def test_glob_brace1 (self):
     self.assertEqual (sorted (bash ('s{a,*.py}')), [ 'sa', 'setup.py' ])
示例#37
0
 def test_simple2_brace (self):
     self.assertEqual (bash ('a{b,ce}d'), [ 'abd', 'aced' ])
示例#38
0
 def test_simple1_brace (self):
     self.assertEqual (bash ('{acde,b}'), [ 'acde', 'b' ])
示例#39
0
 def test_simple3_brace (self):
     self.assertEqual (bash ('{a}'), [ '{a}' ])
示例#40
0
 def test_simple3_brace (self):
     self.assertEqual (bash ('{a}'), [ '{a}' ])
示例#41
0
 def test_simple4_brace (self):
     self.assertEqual (bash ('a}'), [ 'a}' ])
示例#42
0
 def test_simple4_brace_single (self):
     self.assertEqual (bash ('a}', single=True), 'a}')
示例#43
0
 def test_simple4_brace_single (self):
     self.assertEqual (bash ('a}', single=True), 'a}')
示例#44
0
 def test_simple6_brace (self):
     self.assertEqual (bash ('{a,{b,c}d}'), [ 'a', 'bd', 'cd' ])
示例#45
0
 def test_simple5_brace (self):
     self.assertEqual (bash ('a{bfgh,{ci,djkl}e'), [ 'a{bfgh,cie', 'a{bfgh,djkle' ])
示例#46
0
 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' ])
示例#47
0
 def test_simple6_brace (self):
     self.assertEqual (bash ('{a,{b,c}d}'), [ 'a', 'bd', 'cd' ])
示例#48
0
 def test_escaped_brace (self):
     self.assertEqual (bash ('\{a,b}'), [ '{a,b}' ])
示例#49
0
 def test_simple7_brace (self):
     self.assertEqual (bash ('foo{,bar}'), [ 'foo', 'foobar' ])
示例#50
0
 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' ])
示例#51
0
 def test_simple4_brace_single(self):
     self.assertEqual(bash("a}", single=True), "a}")