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 """
36 ROSH library for running processes.
37
38 This library is necessary as ROSH commands, like set_master, can
39 manipulate the environment in ways that would affect subprocesses.
40 """
41
42 import os
43 from subprocess import Popen, PIPE
44
45 import roslib.rosenv
46
47
48
49
50 -def run(config, cmd, stdout=True):
51 """
52 Run the specified command using the current ROS configuration.
53 """
54 env = os.environ.copy()
55 env[roslib.rosenv.ROS_MASTER_URI] = config.master.master_uri
56
57 if 0:
58 print "CMD", cmd
59
60
61 if stdout:
62 p = Popen(cmd, stderr=PIPE, env=env)
63 else:
64 p = Popen(cmd, stdout=PIPE, stderr=PIPE, env=env)
65
66 p.poll()
67 return p.returncode in [None, 0]
68
70 """
71 Add shared roslaunch instance to ctx if not already initialized.
72
73 @param ctx: ROSH context
74 @type ctx: Contextj
75 """
76 if not ctx._roslaunch.started:
77 ctx._roslaunch.start()
78
79
81 """
82 ROSH wrapper for processes to make them kill-able
83 """
84
86 self.roslaunch_process = roslaunch_process
87
89 self.roslaunch_process.stop()
90
91 -def launch_node(ctx, pkg, type_, args=[], remap={}, stdout=False):
92 """
93 Low-level launch() API for internal ROSH and ROSH plugin use.
94
95 @param ctx: ROSH context
96 @type ctx: Context
97 @param pkg: package name
98 @param type_: node type
99 @return: Node and Process instance
100 @rtype: (roslaunch.Node, roslaunch.Process)
101 """
102 output = 'screen' if stdout else None
103 if type(args) in (list, tuple):
104 args = ' '.join([str(x) for x in args])
105 if remap:
106 args = args + ' '.join(['%s:=%s'%(k, v) for k, v in remap.iteritems()])
107
108 return launch_roslaunch_Node(ctx, roslaunch.Node(pkg, type_, args=args, output=output, filename='<rosh>'))
109
111
112 raise NotImplemented
113
115 """
116 Launch a Node instance. This is a low-level launch() API for
117 internal ROSH and ROSH plugin use.
118
119 @param ctx: ROSH context
120 @type ctx: Context
121 @param node: node instance. The name attribute may be overwritten.
122 @type node: roslaunch.Node
123 @return: Node instance
124 @rtype: Node
125 """
126 _init_ctx(ctx)
127 p = ctx._roslaunch.launch(node)
128 return node, Process(p)
129