meshcore-cli 1.6.13__tar.gz → 1.6.14__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: meshcore-cli
3
- Version: 1.6.13
3
+ Version: 1.6.14
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
@@ -254,11 +254,13 @@ Will print out the content of `rx_log` as it comes in.
254
254
 
255
255
  #### Timers
256
256
 
257
- `timer [-j] [-c<contact>] [-s<scope>] <s> <line>` runs `line` every `s` seconds.
257
+ `timer [-j] [-x] [-n<count>] [-c<contact>] [-s<scope>] <s> <line>` runs `line` every `s` seconds.
258
258
 
259
259
  - `-c` sets the contact the line is run from (`~` for root).
260
260
  - `-s` sets the scope for the line (default is the current scope of the node).
261
261
  - `-j` forces json output for the timed line.
262
+ - `-x` executes the line immediately instead of waiting `s` seconds for the first run.
263
+ - `-n` runs the line `count` times and then disarms the timer (default: runs until cancelled). For instance `timer -x -n3 10m "chan 1 hi"` sends the message right away, then 2 more times at 10 minute intervals.
262
264
 
263
265
  `timers` lists the running timers and `timer_cancel <n>` cancels timer `n`.
264
266
 
@@ -235,11 +235,13 @@ Will print out the content of `rx_log` as it comes in.
235
235
 
236
236
  #### Timers
237
237
 
238
- `timer [-j] [-c<contact>] [-s<scope>] <s> <line>` runs `line` every `s` seconds.
238
+ `timer [-j] [-x] [-n<count>] [-c<contact>] [-s<scope>] <s> <line>` runs `line` every `s` seconds.
239
239
 
240
240
  - `-c` sets the contact the line is run from (`~` for root).
241
241
  - `-s` sets the scope for the line (default is the current scope of the node).
242
242
  - `-j` forces json output for the timed line.
243
+ - `-x` executes the line immediately instead of waiting `s` seconds for the first run.
244
+ - `-n` runs the line `count` times and then disarms the timer (default: runs until cancelled). For instance `timer -x -n3 10m "chan 1 hi"` sends the message right away, then 2 more times at 10 minute intervals.
243
245
 
244
246
  `timers` lists the running timers and `timer_cancel <n>` cancels timer `n`.
245
247
 
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "meshcore-cli"
7
- version = "1.6.13"
7
+ version = "1.6.14"
8
8
  authors = [
9
9
  { name="Florent de Lamotte", email="florent@frizoncorrea.fr" },
10
10
  ]
@@ -16,8 +16,9 @@ import subprocess
16
16
  import math
17
17
  from prompt_toolkit.shortcuts import PromptSession
18
18
  from prompt_toolkit.shortcuts import CompleteStyle
19
- from prompt_toolkit.completion import NestedCompleter, PathCompleter
19
+ from prompt_toolkit.completion import NestedCompleter, PathCompleter, Completer, Completion
20
20
  from prompt_toolkit.history import FileHistory
21
+ from prompt_toolkit.document import Document
21
22
  from prompt_toolkit.formatted_text import ANSI
22
23
  from prompt_toolkit.key_binding import KeyBindings
23
24
  from prompt_toolkit.shortcuts import radiolist_dialog
@@ -41,7 +42,7 @@ except ImportError:
41
42
  from meshcore import MeshCore, EventType, logger
42
43
 
43
44
  # Version
44
- VERSION = "v1.6.13"
45
+ VERSION = "v1.6.14"
45
46
 
46
47
  # default ble address is stored in a config file
47
48
  MCCLI_CONFIG_DIR = os.path.expanduser("~/.config/meshcore/")
@@ -252,8 +253,12 @@ def enqueue_handler_event(handler_type, payload):
252
253
  logger.warning(f"Handler {handler['id']} queue is full; dropping event")
253
254
 
254
255
  async def run_timer(mc, timer):
256
+ first = timer["exec"] # -x: first run without waiting for the delay
255
257
  while True:
256
- await asyncio.sleep(timer["secs"])
258
+ if first:
259
+ first = False
260
+ else:
261
+ await asyncio.sleep(timer["secs"])
257
262
  async with CMD_LOCK:
258
263
  base = set_scope.current_scope
259
264
  if base is None:
@@ -268,6 +273,13 @@ async def run_timer(mc, timer):
268
273
  if timer["scope"] != base:
269
274
  await set_scope(mc, base)
270
275
 
276
+ # n given: count the run and disarm the timer once it is exhausted
277
+ if timer["remaining"] is not None:
278
+ timer["remaining"] -= 1
279
+ if timer["remaining"] <= 0:
280
+ TIMERS.pop(timer["id"], None)
281
+ return
282
+
271
283
  async def write_handler(handler):
