Include arch-independent builds

This commit is contained in:
oitsjustjose 2024-12-11 00:36:48 -06:00
commit 97e3456250
4 changed files with 69 additions and 69 deletions

BIN
pixlet.aarch64 Normal file

Binary file not shown.

BIN
pixlet.x86_64 Normal file

Binary file not shown.

View file

@ -2,92 +2,91 @@
import subprocess import subprocess
from pathlib import Path from pathlib import Path
from platform import machine
from renderables import Renderable from renderables import Renderable
ROOT_PATH = Path("./").resolve() class PixletHelper:
PIXLET_EXEC = ROOT_PATH.joinpath("pixlet").resolve() def __init__(self):
self.root_path = Path("./").resolve()
self.pixlet = self.root_path.joinpath(f"pixlet.{machine()}").resolve()
def push_to_tidbyt(self, renderable: Renderable) -> None:
"""Pushes a renderable to the Tidbyt device
def push_to_tidbyt(renderable: Renderable) -> None: Args:
"""Pushes a renderable to the Tidbyt device renderable (Renderable): The Pixlet Configuration for the given state
"""
self.__display(self.__render(renderable))
Args: def __render(self, renderable: Renderable) -> Path:
renderable (Renderable): The Pixlet Configuration for the given state """Renders a given PixeltConfiguration (and any template args) to webp
"""
__display(__render(renderable))
Args:
renderable (Renderable): The Pixlet Configuration for the given state
def __render(renderable: Renderable) -> Path: Returns:
"""Renders a given PixeltConfiguration (and any template args) to webp Path: The path to the rendered output file
"""
output_path = self.__prepare_file(renderable)
Args: with subprocess.Popen([self.pixlet, "render", str(output_path)]) as proc:
renderable (Renderable): The Pixlet Configuration for the given state proc.wait()
Returns: return self.root_path.joinpath("tmp.webp").resolve()
Path: The path to the rendered output file
"""
output_path = __prepare_file(renderable)
with subprocess.Popen([PIXLET_EXEC, "render", str(output_path)]) as proc: def __display(self, path: Path) -> None:
proc.wait() """Pushes a given rendered webp file to the pixlet on the same installation id
return ROOT_PATH.joinpath("tmp.webp").resolve() Args:
path (Path): The path to the given rendered webp
"""
with open(
self.root_path.joinpath("device_id").resolve(), "r", encoding="utf8"
) as handle:
dev_id = handle.read()
def __display(path: Path) -> None: with subprocess.Popen(
"""Pushes a given rendered webp file to the pixlet on the same installation id [
self.pixlet,
"push",
"--installation-id",
"automation",
dev_id,
str(path),
]
) as proc:
proc.wait()
Args: def __prepare_file(self, renderable: Renderable) -> Path:
path (Path): The path to the given rendered webp """Prepares a given pixlet star file. If the file is a template, checks the template keys and prepares the template before writing to the temp path
"""
with open( Args:
ROOT_PATH.joinpath("device_id").resolve(), "r", encoding="utf8" renderable (Renderable): The Pixlet Configuration for the given state
) as handle:
dev_id = handle.read()
with subprocess.Popen( Raises:
[ Exception: Thrown if a required key defined in the Renderable is missing
PIXLET_EXEC,
"push",
"--installation-id",
"automation",
dev_id,
str(path),
]
) as proc:
proc.wait()
Returns:
Path: The path to the output file
"""
output_path = self.root_path.joinpath("tmp.star").resolve()
def __prepare_file(renderable: Renderable) -> Path: with open(renderable.file_path, "r", encoding="utf8") as handle:
"""Prepares a given pixlet star file. If the file is a template, checks the template keys and prepares the template before writing to the temp path data = handle.read()
Args: if renderable.is_dynamic:
renderable (Renderable): The Pixlet Configuration for the given state args = renderable.resolve_template_keys()
for key in renderable.template_keys:
if not key in args:
raise Exception(
f"Failed to render Pixlet Configuration for {renderable.for_state.name} -- missing key '{key}'"
)
data = data.replace(key, args[key])
Raises: with open(output_path, "w", encoding="utf8") as handle:
Exception: Thrown if a required key defined in the Renderable is missing handle.write(data)
Returns: return output_path
Path: The path to the output file
"""
output_path = ROOT_PATH.joinpath("tmp.star").resolve()
with open(renderable.file_path, "r", encoding="utf8") as handle:
data = handle.read()
if renderable.is_dynamic:
args = renderable.resolve_template_keys()
for key in renderable.template_keys:
if not key in args:
raise Exception(
f"Failed to render Pixlet Configuration for {renderable.for_state.name} -- missing key '{key}'"
)
data = data.replace(key, args[key])
with open(output_path, "w", encoding="utf8") as handle:
handle.write(data)
return output_path

View file

@ -4,7 +4,7 @@ from threading import Thread
from time import sleep from time import sleep
from typing import Dict from typing import Dict
from pixlet import push_to_tidbyt from pixlet import PixletHelper
from renderables import Renderable from renderables import Renderable
from renderables.forgeserv import ForgeServ from renderables.forgeserv import ForgeServ
@ -47,6 +47,7 @@ class StateManager:
self.timeout = timeout self.timeout = timeout
self.thread: Thread = None self.thread: Thread = None
self.stop_thread = False self.stop_thread = False
self.__pixlet_helper = PixletHelper()
self.__start() self.__start()
def update(self, new_state: AppState): def update(self, new_state: AppState):
@ -59,7 +60,7 @@ class StateManager:
return self.state return self.state
self.state = new_state self.state = new_state
push_to_tidbyt(self.renderables[self.state]) self.__pixlet_helper.push_to_tidbyt(self.renderables[self.state])
def __start(self): def __start(self):
"""Instantiates and starts the worker thread """Instantiates and starts the worker thread
@ -76,5 +77,5 @@ class StateManager:
"""A looping task that renders and pushes the correct pixlet based on state""" """A looping task that renders and pushes the correct pixlet based on state"""
while not self.stop_thread: while not self.stop_thread:
if self.renderables[self.state].is_dynamic: if self.renderables[self.state].is_dynamic:
push_to_tidbyt(self.renderables[self.state]) self.__pixlet_helper.push_to_tidbyt(self.renderables[self.state])
sleep(self.timeout) sleep(self.timeout)