ensure_packages_installed logging
This commit is contained in:
parent
49f8d46b45
commit
a9d57c18ae
|
@ -1,11 +1,17 @@
|
|||
from lib import logging as logging_lib
|
||||
|
||||
import aiofiles
|
||||
import os
|
||||
from datetime import datetime
|
||||
|
||||
from typing import List
|
||||
from lib import utils
|
||||
import time
|
||||
|
||||
log = logging_lib.log
|
||||
|
||||
LOGGING_ENABLED = True
|
||||
|
||||
async def ensure_packages_installed(
|
||||
packages: List[str] = [],
|
||||
total_timeout: float = 300
|
||||
|
@ -39,6 +45,11 @@ async def ensure_packages_installed(
|
|||
timeout=None if total_timeout == None else 180,
|
||||
env=non_interactive_env
|
||||
)
|
||||
|
||||
if LOGGING_ENABLED:
|
||||
await ensure_packages_installed_log(f"update stdout: {stdout}")
|
||||
await ensure_packages_installed_log(f"update stderr: {stderr}\ncode: {str(return_code)}")
|
||||
|
||||
if return_code != 0:
|
||||
log.error(f"Failed to update package lists: {stderr}")
|
||||
return False
|
||||
|
@ -63,9 +74,24 @@ async def ensure_packages_installed(
|
|||
env=non_interactive_env
|
||||
)
|
||||
|
||||
if LOGGING_ENABLED:
|
||||
await ensure_packages_installed_log(f"install stdout: {stdout}")
|
||||
await ensure_packages_installed_log(f"install stderr: {stderr}\ncode: {str(return_code)}")
|
||||
|
||||
if return_code == 0:
|
||||
log.debug(f"Successfully installed packages: {packages_to_install}")
|
||||
return True
|
||||
else:
|
||||
log.error(f"Failed to install packages: {stderr}")
|
||||
return False
|
||||
|
||||
async def ensure_packages_installed_log(msg):
|
||||
try:
|
||||
log_file_path = "/opt/clore-hosting/ensure-packages-installed-log.txt"
|
||||
os.makedirs(os.path.dirname(log_file_path), exist_ok=True)
|
||||
current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
log_message = f"{current_time} | {msg}\n"
|
||||
async with aiofiles.open(log_file_path, "a") as log_file:
|
||||
await log_file.write(log_message)
|
||||
except Exception as e:
|
||||
pass
|
Loading…
Reference in New Issue