272
284
  try:
273
285
  while True:
@@ -704,12 +716,38 @@ class MyNestedCompleter(NestedCompleter):
704
716
  else: # normal behavior for remainder
705
717
  yield from super().get_completions(document, complete_event)
706
718
 
719
+ class OptionsCompleter(Completer):
720
+ def __init__(self, options, then=None):
721
+ self.options = list(options)
722
+ if isinstance(then, dict):
723
+ then = NestedCompleter.from_nested_dict(then)
724
+ self.then = then
725
+
726
+ def get_completions(self, document, complete_event):
727
+ words = document.text_before_cursor.split(" ")
728
+ current = words[-1]
729
+ done = [w for w in words[:-1] if w]
730
+
731
+ n = 0 # leading words that are options
732
+ while n < len(done) and done[n].startswith("-"):
733
+ n += 1
734
+
735
+ if n == len(done) and (current == "" or current.startswith("-")):
736
+ used = {w[:2] for w in done}
737
+ for o in self.options:
738
+ if o[:2] not in used and o.startswith(current):
739
+ yield Completion(o, start_position=-len(current))
740
+
741
+ if self.then is not None and not current.startswith("-"):
742
+ rest = " ".join(done[n:] + [current])
743
+ yield from self.then.get_completions(Document(rest, len(rest)), complete_event)
744
+
707
745
 
708
746
  def make_completion_dict(contacts, pending=None, to=None, channels=None):
709
747
  pending = pending or {}
710
748
  contact_list = {}
711
749
  pending_list = {}
712
- discovered_list = {"-a":None}
750
+ discovered_list = {}
713
751
  to_list = {}
714
752
 
715
753
  to_list["~"] = None
@@ -750,7 +788,7 @@ def make_completion_dict(contacts, pending=None, to=None, channels=None):
750
788
  root_completion_list = {
751
789
  "public" : None,
752
790
  "chan" : None,
753
- "chan_data" : None,
791
+ "chan_data" : OptionsCompleter(["-p"]),
754
792
  "ver" : None,
755
793
  "infos" : None,
756
794
  "advert" : None,
@@ -763,7 +801,8 @@ def make_completion_dict(contacts, pending=None, to=None, channels=None):
763
801
  "reboot" : None,
764
802
  "card" : None,
765
803
  "upload_card" : None,
766
- "contacts": None,
804
+ "contacts": OptionsCompleter(["-s", "-f", "-t", "-b", "-q", "-l"]),
805
+ "lc": OptionsCompleter(["-s", "-f", "-t", "-b", "-q", "-l"]),
767
806
  "pending_contacts": None,
768
807
  "add_pending": pending_list,
769
808
  "flush_pending": None,
@@ -774,9 +813,9 @@ def make_completion_dict(contacts, pending=None, to=None, channels=None):
774
813
  "path": contact_list,
775
814
  "disc_path" : contact_list,
776
815
  "advert_path" : contact_list | pending_list,
777
- "node_discover": {"-tall":None, "-tsens":None, "-trep":None, "-tcomp":None, "-troom":None, "-tcli":None},
816
+ "node_discover": OptionsCompleter(["-f", "-tall", "-tsens", "-trep", "-tcomp", "-troom", "-tcli"]),
778
817
  "list_discovered": None,
779
- "add_discovered": discovered_list,
818
+ "add_discovered": OptionsCompleter(["-a", "-n"], then=discovered_list),
780
819
  "trace" : None,
781
820
  "reset_path" : contact_list,
782
821
  "change_path" : contact_list,
@@ -792,7 +831,7 @@ def make_completion_dict(contacts, pending=None, to=None, channels=None):
792
831
  "handler_attach": {"rxlog":None, "msgs":None, "chan_data":None, "telemetry":None},
793
832
  "handler_detach": None,
794
833
  "handlers": None,
795
- "timer": None,
834
+ "timer": OptionsCompleter(["-j", "-x", "-n", "-c", "-s"]),
796
835
  "timer_cancel": None,
797
836
  "timers": None,
798
837
  "login" : contact_list,
@@ -999,7 +1038,7 @@ def make_completion_dict(contacts, pending=None, to=None, channels=None):
999
1038
  "unsub_telemetry" : None,
1000
1039
  "req_binary" : None,
1001
1040
  "forget_password" : None,
1002
- "timer" : None,
1041
+ "timer" : OptionsCompleter(["-j", "-x", "-n", "-s"]),
1003
1042
  }
1004
1043
 
