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 from __future__ import print_function
34
35 import os
36 import socket
37 import sys
38
39 import rosgraph
40 import rospy
41
42 from .logger_level_service_caller import LoggerLevelServiceCaller
43 from .logger_level_service_caller import ROSConsoleException
44
45 NAME = 'rosconsole'
46
47
49 print("%s: error: %s" % (NAME, msg), file=sys.stderr)
50 sys.exit(status)
51
52
54 from optparse import OptionParser
55
56 usage = "usage: %prog list <node>"
57 parser = OptionParser(usage=usage, prog=NAME)
58
59 return parser
60
61
63 args = argv[2:]
64 parser = _get_cmd_list_optparse()
65 (options, args) = parser.parse_args(args)
66
67 if not args:
68 parser.error("you must specify a node to list loggers")
69 elif len(args) > 1:
70 parser.error("you may only specify one node to list")
71
72 logger_level = LoggerLevelServiceCaller()
73
74 loggers = logger_level.get_loggers(args[0])
75
76 output = '\n'.join(loggers)
77 print(output)
78
79
81 from optparse import OptionParser
82
83 usage = "usage: %prog set <node> <logger> <level>"
84 levels = ', '.join(LoggerLevelServiceCaller().get_levels())
85 usage += "\n\n <level> must be one of [" + levels + "]"
86 parser = OptionParser(usage=usage, prog=NAME)
87
88 return parser
89
90
92 args = argv[2:]
93 parser = _get_cmd_set_optparse()
94 (options, args) = parser.parse_args(args)
95
96 if len(args) < 3:
97 parser.error("you must specify a node, a logger and a level")
98
99 logger_level = LoggerLevelServiceCaller()
100 logger_level.get_loggers(args[0])
101
102 if args[1] not in logger_level._current_levels:
103 error(2, "node " + args[0] + " does not contain logger " + args[1])
104
105 level = args[2].lower()
106 if level not in logger_level.get_levels():
107 parser.error("invalid level")
108
109 logger_level.send_logger_change_message(args[0], args[1], args[2])
110
111
113 from optparse import OptionParser
114
115 usage = "usage: %prog get <node> <logger>"
116 parser = OptionParser(usage=usage, prog=NAME)
117
118 return parser
119
120
122 args = argv[2:]
123 parser = _get_cmd_get_optparse()
124 (options, args) = parser.parse_args(args)
125
126 if len(args) < 2:
127 parser.error("you must specify a node and a logger")
128
129 logger_level = LoggerLevelServiceCaller()
130 logger_level.get_loggers(args[0])
131
132 if args[1] not in logger_level._current_levels:
133 error(2, "node " + args[0] + " does not contain logger " + args[1])
134
135 print(logger_level._current_levels[args[1]])
136
137
139 print("""rosconsole is a command-line tool for configuring the logger level of ROS nodes.
140
141 Commands:
142 \trosconsole get\tdisplay level for a logger
143 \trosconsole list\tlist loggers for a node
144 \trosconsole set\tset level for a logger
145
146 Type rosconsole <command> -h for more detailed usage, e.g. 'rosconsole list -h'
147 """)
148 sys.exit(getattr(os, 'EX_USAGE', 1))
149
150
151 -def main(argv=None):
152 if argv is None:
153 argv = sys.argv
154
155
156
157 rospy.init_node('rosconsole', anonymous=True)
158 argv = rospy.myargv(argv)
159
160
161 if len(argv) == 1:
162 _fullusage()
163
164 try:
165 command = argv[1]
166 if command == 'get':
167 _rosconsole_cmd_get(argv)
168 elif command == 'list':
169 _rosconsole_cmd_list(argv)
170 elif command == 'set':
171 _rosconsole_cmd_set(argv)
172 else:
173 _fullusage()
174 except socket.error as e:
175 error(1,
176 "Network communication failed; most likely failed to communicate with master: %s" % e)
177 except rosgraph.MasterException as e:
178
179 error(1, str(e))
180 except ROSConsoleException as e:
181 error(1, str(e))
182 except KeyboardInterrupt:
183 pass
184 except rospy.ROSInterruptException:
185 pass
186