99from types import ModuleType
1010
1111import argparse
12+ import logging
13+
14+ logger = logging .getLogger (__name__ )
15+
1216argcomplete : Union [None , ModuleType ] = None
1317try :
1418 import argcomplete # type: ignore
@@ -67,7 +71,7 @@ def onReceive(packet, interface) -> None:
6771 args = mt_config .args
6872 try :
6973 d = packet .get ("decoded" )
70- logging .debug (f"in onReceive() d:{ d } " )
74+ logger .debug (f"in onReceive() d:{ d } " )
7175
7276 # Exit once we receive a reply
7377 if (
@@ -101,7 +105,7 @@ def onConnection(interface, topic=pub.AUTO_TOPIC) -> None: # pylint: disable=W0
101105def checkChannel (interface : MeshInterface , channelIndex : int ) -> bool :
102106 """Given an interface and channel index, return True if that channel is non-disabled on the local node"""
103107 ch = interface .localNode .getChannelByChannelIndex (channelIndex )
104- logging .debug (f"ch:{ ch } " )
108+ logger .debug (f"ch:{ ch } " )
105109 return ch and ch .role != channel_pb2 .Channel .Role .DISABLED
106110
107111
@@ -114,7 +118,7 @@ def _printSetting(config_type, uni_name, pref_value, repeated):
114118 else :
115119 pref_value = meshtastic .util .toStr (pref_value )
116120 print (f"{ str (config_type .name )} .{ uni_name } : { str (pref_value )} " )
117- logging .debug (f"{ str (config_type .name )} .{ uni_name } : { str (pref_value )} " )
121+ logger .debug (f"{ str (config_type .name )} .{ uni_name } : { str (pref_value )} " )
118122
119123 name = splitCompoundName (comp_name )
120124 wholeField = name [0 ] == name [1 ] # We want the whole field
@@ -123,8 +127,8 @@ def _printSetting(config_type, uni_name, pref_value, repeated):
123127 # Note: protobufs has the keys in snake_case, so snake internally
124128 snake_name = meshtastic .util .camel_to_snake (name [1 ])
125129 uni_name = camel_name if mt_config .camel_case else snake_name
126- logging .debug (f"snake_name:{ snake_name } camel_name:{ camel_name } " )
127- logging .debug (f"use camel:{ mt_config .camel_case } " )
130+ logger .debug (f"snake_name:{ snake_name } camel_name:{ camel_name } " )
131+ logger .debug (f"use camel:{ mt_config .camel_case } " )
128132
129133 # First validate the input
130134 localConfig = node .localConfig
@@ -198,8 +202,8 @@ def setPref(config, comp_name, raw_val) -> bool:
198202 snake_name = meshtastic .util .camel_to_snake (name [- 1 ])
199203 camel_name = meshtastic .util .snake_to_camel (name [- 1 ])
200204 uni_name = camel_name if mt_config .camel_case else snake_name
201- logging .debug (f"snake_name:{ snake_name } " )
202- logging .debug (f"camel_name:{ camel_name } " )
205+ logger .debug (f"snake_name:{ snake_name } " )
206+ logger .debug (f"camel_name:{ camel_name } " )
203207
204208 objDesc = config .DESCRIPTOR
205209 config_part = config
@@ -223,7 +227,7 @@ def setPref(config, comp_name, raw_val) -> bool:
223227 val = meshtastic .util .fromStr (raw_val )
224228 else :
225229 val = raw_val
226- logging .debug (f"valStr:{ raw_val } val:{ val } " )
230+ logger .debug (f"valStr:{ raw_val } val:{ val } " )
227231
228232 if snake_name == "wifi_psk" and len (str (raw_val )) < 8 :
229233 print ("Warning: network.wifi_psk must be 8 or more characters." )
@@ -603,7 +607,7 @@ def onConnected(interface):
603607 time .sleep (1 )
604608 if interface .gotResponse :
605609 break
606- logging .debug (f"end of gpio_rd" )
610+ logger .debug (f"end of gpio_rd" )
607611
608612 if args .gpio_watch :
609613 bitmask = int (args .gpio_watch , 16 )
@@ -1059,7 +1063,7 @@ def setSimpleConfig(modem_preset):
10591063 # Even if others said we could close, stay open if the user asked for a tunnel
10601064 closeNow = False
10611065 if interface .noProto :
1062- logging .warning (f"Not starting Tunnel - disabled by noProto" )
1066+ logger .warning (f"Not starting Tunnel - disabled by noProto" )
10631067 else :
10641068 if args .tunnel_net :
10651069 tunnel .Tunnel (interface , subnet = args .tunnel_net )
@@ -1250,14 +1254,14 @@ def create_power_meter():
12501254 meter = SimPowerSupply ()
12511255
12521256 if meter and v :
1253- logging .info (f"Setting power supply to { v } volts" )
1257+ logger .info (f"Setting power supply to { v } volts" )
12541258 meter .v = v
12551259 meter .powerOn ()
12561260
12571261 if args .power_wait :
12581262 input ("Powered on, press enter to continue..." )
12591263 else :
1260- logging .info ("Powered-on, waiting for device to boot" )
1264+ logger .info ("Powered-on, waiting for device to boot" )
12611265 time .sleep (5 )
12621266
12631267
@@ -1312,7 +1316,7 @@ def common():
13121316 args .seriallog = "none" # assume no debug output in this case
13131317
13141318 if args .deprecated is not None :
1315- logging .error (
1319+ logger .error (
13161320 "This option has been deprecated, see help below for the correct replacement..."
13171321 )
13181322 parser .print_help (sys .stderr )
@@ -1331,18 +1335,18 @@ def common():
13311335 logfile = sys .stdout
13321336 elif args .seriallog == "none" :
13331337 args .seriallog = None
1334- logging .debug ("Not logging serial output" )
1338+ logger .debug ("Not logging serial output" )
13351339 logfile = None
13361340 else :
1337- logging .info (f"Logging serial output to { args .seriallog } " )
1341+ logger .info (f"Logging serial output to { args .seriallog } " )
13381342 # Note: using "line buffering"
13391343 # pylint: disable=R1732
13401344 logfile = open (args .seriallog , "w+" , buffering = 1 , encoding = "utf8" )
13411345 mt_config .logfile = logfile
13421346
13431347 subscribe ()
13441348 if args .ble_scan :
1345- logging .debug ("BLE scan starting" )
1349+ logger .debug ("BLE scan starting" )
13461350 for x in BLEInterface .scan ():
13471351 print (f"Found: name='{ x .name } ' address='{ x .address } '" )
13481352 meshtastic .util .our_exit ("BLE scan finished" , 0 )
@@ -1433,7 +1437,7 @@ def common():
14331437 while True :
14341438 time .sleep (1000 )
14351439 except KeyboardInterrupt :
1436- logging .info ("Exiting due to keyboard interrupt" )
1440+ logger .info ("Exiting due to keyboard interrupt" )
14371441
14381442 # don't call exit, background threads might be running still
14391443 # sys.exit(0)
0 commit comments