1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 from __future__ import with_statement
36
37 import sys
38
39 import roslib.packages
40
41 import rosh
42 from rosh.impl.exceptions import ROSHException
43 import rosh.impl.ros_graph
44
46 """
47 Generate global symbol table for roshlet
48
49 @param plugin_context: context for loading plugins that roshlet depends on
50 @type plugin_context: [str]
51 @param dependencies: names of plugins that roshlet depends on
52 @type dependencies: [str]
53 """
54
55 rosh = sys.modules['rosh']
56
57 globals_ = rosh.__dict__.copy()
58 globals_['rosh'] = rosh
59
60
61
62 rosh.impl.ros_graph.load_rosh_plugin('rosh.impl.ros_graph', plugin_context, globals_)
63
64 for d in dependencies:
65 rosh.plugin.load_plugin(d, plugin_context, globals_)
66 return globals_
67
69 """
70 @param filename: name of file with roshlet code
71 @type filename: str
72 @param plugin_context: context for loading plugins that roshlet depends on
73 @type plugin_context: [str]
74 @param dependencies: names of plugins that roshlet depends on
75 @type dependencies: [str]
76 """
77 with open(filename) as f:
78 str = f.read()
79 return load_roshlet_str(str, plugin_context, dependencies, filename=filename)
80
82 """
83 @param str_: roshlet code
84 @type str_: str
85 @param plugin_context: context for loading plugins that roshlet depends on
86 @type plugin_context: [str]
87 @param dependencies: names of plugins that roshlet depends on
88 @type dependencies: [str]
89 """
90 globals_ = create_globals(plugin_context, dependencies)
91 try:
92 c = compile(str_, filename, 'exec')
93 except SyntaxError, e:
94 raise ROSHException("roshlet [%s] has syntax errors: \n%s"%(filename, e))
95 except TypeError, e:
96 raise ROSHException("roshlet [%s] source contains null bytes: \n%s"%(filename, e))
97
98 return c, globals_
99
101 exec compiled in globals_
102
104 """
105 @raise roslib.packages.InvalidROSPkgException: If package does not exist
106 @raise IOError: If roshlet cannot be located
107 """
108 script_candidates = roslib.packages.find_resource(package, type_)
109 if not script_candidates:
110 raise IOError("cannot find roshlet [%s] in package [%s]"%(type_, package))
111
112 return script_candidates[0]
113
114
116 """
117 Execute roshlet standalone. This method blocks until roshlet exits.
118
119 @param name: roshlet name
120 @type name: str
121 @param package: roshlet package
122 @type package: str
123 @param type_: roshlet type
124 @type type_: str
125 @param plugins: list of roshlet plugins to load for roshlet
126 @type plugins: [str]
127 @raise roslib.packages.InvalidROSPkgException: If package does not exist
128 @raise IOError: If roshlet cannot be located
129 """
130
131 plugins = [p for p in plugins if p]
132
133
134 rosh.rosh_init()
135
136
137 pc = rosh.get_default_plugin_context()
138 args = rosh.impl.roshlets.load_roshlet(script, pc, plugins)
139 rosh.impl.roshlets.exec_roshlet(*args)
140