1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 """C{py PYTHON_CODE}
19
20 C{PYTHON_CODE} is executed, and any variables defined are available to
21 subsequent commands in the same command line.
22
23 B{Example}::
24
25 osh py 'a = 123; b = 456' ^ f '(a, b)' $
26
27 This command generates the output C{'(123, 456)'}.
28
29 In addition to executing the specified code, input objects are passed
30 to the output stream.
31 """
32
33 import sys
34
35 import osh.args
36 import osh.core
37
38
41
42
44 """C{python_code} is executed. Any symbols defined by the execution of this
45 code are available to subsequent osh commands. Input objects are passed to
46 the output stream.
47 """
48 return _Py().process_args(python_code)
49
50 -class _Py(osh.core.Op):
51
52
53
56
57
58
59
62
64 code = self.args().next_string()
65 before = globals().copy()
66 exec code in globals()
67 after = globals()
68
69 for key, value in after.iteritems():
70 if key not in before:
71 osh.core.add_to_namespace(key, value)
72
75
76
77
78
81