Include arch-independent builds
This commit is contained in:
parent
9491692407
commit
97e3456250
4 changed files with 69 additions and 69 deletions
|
|
@ -2,92 +2,91 @@
|
|||
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
from platform import machine
|
||||
|
||||
from renderables import Renderable
|
||||
|
||||
|
||||
ROOT_PATH = Path("./").resolve()
|
||||
PIXLET_EXEC = ROOT_PATH.joinpath("pixlet").resolve()
|
||||
class PixletHelper:
|
||||
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:
|
||||
"""Pushes a renderable to the Tidbyt device
|
||||
Args:
|
||||
renderable (Renderable): The Pixlet Configuration for the given state
|
||||
"""
|
||||
self.__display(self.__render(renderable))
|
||||
|
||||
Args:
|
||||
renderable (Renderable): The Pixlet Configuration for the given state
|
||||
"""
|
||||
__display(__render(renderable))
|
||||
def __render(self, renderable: Renderable) -> Path:
|
||||
"""Renders a given PixeltConfiguration (and any template args) to webp
|
||||
|
||||
Args:
|
||||
renderable (Renderable): The Pixlet Configuration for the given state
|
||||
|
||||
def __render(renderable: Renderable) -> Path:
|
||||
"""Renders a given PixeltConfiguration (and any template args) to webp
|
||||
Returns:
|
||||
Path: The path to the rendered output file
|
||||
"""
|
||||
output_path = self.__prepare_file(renderable)
|
||||
|
||||
Args:
|
||||
renderable (Renderable): The Pixlet Configuration for the given state
|
||||
with subprocess.Popen([self.pixlet, "render", str(output_path)]) as proc:
|
||||
proc.wait()
|
||||
|
||||
Returns:
|
||||
Path: The path to the rendered output file
|
||||
"""
|
||||
output_path = __prepare_file(renderable)
|
||||
return self.root_path.joinpath("tmp.webp").resolve()
|
||||
|
||||
with subprocess.Popen([PIXLET_EXEC, "render", str(output_path)]) as proc:
|
||||
proc.wait()
|
||||
def __display(self, path: Path) -> None:
|
||||
"""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:
|
||||
"""Pushes a given rendered webp file to the pixlet on the same installation id
|
||||
with subprocess.Popen(
|
||||
[
|
||||
self.pixlet,
|
||||
"push",
|
||||
"--installation-id",
|
||||
"automation",
|
||||
dev_id,
|
||||
str(path),
|
||||
]
|
||||
) as proc:
|
||||
proc.wait()
|
||||
|
||||
Args:
|
||||
path (Path): The path to the given rendered webp
|
||||
"""
|
||||
def __prepare_file(self, renderable: Renderable) -> Path:
|
||||
"""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(
|
||||
ROOT_PATH.joinpath("device_id").resolve(), "r", encoding="utf8"
|
||||
) as handle:
|
||||
dev_id = handle.read()
|
||||
Args:
|
||||
renderable (Renderable): The Pixlet Configuration for the given state
|
||||
|
||||
with subprocess.Popen(
|
||||
[
|
||||
PIXLET_EXEC,
|
||||
"push",
|
||||
"--installation-id",
|
||||
"automation",
|
||||
dev_id,
|
||||
str(path),
|
||||
]
|
||||
) as proc:
|
||||
proc.wait()
|
||||
Raises:
|
||||
Exception: Thrown if a required key defined in the Renderable is missing
|
||||
|
||||
Returns:
|
||||
Path: The path to the output file
|
||||
"""
|
||||
output_path = self.root_path.joinpath("tmp.star").resolve()
|
||||
|
||||
def __prepare_file(renderable: Renderable) -> Path:
|
||||
"""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(renderable.file_path, "r", encoding="utf8") as handle:
|
||||
data = handle.read()
|
||||
|
||||
Args:
|
||||
renderable (Renderable): The Pixlet Configuration for the given state
|
||||
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])
|
||||
|
||||
Raises:
|
||||
Exception: Thrown if a required key defined in the Renderable is missing
|
||||
with open(output_path, "w", encoding="utf8") as handle:
|
||||
handle.write(data)
|
||||
|
||||
Returns:
|
||||
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
|
||||
return output_path
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ from threading import Thread
|
|||
from time import sleep
|
||||
from typing import Dict
|
||||
|
||||
from pixlet import push_to_tidbyt
|
||||
from pixlet import PixletHelper
|
||||
from renderables import Renderable
|
||||
from renderables.forgeserv import ForgeServ
|
||||
|
||||
|
|
@ -47,6 +47,7 @@ class StateManager:
|
|||
self.timeout = timeout
|
||||
self.thread: Thread = None
|
||||
self.stop_thread = False
|
||||
self.__pixlet_helper = PixletHelper()
|
||||
self.__start()
|
||||
|
||||
def update(self, new_state: AppState):
|
||||
|
|
@ -59,7 +60,7 @@ class StateManager:
|
|||
return self.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):
|
||||
"""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"""
|
||||
while not self.stop_thread:
|
||||
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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue