Skip to content

Commit

Permalink
feat: hold update until the app creates a file signaling it is loaded -
Browse files Browse the repository at this point in the history
closes #177
  • Loading branch information
sassanh committed Jan 10, 2025
1 parent 69333bb commit 97c300e
Show file tree
Hide file tree
Showing 44 changed files with 98 additions and 85 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- fix: pass raw bytes to `DisplayRenderEvent` and `DisplayCompressedRenderEvent` to avoid encoding issues
- fix: add ".local" to hostname in users menus - closes #134
- fix: use stdout instead of stderr for reading rpi-connect process output - closes #174
- feat: hold update until the app creates a file signaling it is loaded - closes #177

## Version 1.1.0

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ select = ["ALL"]
ignore = ["INP001", "PLR0911", "D203", "D213", "PLC0415", "TD003"]
fixable = ["ALL"]
unfixable = []
logger-objects = ['ubo_app.logging.logger']
logger-objects = ['ubo_app.logger.logger']

[tool.ruff.lint.flake8-builtins]
builtins-ignorelist = ["type", "id"]
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def app_context(original_app_context: AppContext) -> AppContext:
def _logger() -> None:
import logging

from ubo_app.logging import ExtraFormatter
from ubo_app.logger import ExtraFormatter

extra_formatter = ExtraFormatter()

Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ async def app_context(

import os

from ubo_app.logging import setup_logging
from ubo_app.logger import setup_logging

setup_logging()

Expand Down
6 changes: 3 additions & 3 deletions ubo_app/error_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def global_exception_handler(
exception_traceback: TracebackType,
) -> None:
_ = exception_type, exception_traceback
from ubo_app.logging import logger
from ubo_app.logger import logger

Check warning on line 52 in ubo_app/error_handlers.py

View check run for this annotation

Codecov / codecov/patch

ubo_app/error_handlers.py#L52

Added line #L52 was not covered by tests

threads_info = get_all_thread_stacks()

Expand All @@ -67,7 +67,7 @@ def global_exception_handler(


def thread_exception_handler(args: threading.ExceptHookArgs) -> None:
from ubo_app.logging import logger
from ubo_app.logger import logger

Check warning on line 70 in ubo_app/error_handlers.py

View check run for this annotation

Codecov / codecov/patch

ubo_app/error_handlers.py#L70

Added line #L70 was not covered by tests

threads_info = get_all_thread_stacks()

Expand Down Expand Up @@ -98,7 +98,7 @@ def loop_exception_handler(
context: dict[str, object],
) -> None:
from ubo_app.constants import DEBUG_MODE_TASKS
from ubo_app.logging import logger
from ubo_app.logger import logger

Check warning on line 101 in ubo_app/error_handlers.py

View check run for this annotation

Codecov / codecov/patch

ubo_app/error_handlers.py#L101

Added line #L101 was not covered by tests

threads_info = get_all_thread_stacks()

Expand Down
4 changes: 2 additions & 2 deletions ubo_app/load_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
SERVICES_PATH,
)
from ubo_app.error_handlers import STACKS, loop_exception_handler
from ubo_app.logging import logger
from ubo_app.logger import logger

if TYPE_CHECKING:
from asyncio.tasks import Task
Expand Down Expand Up @@ -339,7 +339,7 @@ def task_wrapper(stack: str) -> None:
)

async def shutdown(self: UboServiceThread) -> None:
from ubo_app.logging import logger
from ubo_app.logger import logger

logger.debug(
'Stopping service thread',
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions ubo_app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import dotenv

from ubo_app.error_handlers import setup_error_handling
from ubo_app.logging import setup_logging
from ubo_app.logger import setup_logging

Check warning on line 11 in ubo_app/main.py

View check run for this annotation

Codecov / codecov/patch

ubo_app/main.py#L11

Added line #L11 was not covered by tests
from ubo_app.setup import setup
from ubo_app.utils import IS_RPI

Expand Down Expand Up @@ -67,7 +67,7 @@ def main() -> None:
),
)

from ubo_app.logging import logger
from ubo_app.logger import logger

Check warning on line 70 in ubo_app/main.py

View check run for this annotation

Codecov / codecov/patch

ubo_app/main.py#L70

Added line #L70 was not covered by tests
from ubo_app.menu_app.menu import MenuApp

logger.info('----------------------Starting the app----------------------')
Expand Down
2 changes: 1 addition & 1 deletion ubo_app/menu_app/menu_central.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from ubo_gui.menu.stack_item import StackItem, StackMenuItem

