Merge branch 'main' of https://git.xkjq.uk/ross/uploader
This commit is contained in:
@@ -8,7 +8,7 @@ from pathlib import Path
|
|||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from local_file_picker import local_file_picker
|
from local_file_picker import local_file_picker
|
||||||
|
|
||||||
from nicegui import ui, app, html, run, Client
|
from nicegui import ui, app, html, run, Client, native
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
@@ -59,6 +59,8 @@ import typer
|
|||||||
# ui.html("<h2>Uploader tool</h2>")
|
# ui.html("<h2>Uploader tool</h2>")
|
||||||
# ui.button('Choose file', on_click=pick_file, icon='folder')
|
# ui.button('Choose file', on_click=pick_file, icon='folder')
|
||||||
|
|
||||||
|
NATIVE = False
|
||||||
|
|
||||||
SOCKET_PATH = 'tcp://localhost:9976'
|
SOCKET_PATH = 'tcp://localhost:9976'
|
||||||
|
|
||||||
WORK_DIR = Path("C:/uploader")
|
WORK_DIR = Path("C:/uploader")
|
||||||
@@ -69,7 +71,7 @@ ANON_PATH = WORK_DIR / Path("anon/")
|
|||||||
|
|
||||||
EXPORT_PATH.mkdir(exist_ok=True, parents=True)
|
EXPORT_PATH.mkdir(exist_ok=True, parents=True)
|
||||||
PROCESS_PATH.mkdir(exist_ok=True, parents=True)
|
PROCESS_PATH.mkdir(exist_ok=True, parents=True)
|
||||||
EXPORT_PATH.mkdir(exist_ok=True, parents=True)
|
ANON_PATH.mkdir(exist_ok=True, parents=True)
|
||||||
|
|
||||||
BASE_SITE_URL = "https://www.penracourses.org.uk"
|
BASE_SITE_URL = "https://www.penracourses.org.uk"
|
||||||
|
|
||||||
@@ -80,9 +82,9 @@ LOGIN_SUCCESS = False
|
|||||||
LOGGED_IN_USER = "None"
|
LOGGED_IN_USER = "None"
|
||||||
|
|
||||||
|
|
||||||
REFRESH_TRIGGERED = False
|
REFRESH_TRIGGERED = True
|
||||||
|
|
||||||
DELETE_FILES_ON_UPLOAD = False
|
DELETE_FILES_ON_UPLOAD = True
|
||||||
|
|
||||||
DEBUG = False
|
DEBUG = False
|
||||||
|
|
||||||
@@ -190,9 +192,17 @@ anonymizer = Anonymizer(ANON_PATH)
|
|||||||
async def upload_files_start(progress, upload_queue):
|
async def upload_files_start(progress, upload_queue):
|
||||||
global uploaded_files, duplicate_series
|
global uploaded_files, duplicate_series
|
||||||
progress.visible = True
|
progress.visible = True
|
||||||
new_uploaded_files, upload_file_list, duplicate_file_list, failed, duplicate_series = await run.cpu_bound(upload_files, upload_queue, rqst)
|
|
||||||
|
results = await run.cpu_bound(upload_files, upload_queue, rqst)
|
||||||
progress.visible = False
|
progress.visible = False
|
||||||
|
|
||||||
|
if results:
|
||||||
|
new_uploaded_files, upload_file_list, duplicate_file_list, failed, duplicate_series = results
|
||||||
|
else:
|
||||||
|
ui.notify("No files to upload", color="negative")
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
uploaded_files.update(new_uploaded_files)
|
uploaded_files.update(new_uploaded_files)
|
||||||
|
|
||||||
ui.notify(f"Uploaded {len(upload_file_list)} files", color='positive')
|
ui.notify(f"Uploaded {len(upload_file_list)} files", color='positive')
|
||||||
@@ -208,6 +218,7 @@ async def upload_files_start(progress, upload_queue):
|
|||||||
uploaded_files_ui.refresh()
|
uploaded_files_ui.refresh()
|
||||||
|
|
||||||
async def load_files_start(progress_bar, queue, custom_path=None):
|
async def load_files_start(progress_bar, queue, custom_path=None):
|
||||||
|
logger.debug("load files start")
|
||||||
global loaded_files, loaded_series, loaded_series_data
|
global loaded_files, loaded_series, loaded_series_data
|
||||||
progress_bar.visible = True
|
progress_bar.visible = True
|
||||||
|
|
||||||
@@ -289,7 +300,7 @@ def load_files(q: Queue, src_path: Path | None = None):
|
|||||||
src_path = EXPORT_PATH
|
src_path = EXPORT_PATH
|
||||||
|
|
||||||
to_process = []
|
to_process = []
|
||||||
for file in src_path.iterdir():
|
for file in src_path.glob("**/*.dcm"):
|
||||||
logger.debug(f"Moving {file} to {PROCESS_PATH}")
|
logger.debug(f"Moving {file} to {PROCESS_PATH}")
|
||||||
|
|
||||||
file_to_process = PROCESS_PATH / file.name
|
file_to_process = PROCESS_PATH / file.name
|
||||||
@@ -324,7 +335,7 @@ def reload_anonymized(q: Queue):
|
|||||||
#processed_files.clear()
|
#processed_files.clear()
|
||||||
|
|
||||||
|
|
||||||
to_process = list(ANON_PATH.glob("*.dcm"))
|
to_process = list(ANON_PATH.glob("**/*.dcm"))
|
||||||
to_process_len = len(to_process)
|
to_process_len = len(to_process)
|
||||||
for n, file in enumerate(to_process):
|
for n, file in enumerate(to_process):
|
||||||
with pydicom.dcmread(file) as dataset:
|
with pydicom.dcmread(file) as dataset:
|
||||||
@@ -368,8 +379,7 @@ def upload_files(q, rqst):
|
|||||||
files_to_upload.append(("files", open(str(file), "rb")))
|
files_to_upload.append(("files", open(str(file), "rb")))
|
||||||
|
|
||||||
if not files_to_upload:
|
if not files_to_upload:
|
||||||
ui.notify('No files to upload', color='negative')
|
return None
|
||||||
return
|
|
||||||
|
|
||||||
# chunck files
|
# chunck files
|
||||||
n = 10
|
n = 10
|
||||||
@@ -623,6 +633,7 @@ def main_page():
|
|||||||
ui.label(f"Anon path: {ANON_PATH}")
|
ui.label(f"Anon path: {ANON_PATH}")
|
||||||
ui.button("Clear anon path", on_click=clear_anonymized_files).tooltip("Delete all files in ANON_PATH")
|
ui.button("Clear anon path", on_click=clear_anonymized_files).tooltip("Delete all files in ANON_PATH")
|
||||||
|
|
||||||
|
ui.button("Shutdown", on_click=app.shutdown)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -655,7 +666,9 @@ def launch_app(work_dir: Path = typer.Option(WORK_DIR, help="Working directory")
|
|||||||
if use_nng:
|
if use_nng:
|
||||||
app.on_startup(read_nng_messages)
|
app.on_startup(read_nng_messages)
|
||||||
|
|
||||||
ui.run(storage_secret="123456", reload=False, show=False)
|
|
||||||
|
|
||||||
|
ui.run(storage_secret="123456", reload=False, show=True, port=native.find_open_port(), native=NATIVE)
|
||||||
|
|
||||||
if __name__ in {"__main__", "__mp_main__"}:
|
if __name__ in {"__main__", "__mp_main__"}:
|
||||||
freeze_support()
|
freeze_support()
|
||||||
|
|||||||
Reference in New Issue
Block a user