From 98742107b2ec1fb705c4a0263fe46aa7d4e5edeb Mon Sep 17 00:00:00 2001 From: Marcel Gansfusz Date: Fri, 24 Oct 2025 21:02:42 +0200 Subject: [PATCH] changed structure for docker usage --- {favicon => app/favicon}/apple-touch-icon.png | Bin {favicon => app/favicon}/favicon-96x96.png | Bin {favicon => app/favicon}/favicon.ico | Bin {favicon => app/favicon}/favicon.svg | 0 {favicon => app/favicon}/generated_from.txt | 0 {favicon => app/favicon}/site.webmanifest | 0 .../favicon}/web-app-manifest-192x192.png | Bin .../favicon}/web-app-manifest-512x512.png | Bin index.html => app/index.html | 0 app/init.py | 20 +++++- app/main.py | 34 ++++++---- {static => app/static}/app.js | 0 {static => app/static}/autocomplete.js | 0 {static => app/static}/dynhide.js | 0 {static => app/static}/filedrop.js | 0 {static => app/static}/style.css | 0 compose.yml | 58 ++++++++++++++++++ requirements.txt | 1 + 18 files changed, 99 insertions(+), 14 deletions(-) rename {favicon => app/favicon}/apple-touch-icon.png (100%) rename {favicon => app/favicon}/favicon-96x96.png (100%) rename {favicon => app/favicon}/favicon.ico (100%) rename {favicon => app/favicon}/favicon.svg (100%) rename {favicon => app/favicon}/generated_from.txt (100%) rename {favicon => app/favicon}/site.webmanifest (100%) rename {favicon => app/favicon}/web-app-manifest-192x192.png (100%) rename {favicon => app/favicon}/web-app-manifest-512x512.png (100%) rename index.html => app/index.html (100%) rename {static => app/static}/app.js (100%) rename {static => app/static}/autocomplete.js (100%) rename {static => app/static}/dynhide.js (100%) rename {static => app/static}/filedrop.js (100%) rename {static => app/static}/style.css (100%) create mode 100644 compose.yml diff --git a/favicon/apple-touch-icon.png b/app/favicon/apple-touch-icon.png similarity index 100% rename from favicon/apple-touch-icon.png rename to app/favicon/apple-touch-icon.png diff --git a/favicon/favicon-96x96.png b/app/favicon/favicon-96x96.png similarity index 100% rename from favicon/favicon-96x96.png rename to app/favicon/favicon-96x96.png diff --git a/favicon/favicon.ico b/app/favicon/favicon.ico similarity index 100% rename from favicon/favicon.ico rename to app/favicon/favicon.ico diff --git a/favicon/favicon.svg b/app/favicon/favicon.svg similarity index 100% rename from favicon/favicon.svg rename to app/favicon/favicon.svg diff --git a/favicon/generated_from.txt b/app/favicon/generated_from.txt similarity index 100% rename from favicon/generated_from.txt rename to app/favicon/generated_from.txt diff --git a/favicon/site.webmanifest b/app/favicon/site.webmanifest similarity index 100% rename from favicon/site.webmanifest rename to app/favicon/site.webmanifest diff --git a/favicon/web-app-manifest-192x192.png b/app/favicon/web-app-manifest-192x192.png similarity index 100% rename from favicon/web-app-manifest-192x192.png rename to app/favicon/web-app-manifest-192x192.png diff --git a/favicon/web-app-manifest-512x512.png b/app/favicon/web-app-manifest-512x512.png similarity index 100% rename from favicon/web-app-manifest-512x512.png rename to app/favicon/web-app-manifest-512x512.png diff --git a/index.html b/app/index.html similarity index 100% rename from index.html rename to app/index.html diff --git a/app/init.py b/app/init.py index 3a1feaa..a638b1d 100644 --- a/app/init.py +++ b/app/init.py @@ -2,12 +2,16 @@ from os.path import isdir from stat import S_ISDIR, S_ISREG import re import pathlib +import os # from base64 import decodebytes import json import mariadb import logging +import schedule +import time + CATEGORIES = [ "Prüfungen", "Klausuren", @@ -18,7 +22,7 @@ CATEGORIES = [ "Multimedia", ] SUBCAT_CATEGORIES = ["Klausuren", "Übungen", "Labore"] -unizeug_path = "/home/wildarch/web/fet_unizeug/unizeug/" +unizeug_path = os.environ.get("UNIZEUG_PATH","./unizeug") log = logging.getLogger(__name__) logging.basicConfig( @@ -31,7 +35,11 @@ info = log.info error = log.error db = mariadb.connect( - host="localhost", user="wildserver", password="DBPassword", database="Unizeug" + host=os.environ.get("DB_HOST", "db"), + user=os.environ.get("DB_USER", "user"), + password=os.environ.get("DB_PASSWORD", "DBPASSWORD"), + database=os.environ.get("DB_DATABASE", "unizeug"), + ) c = db.cursor() try: @@ -62,6 +70,10 @@ except mariadb.OperationalError: c.execute( "CREATE TABLE SubCats(id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,LId BIGINT(20),PId BIGINT(20),cat TINYINT UNSIGNED,name VARCHAR(256), PRIMARY KEY(id))" ) +try: + c.execute("CREATE TABLE FIP(id UUID DEFAULT(UUID()), filename VARCHAR(256), filetype VARCHAR(8),initTimeStamp DATETIME, PRIMARY KEY(id))") +except mariadb.OperationalError: + pass db.commit() @@ -161,3 +173,7 @@ def link_prof(firstname, lastname, lid): if __name__ == "__main__": get_dirstruct() + schedule.every.day.at("04:00","Europe/Vienna").do(get_dirstruct) + while True: + schedule.run_pending() + time.sleep(1) diff --git a/app/main.py b/app/main.py index 19ed9ad..e98dbb9 100644 --- a/app/main.py +++ b/app/main.py @@ -25,17 +25,15 @@ import mariadb import filetype -import datetime import logging -import inspect import pathlib from starlette.types import HTTPExceptionHandler log = logging.getLogger(__name__) logging.basicConfig( - filename="app.log", + filename=os.environ.get("APP_LOG_PATH"), level=logging.INFO, format="[%(asctime)s, %(filename)s:%(lineno)s -> %(funcName)10s() ]%(levelname)s: %(message)s", ) @@ -44,7 +42,10 @@ info = log.info error = log.error db = mariadb.connect( - host="localhost", user="wildserver", password="DBPassword", database="Unizeug" + host=os.environ.get("DB_HOST", "db"), + user=os.environ.get("DB_USER", "user"), + password=os.environ.get("DB_PASSWORD", "DBPASSWORD"), + database=os.environ.get("DB_DATABASE", "unizeug"), ) info("App Started") @@ -53,8 +54,16 @@ info("App Started") # startup() app = FastAPI() -app.mount("/favicon", StaticFiles(directory="./favicon"), name="favicon") -app.mount("/static", StaticFiles(directory="./static"), name="static") +app.mount( + "/favicon", + StaticFiles(directory=os.environ.get("FAVICON_PATH", ".app/favicon")), + name="favicon", +) +app.mount( + "/static", + StaticFiles(directory=os.environ.get("STATIC_PATH", "./static")), + name="static", +) CATEGORIES = [ @@ -66,15 +75,16 @@ CATEGORIES = [ "Zusammenfassungen", "Multimedia", ] +APP_ROOT_PATH = os.environ.get("APP_ROOT_PATH", "./app") SUBCAT_CATEGORIES = ["Klausuren", "Übungen", "Labore"] SUBCAT_CATEGORIES_I = [1, 2, 3] EX_DATE_CATEGORIES = ["Prüfungen", "Klausuren"] EX_DATE_CATEGORIES_I = [0, 1] -UNIZEUG_PATH = "./app/dest/" -FILES_IN_PROGRESS = "./app/files/" -EMPTYFILE = "./app/graphics/empty.pdf" -UNSUPPORTEDFILE = "./app/graphics/unsupported.pdf" -GREETINGFILE = "./app/graphics/greeting.pdf" +UNIZEUG_PATH = os.environ.get("UNIZEUG_PATH", "./app/dest") +FILES_IN_PROGRESS = f"{APP_ROOT_PATH}/files/" +EMPTYFILE = f"{APP_ROOT_PATH}/graphics/empty.pdf" +UNSUPPORTEDFILE = f"{APP_ROOT_PATH}/graphics/unsupported.pdf" +GREETINGFILE = f"{APP_ROOT_PATH}/graphics/greeting.pdf" # cur = db.cursor() @@ -151,7 +161,7 @@ def sqlT( @app.get("/") async def get_index(): """gives the Index.html file""" - return FileResponse("./index.html") + return FileResponse(f"{APP_ROOT_PATH}/index.html") @app.get("/files/{file_id}") diff --git a/static/app.js b/app/static/app.js similarity index 100% rename from static/app.js rename to app/static/app.js diff --git a/static/autocomplete.js b/app/static/autocomplete.js similarity index 100% rename from static/autocomplete.js rename to app/static/autocomplete.js diff --git a/static/dynhide.js b/app/static/dynhide.js similarity index 100% rename from static/dynhide.js rename to app/static/dynhide.js diff --git a/static/filedrop.js b/app/static/filedrop.js similarity index 100% rename from static/filedrop.js rename to app/static/filedrop.js diff --git a/static/style.css b/app/static/style.css similarity index 100% rename from static/style.css rename to app/static/style.css diff --git a/compose.yml b/compose.yml new file mode 100644 index 0000000..c2e9f6a --- /dev/null +++ b/compose.yml @@ -0,0 +1,58 @@ +version: "3" +services: + app: + container_name: python-app + command: python -m uvicorn app.main:app --host 0.0.0.0 --port 80 + biuld: + context: . + dockerfile: Dockerfile_app + volumes: + - ./app:/python + - ./unizeug:/unizeug + ports: + - 80:80 + restart: unless-stopped + environment: + APP_LOG_PATH: /python/app.log + APP_ROOT_PATH: /python + UNIZEUG_PATH: /unizeug + DB_HOST: db + DB_USER: app + DB_PASSWORD: DBPassword + DB_DATABASE: Unizeug + TZ: "Europe/Vienna" + + depends_on: + - db + - scaner + db: + container_name: db + image: mariadb + restart: unless-stopped + environment: + MARAIDB_ROOT_PASSWORD: DBPassword + MARIADB_USER: app + MARIADB_PASSWORD: DBPassword + MARIADB_DATABASE: Unizeug + TZ: "Europe/Vienna" + volumes: + - ./mariadb:/var/lib/mysql + scaner: + container_name: python-scaner + command: python /python/init.py + biuld: + context: . + dockerfile: Dockerfile_scaner + volumes: + - ./app:/python + - ./unizeug + restart: unless-stopped + environment: + UNIZEUG_PATH: /unizeug + DB_HOST: db + DB_USER: app + DB_PASSWORD: DBPassword + DB_DATABASE: Unizeug + TZ: "Europe/Vienna" + depends_on: + - db diff --git a/requirements.txt b/requirements.txt index e788402..501bd21 100644 --- a/requirements.txt +++ b/requirements.txt @@ -48,6 +48,7 @@ PyYAML==6.0.2 requests==2.32.3 rich==13.9.4 rich-toolkit==0.13.2 +schedule==1.2.2 shellingham==1.5.4 sniffio==1.3.1 starlette==0.45.3