Skip to content

Commit

Permalink
fix: send new app status message after uninstall
Browse files Browse the repository at this point in the history
refs #184
  • Loading branch information
fusion44 committed Feb 5, 2023
1 parent e8bb5af commit aff77c8
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions app/apps/impl/raspiblitz.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import asyncio
import json
import logging
import os
import random
from typing import List

from decouple import config
from fastapi import HTTPException, status
from fastapi.encoders import jsonable_encoder
from loguru import logger as logging

from app.api.utils import SSE, broadcast_sse_msg, call_sudo_script, parse_key_value_text
from app.apps.impl.apps_base import AppsBase
Expand Down Expand Up @@ -222,17 +222,17 @@ async def run_bonus_script(self, app_id: str, params: str):

# logging to console
if stdout:
logging.info(f"[stdout]\n{stdout.decode()}")
logging.debug(f"[stdout]\n{stdout.decode()}")
else:
logging.error(f"NO [stdout]")
logging.debug(f"NO [stdout]")
if stderr:
logging.error(f"[stderr]\n{stderr.decode()}")
logging.debug(f"[stderr]\n{stderr.decode()}")
else:
logging.error(f"NO [stderr]")
logging.debug(f"NO [stderr]")

# create log file
logFileName = f"/var/cache/raspiblitz/temp/install.{app_id}.log"
logging.info(f"WRITING LONG FILE: {logFileName}")
logging.info(f"WRITING LOG FILE: {logFileName}")
with open(logFileName, "w", encoding="utf-8") as f:
f.write(f"API triggered script: {cmd}\n")
f.write(f"###### STDOUT #######\n")
Expand All @@ -243,10 +243,10 @@ async def run_bonus_script(self, app_id: str, params: str):
f.write(stderr.decode())

# sending final feedback event
logging.info(f"SENDING RESULT EVENT ...")
logging.debug(f"SENDING RESULT EVENT ...")
if stdout:
stdoutData = parse_key_value_text(stdout.decode())
logging.info(f"PARSED STDOUT DATA: {stdoutData}")
logging.debug(f"PARSED STDOUT DATA: {stdoutData}")
# when there is a defined error message (if multiple it wil lbe the last one)
if "error" in stdoutData:
logging.error(
Expand Down Expand Up @@ -296,7 +296,7 @@ async def run_bonus_script(self, app_id: str, params: str):
# if install was running
elif mode == "on":
if updatedAppData["installed"]:
logging.info(f"WIN - install was effective")
logging.info(f"WIN - install of {app_id} was effective")
await broadcast_sse_msg(
SSE.INSTALL_APP,
{
Expand All @@ -309,9 +309,9 @@ async def run_bonus_script(self, app_id: str, params: str):
},
)
else:
logging.error(f"FAIL - was not installed")
logging.warning(f"DEBUG - updatedAppData: {updatedAppData}")
logging.warning(f"DEBUG - params: {params}")
logging.error(f"FAIL - {app_id} was not installed")
logging.debug(f"updatedAppData: {updatedAppData}")
logging.debug(f"params: {params}")
await broadcast_sse_msg(
SSE.INSTALL_APP,
{
Expand All @@ -321,3 +321,15 @@ async def run_bonus_script(self, app_id: str, params: str):
"details": "install was not effective",
},
)

elif mode == "off":
await broadcast_sse_msg(SSE.INSTALLED_APP_STATUS, [updatedAppData])

if not updatedAppData["installed"]:
logging.info(f"WIN - uninstall of {app_id} was effective")
return

logging.error(f"FAIL - {app_id} was not uninstalled")
logging.debug(f"updatedAppData: {updatedAppData}")
logging.debug(f"params: {params}")
return

0 comments on commit aff77c8

Please sign in to comment.