Frontend created and rewritten a few times, with some backend fixes #1

Merged
leo merged 110 commits from plaintable into main 2023-11-08 20:38:40 +00:00
Showing only changes of commit 2695fc67f3 - Show all commits

View File

@ -1,10 +1,10 @@
import asyncio
import shutil
import sys
import threading
import time
from pathlib import Path, PurePosixPath
import inotify.adapters
import msgspec
from sanic.log import logging
@ -31,6 +31,7 @@ disk_usage = None
def watcher_thread(loop):
global disk_usage, rootpath
import inotify.adapters
while True:
rootpath = config.config.path
@ -74,6 +75,29 @@ def watcher_thread(loop):
i = None # Free the inotify object
def watcher_thread_poll(loop):
global disk_usage, rootpath
while True:
rootpath = config.config.path
old = format_tree() if tree[""] else None
with tree_lock:
# Initialize the tree from filesystem
tree[""] = walk(rootpath)
print(" ".join(tree[""].dir.keys()))
msg = format_tree()
if msg != old:
asyncio.run_coroutine_threadsafe(broadcast(msg), loop)
# Disk usage update
du = shutil.disk_usage(rootpath)
if du != disk_usage:
disk_usage = du
asyncio.run_coroutine_threadsafe(broadcast(format_du()), loop)
time.sleep(1.0)
def format_du():
return msgspec.json.encode(
{
@ -201,7 +225,10 @@ async def broadcast(msg):
async def start(app, loop):
config.load_config()
app.ctx.watcher = threading.Thread(target=watcher_thread, args=[loop])
app.ctx.watcher = threading.Thread(
target=watcher_thread if sys.platform == "linux" else watcher_thread_poll,
args=[loop],
)
app.ctx.watcher.start()