from ubo_app.constants import DEBUG_MODE_MENU
from ubo_app.logging import logger
from ubo_app.logger import logger
from ubo_app.menu_app.menu_notification_handler import MenuNotificationHandler
from ubo_app.store.core.types import (
CloseApplicationEvent,
Expand Down
2 changes: 1 addition & 1 deletion ubo_app/rpc/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from grpclib.server import Server

from ubo_app.constants import GRPC_LISTEN_ADDRESS, GRPC_LISTEN_PORT
from ubo_app.logging import logger
from ubo_app.logger import logger
from ubo_app.rpc.service import StoreService


Expand Down
2 changes: 1 addition & 1 deletion ubo_app/rpc/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import betterproto

from ubo_app.logging import logger
from ubo_app.logger import logger
from ubo_app.rpc.generated.store.v1 import (
DispatchActionRequest,
DispatchActionResponse,
Expand Down
2 changes: 1 addition & 1 deletion ubo_app/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def task_wrapper(stack: str) -> None:

async def shutdown(self: WorkerThread) -> None:
from ubo_app.constants import MAIN_LOOP_GRACE_PERIOD
from ubo_app.logging import logger
from ubo_app.logger import logger

logger.info('Stopping worker thread')

Expand Down
2 changes: 1 addition & 1 deletion ubo_app/services/000-audio/audio_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import simpleaudio
from simpleaudio import _simpleaudio # pyright: ignore [reportAttributeAccessIssue]

from ubo_app.logging import logger
from ubo_app.logger import logger
from ubo_app.store.main import store
from ubo_app.store.services.audio import AudioPlaybackDoneAction
from ubo_app.utils.async_ import create_task
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from ubo_gui.page import PageWidget
from wifi_manager import add_wireless_connection

from ubo_app.logging import logger
from ubo_app.logger import logger
from ubo_app.store.core.types import CloseApplicationAction
from ubo_app.store.input.types import InputFieldDescription, InputFieldType, InputMethod
from ubo_app.store.main import store
Expand Down
2 changes: 1 addition & 1 deletion ubo_app/services/030-wifi/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
request_scan,
)

from ubo_app.logging import logger
from ubo_app.logger import logger
from ubo_app.store.core.types import (
RegisterSettingAppAction,
SettingsCategory,
Expand Down
2 changes: 1 addition & 1 deletion ubo_app/services/030-wifi/wifi_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ async def add_wireless_connection(
'auth-alg': ('s', 'open'),
'psk': ('s', password),
}
from ubo_app.logging import logger
from ubo_app.logger import logger

Check warning on line 267 in ubo_app/services/030-wifi/wifi_manager.py

View check run for this annotation

Codecov / codecov/patch

ubo_app/services/030-wifi/wifi_manager.py#L267

Added line #L267 was not covered by tests

properties: NetworkManagerConnectionProperties = {
'connection': {
Expand Down
2 changes: 1 addition & 1 deletion ubo_app/services/040-rgb-ring/rgb_ring_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from typing import TYPE_CHECKING

from ubo_app.logging import logger
from ubo_app.logger import logger
from ubo_app.store.main import store
from ubo_app.store.services.rgb_ring import RgbRingSetIsConnectedAction
from ubo_app.utils.server import send_command
Expand Down
2 changes: 1 addition & 1 deletion ubo_app/services/050-rpi-connect/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from debouncer import DebounceOptions, debounce
from ubo_gui.constants import DANGER_COLOR

from ubo_app.logging import logger
from ubo_app.logger import logger
from ubo_app.store.main import store
from ubo_app.store.services.notifications import (
Chime,
Expand Down
2 changes: 1 addition & 1 deletion ubo_app/services/050-rpi-connect/sign_in_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from ubo_gui.constants import DANGER_COLOR
from ubo_gui.page import PageWidget

from ubo_app.logging import logger
from ubo_app.logger import logger
from ubo_app.store.core.types import CloseApplicationAction
from ubo_app.store.main import store
from ubo_app.store.services.notifications import (
Expand Down
2 changes: 1 addition & 1 deletion ubo_app/services/050-users/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
SubMenuItem,
)

from ubo_app.logging import logger
from ubo_app.logger import logger
from ubo_app.store.core.types import (
RegisterSettingAppAction,
SettingsCategory,
Expand Down
2 changes: 1 addition & 1 deletion ubo_app/services/050-vscode/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from debouncer import DebounceOptions, debounce
from ubo_gui.constants import DANGER_COLOR

from ubo_app.logging import logger
from ubo_app.logger import logger
from ubo_app.store.main import store
from ubo_app.store.services.notifications import (
Chime,
Expand Down
2 changes: 1 addition & 1 deletion ubo_app/services/050-vscode/login_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from ubo_gui.constants import DANGER_COLOR
from ubo_gui.page import PageWidget

from ubo_app.logging import logger
from ubo_app.logger import logger
from ubo_app.store.core.types import CloseApplicationAction
from ubo_app.store.main import store
from ubo_app.store.services.notifications import (
Expand Down
2 changes: 1 addition & 1 deletion ubo_app/services/080-docker/docker_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from docker_images import IMAGES
from redux import AutorunOptions, FinishEvent

from ubo_app.logging import logger
from ubo_app.logger import logger
from ubo_app.store.main import store
from ubo_app.store.services.docker import (
DockerImageSetDockerIdAction,
Expand Down
2 changes: 1 addition & 1 deletion ubo_app/services/080-docker/docker_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from docker_images import IMAGES

from ubo_app.constants import DOCKER_CREDENTIALS_TEMPLATE
from ubo_app.logging import logger
from ubo_app.logger import logger
from ubo_app.store.main import store
from ubo_app.store.services.docker import DockerImageSetStatusAction, DockerItemStatus
from ubo_app.utils import secrets
Expand Down
2 changes: 1 addition & 1 deletion ubo_app/services/080-docker/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from ubo_gui.menu.types import ActionItem, HeadedMenu, Item, SubMenuItem

from ubo_app.constants import DOCKER_CREDENTIALS_TEMPLATE
from ubo_app.logging import logger
from ubo_app.logger import logger
from ubo_app.store.core.types import (
RegisterRegularAppAction,
RegisterSettingAppAction,
Expand Down
2 changes: 1 addition & 1 deletion ubo_app/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def clear_signal_handlers() -> None:
def signal_handler(signum: int, _: object) -> None:
"""Handle the signal."""
from ubo_app import display
from ubo_app.logging import logger
from ubo_app.logger import logger

Check warning on line 155 in ubo_app/setup.py

View check run for this annotation

Codecov / codecov/patch

ubo_app/setup.py#L155

Added line #L155 was not covered by tests

logger.info('Received signal %s, turning off the display...', signum)

Expand Down
5 changes: 5 additions & 0 deletions ubo_app/side_effects.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from redux import FinishAction, FinishEvent

from ubo_app import display
from ubo_app.constants import INSTALLATION_PATH
from ubo_app.store.core.types import (
PowerOffEvent,
RebootEvent,
Expand Down Expand Up @@ -152,3 +153,7 @@ def setup_side_effects() -> None:
store.subscribe_event(ReplayRecordedSequenceEvent, replay_recorded_sequence)

store.dispatch(UpdateManagerSetStatusAction(status=UpdateStatus.CHECKING))

# Create a file signaling that the app is ready
Path(INSTALLATION_PATH).mkdir(parents=True, exist_ok=True)
(Path(INSTALLATION_PATH) / 'app_ready').touch()
2 changes: 1 addition & 1 deletion ubo_app/store/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
)

from ubo_app.constants import DEBUG_MODE, STORE_GRACE_PERIOD
from ubo_app.logging import logger
from ubo_app.logger import logger
from ubo_app.store.core.reducer import reducer as main_reducer
from ubo_app.store.core.types import MainAction, MainEvent
from ubo_app.store.input.reducer import reducer as input_reducer
Expand Down
2 changes: 1 addition & 1 deletion ubo_app/store/update_manager/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
UPDATE_ASSETS_PATH,
UPDATE_LOCK_PATH,
)
from ubo_app.logging import logger
from ubo_app.logger import logger
from ubo_app.store.core.types import RebootAction
from ubo_app.store.dispatch_action import DispatchItem
from ubo_app.store.main import store
Expand Down
2 changes: 1 addition & 1 deletion ubo_app/system/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from typing import Literal, TypedDict

from ubo_app.constants import INSTALLATION_PATH, USERNAME
from ubo_app.logging import logger
from ubo_app.logger import logger

Check warning on line 16 in ubo_app/system/bootstrap.py

View check run for this annotation

Codecov / codecov/patch

ubo_app/system/bootstrap.py#L16

Added line #L16 was not covered by tests

RETRIES = 5

Expand Down
7 changes: 6 additions & 1 deletion ubo_app/system/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,12 @@ set -o errexit
# Define the installation path
INSTALLATION_PATH=${INSTALLATION_PATH:-"/opt/ubo"}

# Create the installation path
# Wait for the app to signal
while [ ! -f "$INSTALLATION_PATH/app_ready" ]; do
sleep 1
done

# Remove the old files and create a fresh virtual environment in the installation path
rm -rf "$INSTALLATION_PATH/env"
virtualenv --system-site-packages "$INSTALLATION_PATH/env"

Expand Down
1 change: 1 addition & 0 deletions ubo_app/system/services/update.service.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ User=root
Environment=INSTALLATION_PATH={{INSTALLATION_PATH}}
Environment=USERNAME={{USERNAME}}
ExecStartPre=/bin/bash -c '[[ -e /opt/ubo/_update/update_is_ready.lock ]]'
ExecStartPre=rm -f {{INSTALLATION_PATH}}/app_ready
ExecStart={{INSTALLATION_PATH}}/_update/install.sh --update
RemainAfterExit=no
Restart=yes
Expand Down
2 changes: 1 addition & 1 deletion ubo_app/system/system_manager/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import time
from pathlib import Path

from ubo_app.logging import get_logger
from ubo_app.logger import get_logger

Check warning on line 8 in ubo_app/system/system_manager/audio.py

View check run for this annotation

Codecov / codecov/patch

ubo_app/system/system_manager/audio.py#L8

Added line #L8 was not covered by tests

DEVICE = '1-001a'
DRIVER_PATH = Path('/sys/bus/i2c/drivers/wm8960')
Expand Down
2 changes: 1 addition & 1 deletion ubo_app/system/system_manager/led.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from adafruit_blinka.microcontroller.generic_micropython import Pin
from fake import Fake

from ubo_app.logging import add_file_handler, add_stdout_handler, get_logger
from ubo_app.logger import add_file_handler, add_stdout_handler, get_logger

Check warning on line 15 in ubo_app/system/system_manager/led.py

View check run for this annotation

Codecov / codecov/patch

ubo_app/system/system_manager/led.py#L15

Added line #L15 was not covered by tests

if Path('/proc/device-tree/model').read_text().startswith('Raspberry Pi 5'):
import sys
Expand Down
2 changes: 1 addition & 1 deletion ubo_app/system/system_manager/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from ubo_app.constants import USERNAME
from ubo_app.error_handlers import setup_error_handling
from ubo_app.logging import add_file_handler, add_stdout_handler, get_logger
from ubo_app.logger import add_file_handler, add_stdout_handler, get_logger

Check warning on line 22 in ubo_app/system/system_manager/main.py

View check run for this annotation

Codecov / codecov/patch

ubo_app/system/system_manager/main.py#L22

Added line #L22 was not covered by tests
from ubo_app.store.services.ethernet import NetState
from ubo_app.system.system_manager.audio import audio_handler
from ubo_app.system.system_manager.docker import docker_handler
Expand Down
2 changes: 1 addition & 1 deletion ubo_app/system/system_manager/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import subprocess

from ubo_app.logging import get_logger
from ubo_app.logger import get_logger

Check warning on line 7 in ubo_app/system/system_manager/package.py

View check run for this annotation

Codecov / codecov/patch

ubo_app/system/system_manager/package.py#L7

Added line #L7 was not covered by tests
from ubo_app.utils.apt import install_package, uninstall_package

PACKAGE_WHITELIST = [
Expand Down
2 changes: 1 addition & 1 deletion ubo_app/system/system_manager/reset_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import subprocess
import time

from ubo_app.logging import get_logger
from ubo_app.logger import get_logger

logger = get_logger('system-manager')

Check warning on line 8 in ubo_app/system/system_manager/reset_button.py

View check run for this annotation

Codecov / codecov/patch

ubo_app/system/system_manager/reset_button.py#L6-L8

Added lines #L6 - L8 were not covered by tests

Expand Down
2 changes: 1 addition & 1 deletion ubo_app/system/system_manager/service_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import subprocess

from ubo_app.logging import get_logger
from ubo_app.logger import get_logger


def service_handler(service: str, command: str) -> str | None:
Expand Down
2 changes: 1 addition & 1 deletion ubo_app/system/system_manager/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import subprocess
from pathlib import Path

from ubo_app.logging import get_logger
from ubo_app.logger import get_logger


def users_handler(command: str, username: str | None = None) -> str | None:
Expand Down
2 changes: 1 addition & 1 deletion ubo_app/utils/apt.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import asyncio
import subprocess

from ubo_app.logging import logger
from ubo_app.logger import logger


def install_package(packages: str | list[str], /, *, force: bool = False) -> None:
Expand Down
Loading

0 comments on commit 97c300e

Please sign in to comment.