Skip to content

Commit 90118ab

Browse files
committed
5.15.3 - config commands
1 parent a7eb308 commit 90118ab

File tree

14 files changed

+100
-13
lines changed

14 files changed

+100
-13
lines changed

.github/workflows/python-package.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ jobs:
7878
7979
- run: |
8080
mk python-release owner=libre-embedded \
81-
repo=runtimepy version=5.15.2
81+
repo=runtimepy version=5.15.3
8282
if: |
8383
matrix.python-version == '3.12'
8484
&& matrix.system == 'ubuntu-latest'

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
=====================================
33
generator=datazen
44
version=3.2.3
5-
hash=f1c75c9b812e8ff29fdda46f58009aef
5+
hash=ed2f5b3731ba189c4a3ec2f2252b622e
66
=====================================
77
-->
88

9-
# runtimepy ([5.15.2](https://pypi.org/project/runtimepy/))
9+
# runtimepy ([5.15.3](https://pypi.org/project/runtimepy/))
1010

1111
[![python](https://img.shields.io/pypi/pyversions/runtimepy.svg)](https://pypi.org/project/runtimepy/)
1212
![Build Status](https://github.com/libre-embedded/runtimepy/workflows/Python%20Package/badge.svg)

local/variables/package.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
22
major: 5
33
minor: 15
4-
patch: 2
4+
patch: 3
55
entry: runtimepy

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta:__legacy__"
44

55
[project]
66
name = "runtimepy"
7-
version = "5.15.2"
7+
version = "5.15.3"
88
description = "A framework for implementing Python services."
99
readme = "README.md"
1010
requires-python = ">=3.12"

runtimepy/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# =====================================
22
# generator=datazen
33
# version=3.2.3
4-
# hash=839ec3c3fa52de16f775789c0d38bf3e
4+
# hash=f5155e85b2694b012648fdbe9c12b1cd
55
# =====================================
66

77
"""
@@ -10,7 +10,7 @@
1010

1111
DESCRIPTION = "A framework for implementing Python services."
1212
PKG_NAME = "runtimepy"
13-
VERSION = "5.15.2"
13+
VERSION = "5.15.3"
1414

1515
# runtimepy-specific content.
1616
METRICS_NAME = "metrics"

runtimepy/channel/environment/command/__init__.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212

1313
# third-party
1414
from vcorelib import DEFAULT_ENCODING
15+
from vcorelib.dict import GenericStrDict
1516
from vcorelib.io import ARBITER, JsonObject
17+
from vcorelib.io.bus import BUS
1618
from vcorelib.logging import DEFAULT_TIME_FORMAT, LoggerMixin
1719
from vcorelib.math import default_time_ns, nano_str
1820
from vcorelib.names import name_search
@@ -25,6 +27,7 @@
2527
CommandHook,
2628
EnvironmentMap,
2729
)
30+
from runtimepy.channel.environment.command.result import CommandResult
2831
from runtimepy.channel.registry import ParsedEvent
2932
from runtimepy.mapping import DEFAULT_PATTERN
3033

@@ -243,6 +246,38 @@ def register(self, name: str, env: ChannelCommandProcessor) -> None:
243246
ENVIRONMENTS = GLOBAL
244247

245248

249+
def global_command(env: str, value: str) -> Optional[CommandResult]:
250+
"""Handle a global command."""
251+
252+
result = None
253+
if env in GLOBAL:
254+
result = GLOBAL[env].command(value)
255+
else:
256+
GLOBAL.logger.error(
257+
"Couldn't run command env='%s' value='%s'.", env, value
258+
)
259+
return result
260+
261+
262+
def global_commands(*cmds: tuple[str, str]) -> None:
263+
"""Handle a global command."""
264+
for env, value in cmds:
265+
global_command(env, value)
266+
267+
268+
async def global_command_bus(payload: GenericStrDict) -> None:
269+
"""Handle a bus message."""
270+
271+
if "env" in payload and "value" in payload:
272+
global_command(payload["env"], payload["value"])
273+
elif "cmds" in payload:
274+
global_commands(*payload["cmds"])
275+
276+
277+
BUS.register_ro("command", global_command_bus)
278+
BUS.register_ro("cmd", global_command_bus)
279+
280+
246281
def clear_env() -> None:
247282
"""Reset the global environment mapping."""
248283
GLOBAL.clear()

runtimepy/data/dummy_load.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,7 @@ processes:
107107
app: runtimepy.sample.program.run
108108

109109
program: runtimepy.sample.program.SampleProgram
110+
111+
commands:
112+
- [udp_json_client, "set log_level warning"]
113+
- [proc1.peer, "set log_level warning"]

runtimepy/data/schemas/ConnectionArbiterConfig.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ properties:
2626
items:
2727
$ref: package://runtimepy/schemas/StructConfig.yaml
2828

29+
commands:
30+
type: array
31+
items:
32+
type: array
33+
minItems: 2
34+
maxItems: 2
35+
items:
36+
- type: string
37+
- type: string
38+
2939
tasks:
3040
type: array
3141
items:

runtimepy/net/arbiter/base.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from runtimepy.channel.environment.command import (
2727
clear_env,
2828
env_json_data,
29+
global_commands,
2930
register_env,
3031
)
3132
from runtimepy.net.arbiter.housekeeping import housekeeping
@@ -145,6 +146,8 @@ def __init__(
145146
# A copy of named port mappings (loaded via external config).
146147
self._ports: dict[str, int] = {}
147148

149+
self._commands: list[tuple[str, str]] = []
150+
148151
self._init()
149152

150153
def _init(self) -> None:
@@ -318,6 +321,11 @@ async def _main(
318321

319322
# Run initialization methods.
320323
result = await self._run_apps_list(self._inits, info)
324+
325+
# Run commands.
326+
await _asyncio.sleep(0)
327+
global_commands(*self._commands)
328+
321329
if result == 0:
322330
# Get application methods.
323331
apps = self._apps

runtimepy/net/arbiter/config/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,5 +245,8 @@ async def process_config(
245245
assert "root" not in config.config, config.config
246246
config.config["root"] = root
247247

248+
# Register commands.
249+
self._commands = config.commands
250+
248251

249252
ConfigConnectionArbiter.add_search_package(PKG_NAME)

0 commit comments

Comments
 (0)