Tools
CuemsDeploy: async rsync-based media and project deployer for CUEMS nodes.
Async model: _sync(), _check_mandatory_sources(), _kill(), and _pump() are coroutines scheduled on the event loop injected via NodeEngine.start() late-bind. sync_files() remains a synchronous blocking API; it submits _deploy_all_async() via run_coroutine_threadsafe() and blocks until completion. Watchdogs inside the coroutine bound all wait times.
Late-bind protocol
NodeEngine.init() creates CuemsDeploy(loop=None). NodeEngine.start() calls CUE_HANDLER.set_nng_comms(...), which starts AsyncCommsThread (creates the event_loop), then: self.deploy_manager.loop = CUE_HANDLER.communications_thread.event_loop Any sync_files() before that bind returns False immediately.
Why _avahi_resolve stays synchronous: it is called from init() before any asyncio loop exists, so subprocess.run() (short timeout) is correct.
CuemsDeploy
Source code in src/cuemsengine/tools/CuemsDeploy.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 | |
__init__(library_path='/opt/cuems_library/', tmp_path='/tmp/cuems_library/', controller_ip=None, hostname=None, log_file='/run/cuems/rsync.log', on_progress=None, loop=None)
Construct a deploy manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
controller_ip
|
str | None
|
IP of the controller's rsync daemon (preferred). Pass BaseEngine.controller_ip. If falsy, manager runs disabled. |
None
|
hostname
|
str | None
|
Legacy fallback resolved via avahi when controller_ip is not provided. Kept for backwards compatibility. |
None
|
log_file
|
str
|
Where rsync writes its log. |
'/run/cuems/rsync.log'
|
on_progress
|
Callable[[dict], None] | None
|
Optional callback fired for each rsync progress update (parsed from --info=progress2). Receives a dict with keys bytes, pct, rate, eta, and optionally xfr, remaining, total. Must be non-blocking — invoked from the asyncio loop. |
None
|
loop
|
AbstractEventLoop | None
|
The asyncio event loop for run_coroutine_threadsafe(). Defaults to None; late-bind via NodeEngine.start(). |
None
|
Source code in src/cuemsengine/tools/CuemsDeploy.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
sync_files(project, tag, file_names=None)
Sync files from the controller to the node.
Submits _deploy_all_async() to self.loop via run_coroutine_threadsafe() and blocks until the coroutine completes. Watchdogs inside the coroutine handle all time bounds; no external timeout is needed here.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project
|
str
|
Project identifier used to build paths and log file names. |
required |
tag
|
str
|
Transfer type — |
required |
file_names
|
list[str] | None
|
Explicit list of rsync-relative paths to transfer. When
omitted (or empty) and tag is |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True on success; False if disabled, loop unbound, precheck failed, |
bool
|
rsync exited non-zero, or any unexpected exception occurred. On |
bool
|
failure, self.errors contains one or more diagnostic strings. |
Source code in src/cuemsengine/tools/CuemsDeploy.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | |
MtcListener
Bases: Thread
Source code in src/cuemsengine/tools/MtcListener.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | |
PortHandler
Bases: object
Source code in src/cuemsengine/tools/PortHandler.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
__new__()
Singleton class responsible for handling port objects.
Holds a list of used ports and manages the assignment of new ports. The ports are assigned to a cue Config ports are ports that are ports assigned with None as key Thread-safe: internal state mutations are guarded by a Lock.
Source code in src/cuemsengine/tools/PortHandler.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | |
add_config_ports(ports)
Add new ports to the configuration dictionary
Source code in src/cuemsengine/tools/PortHandler.py
171 172 173 174 175 176 177 178 | |
add_system_ports()
Add all system ports to the configuration dictionary
Source code in src/cuemsengine/tools/PortHandler.py
165 166 167 168 169 | |
assign_ports(names, cue=None)
Assign free ports to a list of names
This method is thread-safe and should be the preferred way to assign ports to a list of names for a cue or config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
names
|
list[str]
|
The names to assign ports to |
required |
cue
|
CuemsDict
|
The cue to assign ports to |
None
|
Source code in src/cuemsengine/tools/PortHandler.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
check_port_range(ports)
staticmethod
Check the port range
Source code in src/cuemsengine/tools/PortHandler.py
126 127 128 129 130 131 132 133 134 135 | |
check_ports(ports, check_range=True)
Check the ports for a cue and return the list of ports if they are valid
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ports
|
list | dict
|
The ports to check |
required |
check_range
|
bool
|
Whether to check the port range |
True
|
Returns:
| Type | Description |
|---|---|
list
|
The ports list if they are valid |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Source code in src/cuemsengine/tools/PortHandler.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
clean_random_ports()
Clean the random ports set by keeping only ports that are in use by the system
Source code in src/cuemsengine/tools/PortHandler.py
206 207 208 209 210 211 212 | |
find_system_ports()
Find all system ports used on the system
Source code in src/cuemsengine/tools/PortHandler.py
159 160 161 162 163 | |
get_all_used_ports()
Get the set of all used ports (assigned ports + random ports combined)
Source code in src/cuemsengine/tools/PortHandler.py
89 90 91 92 93 94 95 96 | |
get_free_port()
Get a free port
Thread-safe: internal state mutations are guarded by a Lock.
Returns:
| Type | Description |
|---|---|
int
|
The free port |
Raises: ValueError: If no free ports are found
Source code in src/cuemsengine/tools/PortHandler.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
get_free_ports(n)
Get n free ports
Source code in src/cuemsengine/tools/PortHandler.py
153 154 155 156 157 | |
get_ports(cue)
Get the ports for a cue
Source code in src/cuemsengine/tools/PortHandler.py
59 60 61 62 63 64 | |
last_port()
Get the last port
Source code in src/cuemsengine/tools/PortHandler.py
52 53 54 55 56 57 | |
new_random_port()
Get a new random port and store it
Source code in src/cuemsengine/tools/PortHandler.py
180 181 182 183 184 185 186 | |
remove_ports(cue)
Remove the ports for a cue
Source code in src/cuemsengine/tools/PortHandler.py
79 80 81 82 83 84 85 86 87 | |
remove_random_port(port)
Remove a specific port from the random ports list, freeing it for reuse. Called when an OSC client that owned the port is closed.
Source code in src/cuemsengine/tools/PortHandler.py
195 196 197 198 199 200 201 202 203 204 | |
set_ports(cue, ports, check_range=True)
Set the ports for a cue
Source code in src/cuemsengine/tools/PortHandler.py
66 67 68 69 70 71 72 73 74 75 76 77 | |
store_random_port(port)
Store a random port to the random ports set
Source code in src/cuemsengine/tools/PortHandler.py
188 189 190 191 192 193 | |
Reader for /run/cuems/display.conf.
display.conf is written by cuems-generate-display-conf (ExecStartPre of
cuems-videocomposer.service) and read by both the videocomposer (for DRM
modeset + canvas layout) and the engine (for canvas geometry + per-output
canvas regions, replacing the broken x = index * 1920 heuristic that used
to live in NodeEngine.set_video_outputs).
File format is INI-like:
canvas_layout=custom
canvas_size=5760x1080 # optional, overrides bbox
[output:HDMI-A-1]
canvas_region=0,0,1920,1080
resolution=1920x1080 # optional
refresh=60.0 # optional
The engine consumes canvas_region and the optional global canvas_size
override; resolution + refresh are read by the videocomposer directly.
DisplayConfNotFoundError
Bases: RuntimeError
display.conf is missing, unreadable, or has no [output:*] sections.
Source code in src/cuemsengine/tools/display_conf.py
36 37 | |
DisplayConfValueError
Bases: RuntimeError
display.conf is present but contains an invalid value (e.g. a canvas_size override that is malformed, non-positive, or smaller than the per-output region bounding box).
Source code in src/cuemsengine/tools/display_conf.py
40 41 42 43 | |
read_display_conf(path=DEFAULT_DISPLAY_CONF)
Parse display.conf and return (regions, canvas_size).
Returns a 2-tuple:
regions:{connector_name: {'x', 'y', 'width', 'height'}}with pixel-int values.canvas_size:(canvas_width, canvas_height). If the globalcanvas_size=WIDTHxHEIGHTkey is present in the file's preamble, it is used (after validating it is >= the per-region bounding box). Otherwise, computed asmax(x + width, y + height)over all regions.
Raises:
DisplayConfNotFoundErrorif the file is missing or has no[output:*]sections.DisplayConfValueErrorifcanvas_size=is malformed, has non-positive values, or is smaller than the per-region bbox.
Source code in src/cuemsengine/tools/display_conf.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
get_pid_by_port(target_port)
Get the PID using a specific port.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_port
|
int
|
The port number to look up |
required |
Returns:
| Type | Description |
|---|---|
Optional[int]
|
Optional[int]: The process ID if found, None otherwise |
Example
pid = get_pid_by_port(8080) print(pid) 1234
Source code in src/cuemsengine/tools/system_ports.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
get_port_by_pid(target_pid)
Get the port used by a specific PID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_pid
|
int
|
The process ID to look up |
required |
Returns:
| Type | Description |
|---|---|
Optional[int]
|
Optional[int]: The port number if found, None otherwise |
Example
port = get_port_by_pid(1234) print(port) 8080
Source code in src/cuemsengine/tools/system_ports.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
get_used_ports_with_pid(user=None)
Recover all used ports using the 'ss' command. Returns a dictionary with PID as key and port as value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user
|
str
|
The user to filter ports by |
None
|
Returns:
| Type | Description |
|---|---|
Dict[str, int]
|
Dict[str, int]: Dictionary mapping PID to port |
Example
ports = get_used_ports_with_pid() print(ports) {'1234': 8080, '5678': 9090}
Source code in src/cuemsengine/tools/system_ports.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
is_port_in_use(port)
Check if a specific port is in use.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
port
|
int
|
The port number to check |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if port is in use, False otherwise |
Example
if is_port_in_use(8080): ... print("Port 8080 is in use") ... else: ... print("Port 8080 is available")
Source code in src/cuemsengine/tools/system_ports.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |