meshcore-cli 1.6.4__tar.gz → 1.6.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {meshcore_cli-1.6.4 → meshcore_cli-1.6.5}/PKG-INFO +2 -2
- {meshcore_cli-1.6.4 → meshcore_cli-1.6.5}/flake.nix +2 -2
- {meshcore_cli-1.6.4 → meshcore_cli-1.6.5}/pyproject.toml +2 -2
- {meshcore_cli-1.6.4 → meshcore_cli-1.6.5}/src/meshcore_cli/meshcore_cli.py +314 -166
- {meshcore_cli-1.6.4 → meshcore_cli-1.6.5}/.github/funding.yml +0 -0
- {meshcore_cli-1.6.4 → meshcore_cli-1.6.5}/.gitignore +0 -0
- {meshcore_cli-1.6.4 → meshcore_cli-1.6.5}/LICENSE +0 -0
- {meshcore_cli-1.6.4 → meshcore_cli-1.6.5}/README.md +0 -0
- {meshcore_cli-1.6.4 → meshcore_cli-1.6.5}/flake.lock +0 -0
- {meshcore_cli-1.6.4 → meshcore_cli-1.6.5}/scripts/README.md +0 -0
- {meshcore_cli-1.6.4 → meshcore_cli-1.6.5}/scripts/ask_mepo_coords +0 -0
- {meshcore_cli-1.6.4 → meshcore_cli-1.6.5}/scripts/contact_markers.sh +0 -0
- {meshcore_cli-1.6.4 → meshcore_cli-1.6.5}/scripts/getpos.py +0 -0
- {meshcore_cli-1.6.4 → meshcore_cli-1.6.5}/scripts/neighbour_map.sh +0 -0
- {meshcore_cli-1.6.4 → meshcore_cli-1.6.5}/src/meshcore_cli/__init__.py +0 -0
- {meshcore_cli-1.6.4 → meshcore_cli-1.6.5}/src/meshcore_cli/__main__.py +0 -0
- {meshcore_cli-1.6.4 → meshcore_cli-1.6.5}/sxmo/sxmo_accel.sh +0 -0
- {meshcore_cli-1.6.4 → meshcore_cli-1.6.5}/sxmo/sxmo_mc.sh +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: meshcore-cli
|
|
3
|
-
Version: 1.6.
|
|
3
|
+
Version: 1.6.5
|
|
4
4
|
Summary: Command line interface to meshcore companion radios and repeaters
|
|
5
5
|
Project-URL: Homepage, https://github.com/fdlamotte/meshcore-cli
|
|
6
6
|
Project-URL: Issues, https://github.com/fdlamotte/meshcore-cli/issues
|
|
@@ -11,7 +11,7 @@ Classifier: Operating System :: OS Independent
|
|
|
11
11
|
Classifier: Programming Language :: Python :: 3
|
|
12
12
|
Requires-Python: >=3.10
|
|
13
13
|
Requires-Dist: bleak>=0.22
|
|
14
|
-
Requires-Dist: meshcore>=2.3.
|
|
14
|
+
Requires-Dist: meshcore>=2.3.15
|
|
15
15
|
Requires-Dist: prompt-toolkit>=3.0.50
|
|
16
16
|
Requires-Dist: requests>=2.28.0
|
|
17
17
|
Description-Content-Type: text/markdown
|
|
@@ -17,12 +17,12 @@
|
|
|
17
17
|
|
|
18
18
|
meshcore = python3Packages.buildPythonPackage rec {
|
|
19
19
|
pname = "meshcore";
|
|
20
|
-
version = "2.3.
|
|
20
|
+
version = "2.3.15";
|
|
21
21
|
pyproject = true;
|
|
22
22
|
|
|
23
23
|
src = python3Packages.fetchPypi {
|
|
24
24
|
inherit pname version;
|
|
25
|
-
sha256 = "sha256-
|
|
25
|
+
sha256 = "sha256-YIR8IdclmhOmi4kAgpYiO0N8Odauwten370gjYQ50FA=";
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
build-system = [ python3Packages.hatchling ];
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "meshcore-cli"
|
|
7
|
-
version = "1.6.
|
|
7
|
+
version = "1.6.5"
|
|
8
8
|
authors = [
|
|
9
9
|
{ name="Florent de Lamotte", email="florent@frizoncorrea.fr" },
|
|
10
10
|
]
|
|
@@ -17,7 +17,7 @@ classifiers = [
|
|
|
17
17
|
]
|
|
18
18
|
license = "MIT"
|
|
19
19
|
license-files = ["LICEN[CS]E*"]
|
|
20
|
-
dependencies = [ "meshcore >= 2.3.
|
|
20
|
+
dependencies = [ "meshcore >= 2.3.15",
|
|
21
21
|
"bleak >= 0.22",
|
|
22
22
|
"prompt_toolkit >= 3.0.50",
|
|
23
23
|
"requests >= 2.28.0" ]
|
|
@@ -35,7 +35,7 @@ except ImportError:
|
|
|
35
35
|
from meshcore import MeshCore, EventType, logger
|
|
36
36
|
|
|
37
37
|
# Version
|
|
38
|
-
VERSION = "v1.6.
|
|
38
|
+
VERSION = "v1.6.5"
|
|
39
39
|
|
|
40
40
|
# default ble address is stored in a config file
|
|
41
41
|
MCCLI_CONFIG_DIR = os.path.expanduser("~/.config/meshcore/")
|
|
@@ -69,6 +69,7 @@ JSON = False
|
|
|
69
69
|
|
|
70
70
|
PS = None
|
|
71
71
|
CS = None
|
|
72
|
+
DS = None
|
|
72
73
|
|
|
73
74
|
# Ansi colors
|
|
74
75
|
ANSI_END = "\033[0m"
|
|
@@ -116,6 +117,7 @@ ALIASES={}
|
|
|
116
117
|
HANDLERS = { # dicts that will be indexed by numbers
|
|
117
118
|
"rxlog" : {},
|
|
118
119
|
"msgs" : {},
|
|
120
|
+
"chan_data" : {},
|
|
119
121
|
}
|
|
120
122
|
LAST_HANDLER_ID = 0
|
|
121
123
|
HANDLER_QUEUE_SIZE = 100
|
|
@@ -153,7 +155,17 @@ LC_OUTPUT_FORMAT = "tkah"
|
|
|
153
155
|
LC_SORT_ORDER = ""
|
|
154
156
|
|
|
155
157
|
def time_ago_from_timestamp (timestamp):
|
|
158
|
+
if timestamp == 0:
|
|
159
|
+
return "0"
|
|
160
|
+
|
|
156
161
|
duration = int(time.time()) - timestamp
|
|
162
|
+
in_future=False
|
|
163
|
+
if duration < 0 :
|
|
164
|
+
in_future = True
|
|
165
|
+
duration = -duration
|
|
166
|
+
if duration > 86400: # > 1 day drift
|
|
167
|
+
return ""
|
|
168
|
+
|
|
157
169
|
if duration / 86400 >= 1 : # result in days
|
|
158
170
|
days_ago = int(duration/86400)
|
|
159
171
|
if days_ago >= 365:
|
|
@@ -166,6 +178,10 @@ def time_ago_from_timestamp (timestamp):
|
|
|
166
178
|
time_ago = f"{int(duration/60)}m"
|
|
167
179
|
else :
|
|
168
180
|
time_ago = f"{int(duration)}s"
|
|
181
|
+
|
|
182
|
+
if in_future :
|
|
183
|
+
time_ago = "+" + time_ago
|
|
184
|
+
|
|
169
185
|
return time_ago
|
|
170
186
|
|
|
171
187
|
def haversine_distance(coord1, coord2):
|
|
@@ -313,7 +329,9 @@ async def process_event_message(mc, ev, json_output, end="\n"):
|
|
|
313
329
|
|
|
314
330
|
path_str = ""
|
|
315
331
|
|
|
316
|
-
if
|
|
332
|
+
if "sender_timestamp" in data\
|
|
333
|
+
and process_event_message.timestamp != ""\
|
|
334
|
+
and process_event_message.timestamp != "off":
|
|
317
335
|
ts = data["sender_timestamp"]
|
|
318
336
|
if process_event_message.timestamp == "on":
|
|
319
337
|
if (abs(time.time()-ts) < 86400):
|
|
@@ -331,7 +349,7 @@ async def process_event_message(mc, ev, json_output, end="\n"):
|
|
|
331
349
|
if "SNR" in data and process_event_message.print_snr:
|
|
332
350
|
path_str = path_str + f",{data['SNR']}dB"
|
|
333
351
|
|
|
334
|
-
if (data['type'] == "PRIV") :
|
|
352
|
+
if ('type' in data and data['type'] == "PRIV") :
|
|
335
353
|
ct = mc.get_contact_by_key_prefix(data['pubkey_prefix'])
|
|
336
354
|
if ct is None:
|
|
337
355
|
logger.debug(f"Unknown contact with pubkey prefix: {data['pubkey_prefix']}")
|
|
@@ -369,7 +387,7 @@ async def process_event_message(mc, ev, json_output, end="\n"):
|
|
|
369
387
|
|
|
370
388
|
output_str += disp + end
|
|
371
389
|
|
|
372
|
-
elif (data['type'] == "CHAN") :
|
|
390
|
+
elif ('type' in data and data['type'] == "CHAN") :
|
|
373
391
|
path_str = f"{ANSI_YELLOW}({path_str}){ANSI_END}"
|
|
374
392
|
if hasattr(mc, "channels"):
|
|
375
393
|
ch_name = mc.channels[data['channel_idx']]['channel_name']
|
|
@@ -388,12 +406,32 @@ async def process_event_message(mc, ev, json_output, end="\n"):
|
|
|
388
406
|
disp = escape_ansi(disp)
|
|
389
407
|
|
|
390
408
|
output_str += disp + end
|
|
409
|
+
|
|
410
|
+
elif ('type' in data and data['type'] == "DATA") :
|
|
411
|
+
if process_event_message.display_channel_data:
|
|
412
|
+
path_str = f"{ANSI_YELLOW}({path_str}){ANSI_END}"
|
|
413
|
+
if hasattr(mc, "channels"):
|
|
414
|
+
ch_name = mc.channels[data['channel_idx']]['channel_name']
|
|
415
|
+
disp = f"{ANSI_GREEN}{ch_name} {path_str}"
|
|
416
|
+
process_event_message.last_node = {"adv_name" : ch_name, "type" : 0, "chan_nb" : data['channel_idx']}
|
|
417
|
+
elif data["channel_idx"] == 0: #public
|
|
418
|
+
disp = f"{ANSI_GREEN}public {path_str}"
|
|
419
|
+
process_event_message.last_node = {"adv_name" : "public", "type" : 0, "chan_nb" : 0}
|
|
420
|
+
else :
|
|
421
|
+
disp = f"{ANSI_GREEN}ch{data['channel_idx']} {path_str}"
|
|
422
|
+
process_event_message.last_node = {"adv_name" : f"ch{data['channel_idx']}", "type" : 0, "chan_nb" : data['channel_idx']}
|
|
423
|
+
disp = disp + f"{ANSI_END} "
|
|
424
|
+
disp += json.dumps(ev.payload)
|
|
425
|
+
|
|
426
|
+
output_str += disp + end
|
|
427
|
+
|
|
391
428
|
else:
|
|
392
429
|
output_str += json.dumps(ev.payload) + end
|
|
393
430
|
return output_str
|
|
394
431
|
process_event_message.print_snr=False
|
|
395
432
|
process_event_message.color=True
|
|
396
433
|
process_event_message.last_node=None
|
|
434
|
+
process_event_message.display_channel_data=True
|
|
397
435
|
process_event_message.timestamp=""
|
|
398
436
|
|
|
399
437
|
async def handle_log_rx(event):
|
|
@@ -543,24 +581,25 @@ async def log_message(mc, msg):
|
|
|
543
581
|
if log_message.file is None:
|
|
544
582
|
return
|
|
545
583
|
|
|
546
|
-
if msg["type"]
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
584
|
+
if "type" in msg and msg["type"] != "DATA":
|
|
585
|
+
if msg["type"] == "PRIV" :
|
|
586
|
+
ct = mc.get_contact_by_key_prefix(msg['pubkey_prefix'])
|
|
587
|
+
if ct is None:
|
|
588
|
+
msg["name"] = msg["pubkey_prefix"]
|
|
589
|
+
msg["sender"] = msg["pubkey_prefix"]
|
|
590
|
+
else:
|
|
591
|
+
msg["name"] = ct["adv_name"]
|
|
592
|
+
msg["sender"] = ct["adv_name"]
|
|
593
|
+
elif msg["type"] == "CHAN" :
|
|
594
|
+
if hasattr(mc, 'channels') :
|
|
595
|
+
msg["sender"] = mc.channels[msg['channel_idx']]["channel_name"]
|
|
596
|
+
else:
|
|
597
|
+
msg["sender"] = f"channel {msg['channel_idx']}"
|
|
598
|
+
msg["name"] = msg["sender"]
|
|
599
|
+
msg["timestamp"] = int(time.time())
|
|
600
|
+
|
|
601
|
+
with open(log_message.file, "a") as logfile:
|
|
602
|
+
logfile.write(json.dumps(msg) + "\n")
|
|
564
603
|
|
|
565
604
|
log_message.file=None
|
|
566
605
|
|
|
@@ -571,7 +610,11 @@ async def handle_message(event):
|
|
|
571
610
|
json_output=handle_message.json_output), end="")
|
|
572
611
|
await log_message(handle_message.mc, event.payload.copy())
|
|
573
612
|
|
|
574
|
-
|
|
613
|
+
pld = event.payload
|
|
614
|
+
if "type" in pld and pld["type"] == "DATA":
|
|
615
|
+
enqueue_handler_event("chan_data", event.payload)
|
|
616
|
+
else:
|
|
617
|
+
enqueue_handler_event("msgs", event.payload)
|
|
575
618
|
|
|
576
619
|
handle_message.json_output=False
|
|
577
620
|
handle_message.mc=None
|
|
@@ -579,7 +622,7 @@ handle_message.display=True
|
|
|
579
622
|
|
|
580
623
|
async def subscribe_to_msgs(mc, json_output=False):
|
|
581
624
|
""" Subscribe to incoming messages """
|
|
582
|
-
global PS, CS
|
|
625
|
+
global PS, CS, DS
|
|
583
626
|
await mc.ensure_contacts()
|
|
584
627
|
handle_message.json_output = json_output
|
|
585
628
|
# Subscribe to private messages
|
|
@@ -588,6 +631,9 @@ async def subscribe_to_msgs(mc, json_output=False):
|
|
|
588
631
|
# Subscribe to channel messages
|
|
589
632
|
if CS is None :
|
|
590
633
|
CS = mc.subscribe(EventType.CHANNEL_MSG_RECV, handle_message)
|
|
634
|
+
# Subscribe to channel data
|
|
635
|
+
if DS is None :
|
|
636
|
+
DS = mc.subscribe(EventType.CHANNEL_DATA_RECV, handle_message)
|
|
591
637
|
await mc.start_auto_message_fetching()
|
|
592
638
|
|
|
593
639
|
# redefine get_completion to let user put symbols in first item
|
|
@@ -650,11 +696,12 @@ def make_completion_dict(contacts, pending=None, to=None, channels=None):
|
|
|
650
696
|
completion_list = {
|
|
651
697
|
"to" : to_list,
|
|
652
698
|
"/to" : to_list,
|
|
653
|
-
"public" : None,
|
|
654
|
-
"chan" : None,
|
|
655
699
|
}
|
|
656
700
|
|
|
657
701
|
root_completion_list = {
|
|
702
|
+
"public" : None,
|
|
703
|
+
"chan" : None,
|
|
704
|
+
"chan_data" : None,
|
|
658
705
|
"ver" : None,
|
|
659
706
|
"infos" : None,
|
|
660
707
|
"advert" : None,
|
|
@@ -685,12 +732,13 @@ def make_completion_dict(contacts, pending=None, to=None, channels=None):
|
|
|
685
732
|
"change_flags" : contact_list,
|
|
686
733
|
"remove_contact" : contact_list,
|
|
687
734
|
"add_contact" : {"key type name":None},
|
|
735
|
+
"reset_advert_time" : contact_list,
|
|
688
736
|
"import_contact" : {"meshcore://":None},
|
|
689
737
|
"reload_contacts" : None,
|
|
690
738
|
"aliases" : None,
|
|
691
739
|
"aliases_load" : None,
|
|
692
740
|
"alias" : None,
|
|
693
|
-
"handler_attach": {"rxlog":None, "msgs":None},
|
|
741
|
+
"handler_attach": {"rxlog":None, "msgs":None, "chan_data":None},
|
|
694
742
|
"handler_detach": None,
|
|
695
743
|
"handlers": None,
|
|
696
744
|
"login" : contact_list,
|
|
@@ -731,6 +779,7 @@ def make_completion_dict(contacts, pending=None, to=None, channels=None):
|
|
|
731
779
|
"lc_output_format":None,
|
|
732
780
|
"lc_sort_order":None,
|
|
733
781
|
"print_adverts" : {"on":None, "off":None},
|
|
782
|
+
"display_channel_data" : {"on":None, "off":None},
|
|
734
783
|
"json_log_rx" : {"on":None, "off":None},
|
|
735
784
|
"channel_echoes" : {"on":None, "off":None},
|
|
736
785
|
"advert_echoes" : {"on":None, "off":None},
|
|
@@ -766,6 +815,7 @@ def make_completion_dict(contacts, pending=None, to=None, channels=None):
|
|
|
766
815
|
"print_timestamp":None,
|
|
767
816
|
"json_msgs":None,
|
|
768
817
|
"color":None,
|
|
818
|
+
"display_channel_data":None,
|
|
769
819
|
"lc_output_format":None,
|
|
770
820
|
"lc_sort_order":None,
|
|
771
821
|
"print_adverts":None,
|
|
@@ -840,6 +890,7 @@ def make_completion_dict(contacts, pending=None, to=None, channels=None):
|
|
|
840
890
|
"reset_path" : None,
|
|
841
891
|
"change_path" : None,
|
|
842
892
|
"change_flags" : None,
|
|
893
|
+
"reset_advert_time" : None,
|
|
843
894
|
"req_telemetry" : None,
|
|
844
895
|
"req_binary" : None,
|
|
845
896
|
"forget_password" : None,
|
|
@@ -1229,84 +1280,84 @@ else:
|
|
|
1229
1280
|
|
|
1230
1281
|
|
|
1231
1282
|
async def process_redirected_line(mc, line, contact=None, scope="*", prev_contact=None, prev_scope="*", json_output=False, sink=sys.stdout, end="\n"):
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
if line.startswith(">>") : # append to-file redirection
|
|
1237
|
-
line = line[2:].strip()
|
|
1238
|
-
try:
|
|
1239
|
-
fp, mcline = split_first_token(line)
|
|
1240
|
-
fp = os.path.expanduser(fp)
|
|
1241
|
-
with open(fp, "a") as file:
|
|
1242
|
-
(new_contact, new_scope, last_ack) = await process_redirected_line(mc, mcline, contact, scope, prev_contact, prev_scope, json_output=json_output, sink=file)
|
|
1243
|
-
except ValueError:
|
|
1244
|
-
logger.error("Couldn't parse filename")
|
|
1245
|
-
except OSError as e:
|
|
1246
|
-
logger.error(f"Cannot append to file: {e}")
|
|
1283
|
+
new_contact = contact
|
|
1284
|
+
new_scope = scope
|
|
1285
|
+
last_ack = True
|
|
1247
1286
|
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1287
|
+
if line.startswith(">>") : # append to-file redirection
|
|
1288
|
+
line = line[2:].strip()
|
|
1289
|
+
try:
|
|
1290
|
+
fp, mcline = split_first_token(line)
|
|
1291
|
+
fp = os.path.expanduser(fp)
|
|
1292
|
+
with open(fp, "a") as file:
|
|
1293
|
+
(new_contact, new_scope, last_ack) = await process_redirected_line(mc, mcline, contact, scope, prev_contact, prev_scope, json_output=json_output, sink=file)
|
|
1294
|
+
except ValueError:
|
|
1295
|
+
logger.error("Couldn't parse filename")
|
|
1296
|
+
except OSError as e:
|
|
1297
|
+
logger.error(f"Cannot append to file: {e}")
|
|
1259
1298
|
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
logger.error(f"Permission denied: {pcom}")
|
|
1272
|
-
except OSError as e:
|
|
1273
|
-
logger.error(f"Cannot pipe: {e}")
|
|
1274
|
-
except BrokenPipeError:
|
|
1275
|
-
logger.error(f"Broken pipe")
|
|
1299
|
+
elif line.startswith(">") : # to-file redirection
|
|
1300
|
+
line = line[1:].strip()
|
|
1301
|
+
try:
|
|
1302
|
+
fp, mcline = split_first_token(line)
|
|
1303
|
+
fp = os.path.expanduser(fp)
|
|
1304
|
+
with open(fp, "w") as file:
|
|
1305
|
+
(new_contact, new_scope, last_ack) = await process_redirected_line(mc, mcline, contact, scope, prev_contact, prev_scope, json_output=json_output, sink=file)
|
|
1306
|
+
except ValueError:
|
|
1307
|
+
logger.error("Couldn't parse filename")
|
|
1308
|
+
except OSError as e:
|
|
1309
|
+
logger.error(f"Cannot write to file: {e}")
|
|
1276
1310
|
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1311
|
+
elif line.startswith("|") : # to process redirection
|
|
1312
|
+
line = line[1:].strip()
|
|
1313
|
+
try:
|
|
1314
|
+
pcom, mcline = split_first_token(line)
|
|
1315
|
+
with subprocess.Popen(shlex.split(pcom, posix=True), stdin=subprocess.PIPE, stdout=sink,text=True) as process:
|
|
1316
|
+
(new_contact, new_scope, last_ack) = await process_redirected_line(mc, mcline, contact, scope, prev_contact, prev_scope, json_output=json_output, sink=process.stdin)
|
|
1317
|
+
except ValueError:
|
|
1318
|
+
logger.error("Couldn't parse name")
|
|
1319
|
+
except FileNotFoundError:
|
|
1320
|
+
logger.error(f"File not found {pcom}")
|
|
1321
|
+
except PermissionError:
|
|
1322
|
+
logger.error(f"Permission denied: {pcom}")
|
|
1323
|
+
except OSError as e:
|
|
1324
|
+
logger.error(f"Cannot pipe: {e}")
|
|
1325
|
+
except BrokenPipeError:
|
|
1326
|
+
logger.error(f"Broken pipe")
|
|
1327
|
+
|
|
1328
|
+
elif line.startswith("<") : # from process redirection
|
|
1329
|
+
try:
|
|
1330
|
+
if line[1] == "|":
|
|
1331
|
+
key = ""
|
|
1332
|
+
line = line[2:].strip()
|
|
1333
|
+
else:
|
|
1334
|
+
key = line[1:].split("|", 1)[0].strip()
|
|
1335
|
+
line = line[1:].split("|", 1)[1].strip()
|
|
1336
|
+
|
|
1337
|
+
pcom, mcline = split_first_token(line)
|
|
1338
|
+
res = subprocess.run(shlex.split(pcom, posix=True), capture_output=True, text=True)
|
|
1339
|
+
replacement = res.stdout.strip()
|
|
1340
|
+
if key == "":
|
|
1341
|
+
mcline = formatter.format(mcline,replacement)
|
|
1342
|
+
else:
|
|
1343
|
+
keywords = {key: replacement}
|
|
1344
|
+
mcline = formatter.format(mcline, **keywords)
|
|
1345
|
+
(new_contact, new_scope, last_ack) = await process_redirected_line(mc, mcline, contact, scope, prev_contact, prev_scope, json_output=json_output, sink=sink)
|
|
1346
|
+
except IndexError as e:
|
|
1347
|
+
logger.error(f"Error with substitution: {e}")
|
|
1348
|
+
except ValueError:
|
|
1349
|
+
logger.error("Couldn't parse name")
|
|
1350
|
+
except FileNotFoundError:
|
|
1351
|
+
logger.error(f"File not found {pcom}")
|
|
1352
|
+
except PermissionError:
|
|
1353
|
+
logger.error(f"Permission denied: {pcom}")
|
|
1354
|
+
except OSError as e:
|
|
1355
|
+
logger.error(f"Cannot pipe: {e}")
|
|
1356
|
+
except BrokenPipeError:
|
|
1357
|
+
logger.error(f"Broken pipe")
|
|
1358
|
+
else :
|
|
1359
|
+
(new_contact, new_scope, last_ack) = await process_pipeline(mc, line, contact, scope, prev_contact, prev_scope, json_output=json_output, sink=sink)
|
|
1360
|
+
return new_contact, new_scope, last_ack
|
|
1310
1361
|
|
|
1311
1362
|
async def process_pipeline(mc, pipeline, contact=None, scope="*", prev_contact=None, prev_scope="*", json_output=False, sink=sys.stdout, end="\n"):
|
|
1312
1363
|
|
|
@@ -1691,6 +1742,7 @@ async def process_contact_chat_line(mc, contact, line, inside=False, json_output
|
|
|
1691
1742
|
line.startswith("req_acl") or line == "ra" or line.startswith("ra ") or\
|
|
1692
1743
|
line.startswith("path ") or line == "path" or\
|
|
1693
1744
|
line.startswith("advert_path") or line == "ap" or line.startswith("ap ") or\
|
|
1745
|
+
line.startswith("reset_advert_time") or\
|
|
1694
1746
|
line.startswith("logout") :
|
|
1695
1747
|
args = [line.split()[0], contact['adv_name']]
|
|
1696
1748
|
out_str = ""
|
|
@@ -1851,6 +1903,8 @@ async def process_contact_chat_line(mc, contact, line, inside=False, json_output
|
|
|
1851
1903
|
async def apply_command_to_contacts(mc, contact_filter, line, json_output=False, sink=sys.stdout, end="\n"):
|
|
1852
1904
|
upd_before = None
|
|
1853
1905
|
upd_after = None
|
|
1906
|
+
adv_before = None
|
|
1907
|
+
adv_after = None
|
|
1854
1908
|
contact_type = None
|
|
1855
1909
|
min_hops = None
|
|
1856
1910
|
max_hops = None
|
|
@@ -1881,6 +1935,24 @@ async def apply_command_to_contacts(mc, contact_filter, line, json_output=False,
|
|
|
1881
1935
|
else:
|
|
1882
1936
|
logger.error(f"Time filter can only be < or >")
|
|
1883
1937
|
return ""
|
|
1938
|
+
elif f[0] == "a": # last advert
|
|
1939
|
+
val_str = f[2:]
|
|
1940
|
+
t = time.time()
|
|
1941
|
+
if val_str[-1] == "d": # value in days
|
|
1942
|
+
t = t - float(val_str[0:-1]) * 86400
|
|
1943
|
+
elif val_str[-1] == "h": # value in hours
|
|
1944
|
+
t = t - float(val_str[0:-1]) * 3600
|
|
1945
|
+
elif val_str[-1] == "m": # value in minutes
|
|
1946
|
+
t = t - float(val_str[0:-1]) * 60
|
|
1947
|
+
else:
|
|
1948
|
+
t = int(val_str)
|
|
1949
|
+
if f[1] == "<": #before
|
|
1950
|
+
adv_before = t
|
|
1951
|
+
elif f[1] == ">":
|
|
1952
|
+
adv_after = t
|
|
1953
|
+
else:
|
|
1954
|
+
logger.error(f"Time filter can only be < or >")
|
|
1955
|
+
return ""
|
|
1884
1956
|
elif f[0] == "t": # type
|
|
1885
1957
|
if f[1] == "=":
|
|
1886
1958
|
contact_type = int(f[2:])
|
|
@@ -1915,6 +1987,8 @@ async def apply_command_to_contacts(mc, contact_filter, line, json_output=False,
|
|
|
1915
1987
|
if (contact_type is None or contact["type"] == contact_type) and\
|
|
1916
1988
|
(upd_before is None or contact["lastmod"] < upd_before) and\
|
|
1917
1989
|
(upd_after is None or contact["lastmod"] > upd_after) and\
|
|
1990
|
+
(adv_before is None or contact["last_advert"] < adv_before) and\
|
|
1991
|
+
(adv_after is None or contact["last_advert"] > adv_after) and\
|
|
1918
1992
|
(min_hops is None or contact["out_path_len"] >= min_hops) and\
|
|
1919
1993
|
(max_hops is None or contact["out_path_len"] <= max_hops) and\
|
|
1920
1994
|
(flags is None or contact["flags"] & flags == flags):
|
|
@@ -2434,6 +2508,8 @@ async def next_cmd(mc, cmds, json_output=False, sink=sys.stdout, end="\n"):
|
|
|
2434
2508
|
SLASH_END = cmds[2]
|
|
2435
2509
|
case "invert_slash":
|
|
2436
2510
|
INVERT_SLASH = cmds[2] == "on"
|
|
2511
|
+
case "display_channel_data":
|
|
2512
|
+
process_event_message.display_channel_data = (cmds[2] == "on")
|
|
2437
2513
|
case "color" :
|
|
2438
2514
|
process_event_message.color = (cmds[2] == "on")
|
|
2439
2515
|
if json_output :
|
|
@@ -2732,6 +2808,11 @@ async def next_cmd(mc, cmds, json_output=False, sink=sys.stdout, end="\n"):
|
|
|
2732
2808
|
output_str += json.dumps({"json_msgs" : handle_message.json_output})+end
|
|
2733
2809
|
else:
|
|
2734
2810
|
output_str += f"{'on' if handle_message.json_output else 'off'}{end}"
|
|
2811
|
+
case "display_channel_data":
|
|
2812
|
+
if json_output :
|
|
2813
|
+
output_str += json.dumps({"display_channel_data" : process_event_message.display_channel_data})+end
|
|
2814
|
+
else:
|
|
2815
|
+
output_str += f"{'on' if process_event_message.display_channel_data else 'off'}{end}"
|
|
2735
2816
|
case "color":
|
|
2736
2817
|
if json_output :
|
|
2737
2818
|
output_str += json.dumps({"color" : process_event_message.color})+end
|
|
@@ -3098,23 +3179,44 @@ async def next_cmd(mc, cmds, json_output=False, sink=sys.stdout, end="\n"):
|
|
|
3098
3179
|
argnum = 2
|
|
3099
3180
|
dest = None
|
|
3100
3181
|
|
|
3101
|
-
|
|
3182
|
+
wait_ack = False
|
|
3183
|
+
|
|
3184
|
+
args = cmds[1:]
|
|
3185
|
+
while len(args) > 0 and args[0][0] == "-":
|
|
3186
|
+
argnum += 1
|
|
3187
|
+
if len(args[0]) <= 1: # just a dash
|
|
3188
|
+
args=args[1:]
|
|
3189
|
+
continue
|
|
3190
|
+
a = args[0][1:]
|
|
3191
|
+
if a[0] == "a": # wait for an ack
|
|
3192
|
+
wait_ack = True
|
|
3193
|
+
|
|
3194
|
+
args = args[1:]
|
|
3195
|
+
|
|
3196
|
+
if len(args[0]) >= 12: # possibly an hex prefix
|
|
3102
3197
|
try:
|
|
3103
|
-
dest = bytes.fromhex(
|
|
3198
|
+
dest = bytes.fromhex(args[0])
|
|
3104
3199
|
except ValueError:
|
|
3105
3200
|
dest = None
|
|
3106
3201
|
|
|
3107
3202
|
if dest is None:
|
|
3108
|
-
dest = await get_contact_from_arg(mc,
|
|
3203
|
+
dest = await get_contact_from_arg(mc, args[0])
|
|
3109
3204
|
|
|
3110
3205
|
if dest is None:
|
|
3111
3206
|
if json_output :
|
|
3112
|
-
output_str += json.dumps({"error" : "unknown destination", "dest" :
|
|
3207
|
+
output_str += json.dumps({"error" : "unknown destination", "dest" : args[0]})+end
|
|
3113
3208
|
else:
|
|
3114
|
-
output_str += f"Unknown destination {
|
|
3209
|
+
output_str += f"Unknown destination {args[0]}{end}"
|
|
3115
3210
|
|
|
3116
|
-
|
|
3117
|
-
|
|
3211
|
+
elif wait_ack:
|
|
3212
|
+
ack = await msg_ack(mc, dest, args[1])
|
|
3213
|
+
if not ack:
|
|
3214
|
+
if json_output:
|
|
3215
|
+
output_str += json.dumps({"ack" : ack})+end
|
|
3216
|
+
else:
|
|
3217
|
+
output_str += f"No ack received{end}"
|
|
3218
|
+
else:
|
|
3219
|
+
res = await send_msg(mc, dest, args[1])
|
|
3118
3220
|
logger.debug(res)
|
|
3119
3221
|
if res.type == EventType.ERROR:
|
|
3120
3222
|
output_str += f"Error sending message: {res}{end}"
|
|
@@ -3141,6 +3243,27 @@ async def next_cmd(mc, cmds, json_output=False, sink=sys.stdout, end="\n"):
|
|
|
3141
3243
|
elif json_output :
|
|
3142
3244
|
output_str += json.dumps(res.payload, indent=4)+end
|
|
3143
3245
|
|
|
3246
|
+
case "chan_data" :
|
|
3247
|
+
argnum = 3 # chan/datatype/payload (path will be an option -p...)
|
|
3248
|
+
if cmds[1].isnumeric() :
|
|
3249
|
+
nb = int(cmds[1])
|
|
3250
|
+
else:
|
|
3251
|
+
chan = await get_channel_by_name(mc, cmds[1])
|
|
3252
|
+
if chan is None:
|
|
3253
|
+
nb = None
|
|
3254
|
+
else:
|
|
3255
|
+
nb = chan['channel_idx']
|
|
3256
|
+
if nb is None:
|
|
3257
|
+
logger.error("Invalid channel")
|
|
3258
|
+
else:
|
|
3259
|
+
res = await mc.commands.send_channel_data(
|
|
3260
|
+
nb, int(cmds[2]), bytes.fromhex(cmds[3]))
|
|
3261
|
+
logger.debug(res)
|
|
3262
|
+
if res.type == EventType.ERROR:
|
|
3263
|
+
output_str += f"Error sending chan data: {res}{end}"
|
|
3264
|
+
elif json_output :
|
|
3265
|
+
output_str += json.dumps(res.payload, indent=4)+end
|
|
3266
|
+
|
|
3144
3267
|
case "public" | "dch" : # default chan
|
|
3145
3268
|
argnum = 1
|
|
3146
3269
|
res = await send_chan_msg(mc, 0, cmds[1])
|
|
@@ -3581,7 +3704,9 @@ async def next_cmd(mc, cmds, json_output=False, sink=sys.stdout, end="\n"):
|
|
|
3581
3704
|
output_str += json.dumps(res, indent=4)+end
|
|
3582
3705
|
else:
|
|
3583
3706
|
width = shutil.get_terminal_size(fallback=(80, 24)).columns
|
|
3584
|
-
output_str += f"Got {res['results_count']} neighbours out of {res['neighbours_count']} from {contact['adv_name']}
|
|
3707
|
+
output_str += f"Got {res['results_count']} neighbours out of {res['neighbours_count']} from {contact['adv_name']}:"
|
|
3708
|
+
if res['results_count'] > 0:
|
|
3709
|
+
output_str += '\n'
|
|
3585
3710
|
first = True
|
|
3586
3711
|
for n in res['neighbours']:
|
|
3587
3712
|
if first :
|
|
@@ -3643,6 +3768,8 @@ async def next_cmd(mc, cmds, json_output=False, sink=sys.stdout, end="\n"):
|
|
|
3643
3768
|
display_types = LC_DISPLAY_TYPES
|
|
3644
3769
|
output_format = LC_OUTPUT_FORMAT
|
|
3645
3770
|
filter_flag = 0
|
|
3771
|
+
quiet = False
|
|
3772
|
+
display_total = True
|
|
3646
3773
|
|
|
3647
3774
|
args = cmds[1:]
|
|
3648
3775
|
while len(args) > 0 and args[0][0] == "-":
|
|
@@ -3663,68 +3790,77 @@ async def next_cmd(mc, cmds, json_output=False, sink=sys.stdout, end="\n"):
|
|
|
3663
3790
|
elif a[0] == "b": # flag
|
|
3664
3791
|
filter_flag = int(a[1:], 0)
|
|
3665
3792
|
|
|
3666
|
-
|
|
3793
|
+
elif a[0] == "q": # quiet
|
|
3794
|
+
quiet = True
|
|
3667
3795
|
|
|
3668
|
-
|
|
3669
|
-
|
|
3796
|
+
elif a[0] == "l": # only displays contact list (no total)
|
|
3797
|
+
display_total = False
|
|
3670
3798
|
|
|
3671
|
-
|
|
3672
|
-
# calculate distance for each node (override previous val)
|
|
3673
|
-
for c in ct:
|
|
3674
|
-
c['distance'] = distance_between(mc.self_info, c)
|
|
3799
|
+
args=args[1:]
|
|
3675
3800
|
|
|
3676
|
-
if
|
|
3677
|
-
|
|
3801
|
+
if not quiet:
|
|
3802
|
+
res = mc.contacts
|
|
3803
|
+
ct = list(res.values())
|
|
3678
3804
|
|
|
3679
|
-
|
|
3680
|
-
|
|
3805
|
+
if "d" in output_format.lower() or "d" in sort_order.lower():
|
|
3806
|
+
# calculate distance for each node (override previous val)
|
|
3807
|
+
for c in ct:
|
|
3808
|
+
c['distance'] = distance_between(mc.self_info, c)
|
|
3681
3809
|
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
continue
|
|
3685
|
-
keyfunc, reverse = SORTING_CRITERIA[s]
|
|
3686
|
-
ct.sort(key=keyfunc, reverse=reverse)
|
|
3810
|
+
if filter_flag > 0:
|
|
3811
|
+
ct = [x for x in ct if x.get("flags", 0) & filter_flag]
|
|
3687
3812
|
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
if argnum == 0:
|
|
3691
|
-
output_str += json.dumps(res, indent=4) + end
|
|
3692
|
-
else:
|
|
3693
|
-
output_str += json.dumps(ct, indent=4) + end
|
|
3694
|
-
else :
|
|
3813
|
+
if display_types != []:
|
|
3814
|
+
ct = [x for x in ct if x.get("type") in display_types]
|
|
3695
3815
|
|
|
3696
|
-
for
|
|
3697
|
-
if
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3816
|
+
for s in reversed(sort_order):
|
|
3817
|
+
if s not in SORTING_CRITERIA:
|
|
3818
|
+
continue
|
|
3819
|
+
keyfunc, reverse = SORTING_CRITERIA[s]
|
|
3820
|
+
ct.sort(key=keyfunc, reverse=reverse)
|
|
3821
|
+
|
|
3822
|
+
if json_output : # json output historically prints the whole dict ...
|
|
3823
|
+
# if there were no args, print the dict else the list
|
|
3824
|
+
if argnum == 0:
|
|
3825
|
+
output_str += json.dumps(res, indent=4) + end
|
|
3701
3826
|
else:
|
|
3702
|
-
|
|
3703
|
-
|
|
3704
|
-
|
|
3705
|
-
|
|
3706
|
-
|
|
3707
|
-
path_str =
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
|
|
3711
|
-
|
|
3712
|
-
|
|
3713
|
-
|
|
3714
|
-
|
|
3715
|
-
|
|
3716
|
-
|
|
3717
|
-
|
|
3718
|
-
|
|
3719
|
-
|
|
3720
|
-
|
|
3721
|
-
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
|
|
3725
|
-
|
|
3726
|
-
|
|
3727
|
-
|
|
3827
|
+
output_str += json.dumps(ct, indent=4) + end
|
|
3828
|
+
else :
|
|
3829
|
+
|
|
3830
|
+
for c in ct:
|
|
3831
|
+
if c['out_path_len'] == -1:
|
|
3832
|
+
path_str = "Flood"
|
|
3833
|
+
elif c['out_path_len'] == 0:
|
|
3834
|
+
path_str = "0 hop"
|
|
3835
|
+
else:
|
|
3836
|
+
phs = c['out_path_hash_mode'] + 1
|
|
3837
|
+
plen = c['out_path_len']
|
|
3838
|
+
path_str_in = c['out_path']
|
|
3839
|
+
path_str = path_str_in[:2*phs]
|
|
3840
|
+
for i in range(1,plen):
|
|
3841
|
+
path_str = path_str + "," + path_str_in[i*phs*2:(i+1)*2*phs]
|
|
3842
|
+
#path_str = f"{c[1]['out_path']}:{c[1]['out_path_hash_mode']}"
|
|
3843
|
+
output_str += f"{c['adv_name']:30} "
|
|
3844
|
+
output_str += f"{ANSI_START}34G"
|
|
3845
|
+
for i in output_format.lower():
|
|
3846
|
+
if i == "t":
|
|
3847
|
+
output_str += f" {CONTACT_TYPENAMES[c['type']]:4}"
|
|
3848
|
+
elif i == "k":
|
|
3849
|
+
output_str += f" {c['public_key'][:12]}"
|
|
3850
|
+
elif i == "h":
|
|
3851
|
+
output_str += f" {path_str:12}"
|
|
3852
|
+
elif i == "a":
|
|
3853
|
+
output_str += f" {time_ago_from_timestamp(c['last_advert']):>4}"
|
|
3854
|
+
elif i == "m":
|
|
3855
|
+
output_str += f" {time_ago_from_timestamp(c['lastmod']):>4}"
|
|
3856
|
+
elif i == "b":
|
|
3857
|
+
output_str += f" {c['flags']:02x}"
|
|
3858
|
+
elif i == "d":
|
|
3859
|
+
output_str += f" {c['distance']:7.2f}km"
|
|
3860
|
+
output_str += "\n"
|
|
3861
|
+
if display_total:
|
|
3862
|
+
output_str += f"> {len(ct)} from {len(mc.contacts)} contacts in device{end}"
|
|
3863
|
+
# we may have an issue with display total if end is empty ...
|
|
3728
3864
|
|
|
3729
3865
|
case "pending_contacts":
|
|
3730
3866
|
if json_output:
|
|
@@ -3832,6 +3968,17 @@ async def next_cmd(mc, cmds, json_output=False, sink=sys.stdout, end="\n"):
|
|
|
3832
3968
|
except ValueError:
|
|
3833
3969
|
output_str += f"Error ! Command format add_contact key type name{end}"
|
|
3834
3970
|
|
|
3971
|
+
case "reset_advert_time":
|
|
3972
|
+
argnum = 1
|
|
3973
|
+
contact = await get_contact_from_arg(mc, cmds[1])
|
|
3974
|
+
contact['last_advert'] = 0
|
|
3975
|
+
res = await mc.commands.update_contact(contact)
|
|
3976
|
+
logger.debug(res)
|
|
3977
|
+
if res.type == EventType.ERROR:
|
|
3978
|
+
output_str += f"Error while reseting last advert for: {cmds[1]}{end}"
|
|
3979
|
+
elif json_output :
|
|
3980
|
+
output_str += json.dumps(res.payload, indent=4)+end
|
|
3981
|
+
|
|
3835
3982
|
case "change_path" | "cp":
|
|
3836
3983
|
argnum = 2
|
|
3837
3984
|
contact = await get_contact_from_arg(mc, cmds[1])
|
|
@@ -4219,7 +4366,7 @@ async def next_cmd(mc, cmds, json_output=False, sink=sys.stdout, end="\n"):
|
|
|
4219
4366
|
process = None
|
|
4220
4367
|
|
|
4221
4368
|
try:
|
|
4222
|
-
if not htype in ["msgs", "rxlog"]:
|
|
4369
|
+
if not htype in ["msgs", "rxlog", "chan_data"]:
|
|
4223
4370
|
raise ValueError (f"Unknown handler type {htype}")
|
|
4224
4371
|
process = await asyncio.create_subprocess_exec(
|
|
4225
4372
|
*shlex.split(cmd, posix=True),
|
|
@@ -4257,7 +4404,7 @@ async def next_cmd(mc, cmds, json_output=False, sink=sys.stdout, end="\n"):
|
|
|
4257
4404
|
case "handler_detach":
|
|
4258
4405
|
argnum = 1
|
|
4259
4406
|
nb = int(cmds[1])
|
|
4260
|
-
handlers = HANDLERS["msgs"]|HANDLERS["rxlog"]
|
|
4407
|
+
handlers = HANDLERS["msgs"]|HANDLERS["rxlog"]|HANDLERS["chan_data"]
|
|
4261
4408
|
handler = handlers[nb]
|
|
4262
4409
|
handler["closed"] = True
|
|
4263
4410
|
for task_name in ("writer_task", "output_task"):
|
|
@@ -4470,6 +4617,7 @@ def get_help_for (cmdname, context="line") :
|
|
|
4470
4617
|
Filter is constructed with comma separated fields :
|
|
4471
4618
|
- u, matches modification time < or > than a timestamp
|
|
4472
4619
|
(can also be days hours or minutes ago if followed by d,h or m)
|
|
4620
|
+
- a, same as u but for advert time
|
|
4473
4621
|
- t, matches the type (1: client, 2: repeater, 3: room, 4: sensor)
|
|
4474
4622
|
- h, matches number of hops
|
|
4475
4623
|
- d, direct, similar to h>-1
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|