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 contents = f.read()
79 if contents.startswith("#|\nexec"):
80 contents = contents[contents.find('|#')+2:]
81 return load_roshlet_str(contents, plugin_context, dependencies, filename=filename)
82
84 """
85 @param str_: roshlet code
86 @type str_: str
87 @param plugin_context: context for loading plugins that roshlet depends on
88 @type plugin_context: [str]
89 @param dependencies: names of plugins that roshlet depends on
90 @type dependencies: [str]
91 """
92 globals_ = create_globals(plugin_context, dependencies)
93 try:
94 c = compile(str_, filename, 'exec')
95 except SyntaxError, e:
96 raise ROSHException("roshlet [%s] has syntax errors: \n%s"%(filename, e))
97 except TypeError, e:
98 raise ROSHException("roshlet [%s] source contains null bytes: \n%s"%(filename, e))
99
100 return c, globals_
101
103 exec compiled in globals_
104
106 """
107 @raise roslib.packages.InvalidROSPkgException: If package does not exist
108 @raise IOError: If roshlet cannot be located
109 """
110 script_candidates = roslib.packages.find_resource(package, type_)
111 if not script_candidates:
112 raise IOError("cannot find roshlet [%s] in package [%s]"%(type_, package))
113
114 return script_candidates[0]
115
116
118 """
119 Execute roshlet standalone. This method blocks until roshlet exits.
120
121 @param name: roshlet name
122 @type name: str
123 @param package: roshlet package
124 @type package: str
125 @param type_: roshlet type
126 @type type_: str
127 @param plugins: list of roshlet plugins to load for roshlet
128 @type plugins: [str]
129 @raise roslib.packages.InvalidROSPkgException: If package does not exist
130 @raise IOError: If roshlet cannot be located
131 """
132
133 plugins = [p for p in plugins if p]
134
135
136 rosh.rosh_init()
137
138
139 pc = rosh.get_default_plugin_context()
140 args = rosh.impl.roshlets.load_roshlet(script, pc, plugins)
141 rosh.impl.roshlets.exec_roshlet(*args)
142