Switch to systemd-boot, full log sending, and offline install fix
This commit is contained in:
@@ -11,25 +11,12 @@ DISCORD_WEBHOOK_URL = "https://discord.com/api/webhooks/1468696228647932280/L9XS
|
||||
LOG_QUEUE = []
|
||||
FULL_LOG = []
|
||||
QUEUE_LOCK = threading.Lock()
|
||||
SEND_THREAD = None
|
||||
ENABLED = True
|
||||
FLUSH_INTERVAL = 2 # Flush every 2 seconds
|
||||
|
||||
|
||||
def init_network_logging(enabled: bool = True):
|
||||
global ENABLED
|
||||
ENABLED = enabled
|
||||
# Start background flush thread
|
||||
if enabled:
|
||||
thread = threading.Thread(target=_background_flush, daemon=True)
|
||||
thread.start()
|
||||
|
||||
|
||||
def _background_flush():
|
||||
"""Background thread to flush logs periodically"""
|
||||
while True:
|
||||
time.sleep(FLUSH_INTERVAL)
|
||||
flush_logs()
|
||||
|
||||
|
||||
def log_to_discord(level: str, message: str, module: str = "general"):
|
||||
@@ -45,45 +32,12 @@ def log_to_discord(level: str, message: str, module: str = "general"):
|
||||
}
|
||||
|
||||
with QUEUE_LOCK:
|
||||
LOG_QUEUE.append(log_entry)
|
||||
FULL_LOG.append(log_entry)
|
||||
|
||||
# Flush immediately for important events
|
||||
if level.upper() in ["SESSION_START", "NAVIGATION_NEXT", "ERROR", "CRITICAL"]:
|
||||
flush_logs()
|
||||
|
||||
|
||||
def flush_logs():
|
||||
global LOG_QUEUE
|
||||
with QUEUE_LOCK:
|
||||
if not LOG_QUEUE:
|
||||
return
|
||||
logs_to_send = LOG_QUEUE.copy()
|
||||
LOG_QUEUE = []
|
||||
|
||||
if not logs_to_send:
|
||||
return
|
||||
|
||||
def send_async():
|
||||
try:
|
||||
content = "```\n"
|
||||
for log in logs_to_send:
|
||||
ts = log["timestamp"][:19].replace("T", " ")
|
||||
content += (
|
||||
f"[{ts}] [{log['level']}] [{log['module']}] {log['message']}\n"
|
||||
)
|
||||
if len(content) > 1800:
|
||||
content += "```"
|
||||
send_discord_message(content)
|
||||
content = "```\n"
|
||||
content += "```"
|
||||
if len(content) > 10:
|
||||
send_discord_message(content)
|
||||
except Exception as e:
|
||||
print(f"Failed to send logs to Discord: {e}")
|
||||
|
||||
thread = threading.Thread(target=send_async, daemon=True)
|
||||
thread.start()
|
||||
# Deprecated: No partial flushing anymore
|
||||
pass
|
||||
|
||||
|
||||
def send_full_log():
|
||||
@@ -102,7 +56,7 @@ def send_full_log():
|
||||
|
||||
def send_sync():
|
||||
try:
|
||||
send_discord_message("--- FULL SESSION LOG START ---")
|
||||
# send_discord_message("--- FULL SESSION LOG START ---")
|
||||
content = "```\n"
|
||||
for log in logs_to_send:
|
||||
ts = log["timestamp"][:19].replace("T", " ")
|
||||
@@ -117,15 +71,14 @@ def send_full_log():
|
||||
|
||||
content += "```"
|
||||
send_discord_message(content)
|
||||
send_discord_message("--- FULL SESSION LOG END ---")
|
||||
# send_discord_message("--- FULL SESSION LOG END ---")
|
||||
except Exception as e:
|
||||
print(f"Failed to send full log to Discord: {e}")
|
||||
|
||||
# For full log, we can run it in a thread but wait for it if we're exiting?
|
||||
# Usually better to wait a bit or just run it.
|
||||
# For full log, we run it in a thread but wait for it
|
||||
t = threading.Thread(target=send_sync)
|
||||
t.start()
|
||||
t.join(timeout=10)
|
||||
t.join(timeout=30)
|
||||
|
||||
|
||||
def send_discord_message(content: str):
|
||||
|
||||
@@ -120,17 +120,17 @@ def install_minimal_os(mount_root, releasever="43"):
|
||||
|
||||
# Offline installation logic
|
||||
iso_repo = "/run/install/repo"
|
||||
dnf_offline_args = []
|
||||
dnf_args = []
|
||||
|
||||
if os.path.exists(iso_repo):
|
||||
logger.info(f"Found ISO repository at {iso_repo}. Using offline mode.")
|
||||
dnf_offline_args = [
|
||||
logger.info(f"Found ISO repository at {iso_repo}. Using strictly offline mode.")
|
||||
dnf_args = [
|
||||
"--disablerepo=*",
|
||||
f"--repofrompath=iridium-iso,{iso_repo}",
|
||||
"--enablerepo=iridium-iso"
|
||||
]
|
||||
else:
|
||||
logger.warning(f"ISO repository not found at {iso_repo}. Falling back to host configuration.")
|
||||
logger.warning(f"ISO repository not found at {iso_repo}. Trying to use host config (may require network).")
|
||||
|
||||
cmd = [
|
||||
"dnf",
|
||||
@@ -141,7 +141,7 @@ def install_minimal_os(mount_root, releasever="43"):
|
||||
"--use-host-config",
|
||||
"--setopt=install_weak_deps=False",
|
||||
"--nodocs",
|
||||
] + dnf_offline_args + packages
|
||||
] + dnf_args + packages
|
||||
|
||||
with mount_pseudo_fs(mount_root):
|
||||
run_command(cmd)
|
||||
|
||||
Reference in New Issue
Block a user