File tree 4 files changed +21
-6
lines changed
diagnostic_common_diagnostics/diagnostic_common_diagnostics
4 files changed +21
-6
lines changed Original file line number Diff line number Diff line change @@ -92,7 +92,11 @@ def main(args=None):
92
92
93
93
# Create the node
94
94
hostname = socket .gethostname ()
95
- node = Node (f'cpu_monitor_{ hostname .replace ("-" , "_" )} ' )
95
+ # Every invalid symbol is replaced by underscore.
96
+ # isalnum() alone also allows invalid symbols depending on the locale
97
+ cleaned_hostname = '' .join (
98
+ c if (c .isascii () and c .isalnum ()) else '_' for c in hostname )
99
+ node = Node (f'cpu_monitor_{ cleaned_hostname } ' )
96
100
97
101
# Declare and get parameters
98
102
node .declare_parameter ('warning_percentage' , 90 )
Original file line number Diff line number Diff line change @@ -74,8 +74,12 @@ class HDMonitor(Node):
74
74
"""
75
75
76
76
def __init__ (self ):
77
- hostname = gethostname ().replace ('.' , '_' ).replace ('-' , '_' )
78
- super ().__init__ (f'hd_monitor_{ hostname } ' )
77
+ hostname = gethostname ()
78
+ # Every invalid symbol is replaced by underscore.
79
+ # isalnum() alone also allows invalid symbols depending on the locale
80
+ cleaned_hostname = '' .join (
81
+ c if (c .isascii () and c .isalnum ()) else '_' for c in hostname )
82
+ super ().__init__ (f'hd_monitor_{ cleaned_hostname } ' )
79
83
80
84
self ._path = '~'
81
85
self ._free_percent_low = 0.05
Original file line number Diff line number Diff line change @@ -72,8 +72,12 @@ def run(self, stat):
72
72
73
73
def main ():
74
74
hostname = socket .gethostname ()
75
+ # Every invalid symbol is replaced by underscore.
76
+ # isalnum() alone also allows invalid symbols depending on the locale
77
+ cleaned_hostname = '' .join (
78
+ c if (c .isascii () and c .isalnum ()) else '_' for c in hostname )
75
79
rclpy .init ()
76
- node = rclpy .create_node (f'ram_monitor_{ hostname . replace ( "-" , "_" ) } ' )
80
+ node = rclpy .create_node (f'ram_monitor_{ cleaned_hostname } ' )
77
81
78
82
updater = Updater (node )
79
83
updater .setHardwareID (hostname )
Original file line number Diff line number Diff line change @@ -245,8 +245,11 @@ def monitor(self, stat):
245
245
if __name__ == '__main__' :
246
246
rclpy .init ()
247
247
hostname = socket .gethostname ()
248
- hostname_clean = hostname .translate (hostname .maketrans ('-' , '_' ))
249
- node = rclpy .create_node ('sensors_monitor_%s' % hostname_clean )
248
+ # Every invalid symbol is replaced by underscore.
249
+ # isalnum() alone also allows invalid symbols depending on the locale
250
+ cleaned_hostname = '' .join (
251
+ c if (c .isascii () and c .isalnum ()) else '_' for c in hostname )
252
+ node = rclpy .create_node ('sensors_monitor_%s' % cleaned_hostname )
250
253
251
254
monitor = SensorsMonitor (node , hostname )
252
255
try :
You can’t perform that action at this time.
0 commit comments