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