1005
1044
  client_completion_list = dict(contact_completion_list)
@@ -4658,18 +4697,30 @@ async def next_cmd(mc, cmds, json_output=False, sink=sys.stdout, end="\n"):
4658
4697
  output_str += json.dumps(HANDLERS, default=str)+end
4659
4698
 
4660
4699
  case "timer":
4661
- argnum = 2 # [-j] [-c<contact>] [-s<scope>] secs line
4700
+ argnum = 2 # [-j] [-x] [-n<count>] [-c<contact>] [-s<scope>] secs line
4662
4701
  t_contact = None
4663
4702
  t_scope = set_scope.current_scope
4664
4703
  if t_scope is None:
4665
4704
  t_scope = ""
4666
4705
  t_json = json_output
4706
+ t_count = None # None = runs until cancelled
4707
+ t_exec = False # -x : first run without delay
4667
4708
  valid = True
4668
4709
 
4669
4710
  args = cmds[1:]
4670
4711
  while len(args) > 0 and args[0][0] == "-":
4671
4712
  argnum += 1
4672
4713
 
4714
+ if args[0].startswith("-x"): # exec now, then every s seconds
4715
+ t_exec = True
4716
+
4717
+ if args[0].startswith("-n"): # number of runs before disarming
4718
+ if args[0][2:].isdigit() and int(args[0][2:]) > 0:
4719
+ t_count = int(args[0][2:])
4720
+ else:
4721
+ valid = False
4722
+ logger.error(f"Invalid count {args[0][2:]!r} for -n, expected a positive integer")
4723
+
4673
4724
  if args[0].startswith("-j"): # force json output for the timer
4674
4725
  t_json = True
4675
4726
 
@@ -4713,6 +4764,9 @@ async def next_cmd(mc, cmds, json_output=False, sink=sys.stdout, end="\n"):
4713
4764
  timer["scope"] = t_scope
4714
4765
  timer["contact"] = t_contact
4715
4766
  timer["json"] = t_json
4767
+ timer["exec"] = t_exec
4768
+ timer["count"] = t_count
4769
+ timer["remaining"] = t_count
4716
4770
  timer["task"] = asyncio.create_task(run_timer(mc, timer))
4717
4771
  TIMERS[LAST_TIMER_ID] = timer
4718
4772
  if json_output:
@@ -4723,7 +4777,10 @@ async def next_cmd(mc, cmds, json_output=False, sink=sys.stdout, end="\n"):
4723
4777
  case "timer_cancel":
4724
4778
  argnum = 1
4725
4779
  nb = int(cmds[1])
4726
- timer = TIMERS.pop(nb)
4780
+ timer = TIMERS.pop(nb, None)
4781
+ if timer is None:
4782
+ logger.error(f"No timer {nb} (unknown, cancelled or already finished)")
4783
+ return (cmds[argnum+1:], output_str)
4727
4784
  timer["task"].cancel()
4728
4785
  try:
4729
4786
  await timer["task"]
@@ -4819,7 +4876,7 @@ def command_help():
4819
4876
  aliases_load : load aliases from a file
4820
4877
  handler_attach <d> <c> : attach c as a handler for d
4821
4878
  handler_detach <n> : detach an handler (from its handle n)
4822
- timer <s> <c> : runs command c every s seconds
4879
+ timer [-x] [-n<k>] <s> <c> : runs command c every s seconds (k times if -n, now if -x)
4823
4880
  timer_cancel <n> : cancels a timer (from its handle n)
4824
4881
  timers : lists current timers
4825
4882
  Messaging
@@ -5266,10 +5323,12 @@ meshcore-cli lets you attach shell process to msg rx_log chan_data or telemetry
5266
5323
  """)
5267
5324
 
5268
5325
  elif "timer" in cmdname:
5269
- print("""timer [-j] [-c<contact>] [-s<scope>] <s> <line>: runs line every s seconds (s can be postfixed with s, m, h or d)
5326
+ print("""timer [-j] [-x] [-n<count>] [-c<contact>] [-s<scope>] <s> <line>: runs line every s seconds (s can be postfixed with s, m, h or d)
5270
5327
 
5271
5328
  * args:
5272
5329
  - `-j` forces json output for the timed line.
5330
+ - `-x` executes the line immediately, then every `s` seconds (without it, the first run happens after `s` seconds).
5331
+ - `-n` runs the line `count` times, then disarms the timer (default: runs until cancelled).
5273
5332
  - `-c` sets the contact the line is run from (`~` for root).
5274
5333
  - `-s` sets the scope for the line, defaults to the current scope.
5275
5334
 
File without changes
File without changes
File without changes
File without changes