changed structure for docker usage
|
Before Width: | Height: | Size: 7.4 KiB After Width: | Height: | Size: 7.4 KiB |
|
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.2 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 78 KiB After Width: | Height: | Size: 78 KiB |
|
Before Width: | Height: | Size: 8.0 KiB After Width: | Height: | Size: 8.0 KiB |
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 28 KiB |
20
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)
|
||||
|
||||
34
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}")
|
||||
|
||||
58
compose.yml
Normal file
@@ -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
|
||||
@@ -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
|
||||
|
||||