update code, switch to loguru

This commit is contained in:
2025-01-10 09:35:18 +01:00
parent e915b47dda
commit 0d7dc28876
17 changed files with 127 additions and 162 deletions

View File

@@ -0,0 +1 @@
0.2.0

View File

@@ -29,6 +29,4 @@ shortcuts:
advanced_refresh: false advanced_refresh: false
catalogue: true catalogue: true
debug: false debug: false
log_debug: false
ic_logging: false
documentation: true documentation: true

View File

@@ -8,16 +8,21 @@ with open("pyproject.toml", "r") as file:
break break
with open(".version", "r") as file: with open(".version", "r") as file:
version = file.read().strip() version = file.read().strip()
print(f"Name: {name}, Version: {version}")
def rename_folders(): def rename_folders():
for folder in os.listdir("dist"): for folder in os.listdir("dist"):
if folder.endswith(".dist"): if folder.endswith(".dist"):
if "-dev" in folder: if "_dev" in folder:
os.rename(f"dist/{folder}", f"dist/{name}-dev") os.rename(
os.path.join("dist", folder),
os.path.join("dist", f"{name}-{version}-dev"),
)
else: else:
os.rename(f"dist/{folder}", f"dist/{name}-{version}") os.rename(
os.path.join("dist", folder),
os.path.join("dist", f"{name}-{version}"),
)
if __name__ == "__main__": if __name__ == "__main__":
rename_folders() rename_folders()

View File

@@ -1,5 +1,9 @@
import sys import sys
from config import Config from config import Config
from loguru import logger
from datetime import datetime
import atexit
import argparse
__version__ = "0.2.0" __version__ = "0.2.0"
__author__ = "Alexander Kirchner" __author__ = "Alexander Kirchner"
__email__ = "alexander.kirchner@ph-freiburg.de" __email__ = "alexander.kirchner@ph-freiburg.de"
@@ -8,54 +12,60 @@ docport = 6543
config = Config("config/settings.yaml") config = Config("config/settings.yaml")
valid_args = ["--debug", "--log", "--no-backup", "--ic-logging", "--version", "-h","--no-documentation"] _config = config
# Store original values that might be overridden by CLI
args_description = {
"--debug": "Enable debug mode",
"--log": "Enable logging",
"--no-backup": "Disable database backup",
"--ic-logging": "Enable icecream logging (not available in production)",
"--version": "Show version",
"-h": "Show help message and exit",
"--no-documentation": "Disable documentation server and shortcut"
}
args = sys.argv[1:] args = argparse.ArgumentParser()
if any(arg not in valid_args for arg in args): args.add_argument("--debug", help="Debugging mode", action="store_true")
print("Invalid argument present") args.add_argument("--no-backup", help="Disable backups", action="store_true")
print([arg for arg in args if arg not in valid_args]) args.add_argument("--version", help="Print version", action="store_true")
sys.exit() args.add_argument(
"--no-documentation", help="Disable documentation", action="store_true"
)
args = args.parse_args()
def help(): if args.version:
print("Ausleihsystem") print(f"Version: {__version__}")
print("Ein Ausleihsystem für Handbibliotheken") sys.exit(0)
print("Version: {}".format(__version__))
print("Valide Argumente:")
print("args")
print("--------")
print("usage: main.py [-h] [--debug] [--log] [--no-backup] [--ic-logging] [--version] [--no-documentation]")
print("options:")
for arg in valid_args:
print(f"{arg} : {args_description[arg]}")
# based on the arguments, set the config values # Override config values temporarily without saving
if"-h" in args: changes_made = False
help()
sys.exit() if args.debug:
if "--debug" in args:
config.debug = True config.debug = True
if "--log" in args: changes_made = True
config.log_debug = True if args.no_backup:
if "--no-backup" in args: config.database.do_backup = False
config.no_backup = True changes_made = True
if "--ic-logging" in args: if args.no_documentation:
config.ic_logging = True
if "--no-documentation" in args:
config.documentation = False config.documentation = False
if "--version" in args: changes_made = True
print(__version__)
sys.exit() if changes_made:
config.save()
def restore_config():
global _config
config._config = _config
config.save()
log.info("Restored configuration")
atexit.register(restore_config)
log = logger
log.remove()
log.add("logs/application.log", rotation="1 week", compression="zip")
# add a log for the current day
log.add(
f"logs/{datetime.now().strftime('%Y-%m-%d')}.log",
rotation="1 day",
compression="zip",
)
print(config.debug)
if config.debug:
import sys
log.add(
sys.stderr,
)

View File

@@ -1,12 +1,10 @@
import requests import requests
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
from src import config from src import config, log
from src.schemas import Book from src.schemas import Book
from src.utils import Log
URL = "https://rds.ibs-bw.de/phfreiburg/opac/RDSIndex/Search?type0%5B%5D=allfields&lookfor0%5B%5D=&join=AND&bool0%5B%5D=AND&type0%5B%5D=au&lookfor0%5B%5D=&join=AND&bool0%5B%5D=AND&type0%5B%5D=ti&lookfor0%5B%5D=&join=AND&bool0%5B%5D=AND&type0%5B%5D=ct&lookfor0%5B%5D=&join=AND&bool0%5B%5D=AND&type0%5B%5D=isn&lookfor0%5B%5D=&join=AND&bool0%5B%5D=AND&type0%5B%5D=ta&lookfor0%5B%5D=&join=AND&bool0%5B%5D=AND&type0%5B%5D=co&lookfor0%5B%5D=&join=AND&bool0%5B%5D=AND&type0%5B%5D=py&lookfor0%5B%5D=&join=AND&bool0%5B%5D=AND&type0%5B%5D=pp&lookfor0%5B%5D=&join=AND&bool0%5B%5D=AND&type0%5B%5D=pu&lookfor0%5B%5D=&join=AND&bool0%5B%5D=AND&type0%5B%5D=si&lookfor0%5B%5D={}&join=AND&bool0%5B%5D=AND&type0%5B%5D=zr&lookfor0%5B%5D=&join=AND&bool0%5B%5D=AND&type0%5B%5D=cc&lookfor0%5B%5D=&join=AND&bool0%5B%5D=AND" URL = "https://rds.ibs-bw.de/phfreiburg/opac/RDSIndex/Search?type0%5B%5D=allfields&lookfor0%5B%5D=&join=AND&bool0%5B%5D=AND&type0%5B%5D=au&lookfor0%5B%5D=&join=AND&bool0%5B%5D=AND&type0%5B%5D=ti&lookfor0%5B%5D=&join=AND&bool0%5B%5D=AND&type0%5B%5D=ct&lookfor0%5B%5D=&join=AND&bool0%5B%5D=AND&type0%5B%5D=isn&lookfor0%5B%5D=&join=AND&bool0%5B%5D=AND&type0%5B%5D=ta&lookfor0%5B%5D=&join=AND&bool0%5B%5D=AND&type0%5B%5D=co&lookfor0%5B%5D=&join=AND&bool0%5B%5D=AND&type0%5B%5D=py&lookfor0%5B%5D=&join=AND&bool0%5B%5D=AND&type0%5B%5D=pp&lookfor0%5B%5D=&join=AND&bool0%5B%5D=AND&type0%5B%5D=pu&lookfor0%5B%5D=&join=AND&bool0%5B%5D=AND&type0%5B%5D=si&lookfor0%5B%5D={}&join=AND&bool0%5B%5D=AND&type0%5B%5D=zr&lookfor0%5B%5D=&join=AND&bool0%5B%5D=AND&type0%5B%5D=cc&lookfor0%5B%5D=&join=AND&bool0%5B%5D=AND"
BASE = "https://rds.ibs-bw.de" BASE = "https://rds.ibs-bw.de"
log = Log("Catalogue")
class Catalogue: class Catalogue:
def __init__(self, timeout=5): def __init__(self, timeout=5):

View File

@@ -1,12 +1,11 @@
import sqlite3 as sql import sqlite3 as sql
import os import os
import shutil import shutil
from src import config from src import config, log
from src.schemas import USERS, MEDIA, LOANS, User, Book, Loan from src.schemas import USERS, MEDIA, LOANS, User, Book, Loan
from src.utils import stringToDate, Log, debugMessage as dbg from src.utils import stringToDate
from PyQt6 import QtCore from PyQt6 import QtCore
log = Log("Database")
FILE = config.database.name FILE = config.database.name
class Database: class Database:
def __init__(self, db_path: str = None): def __init__(self, db_path: str = None):
@@ -25,12 +24,12 @@ class Database:
try: try:
os.makedirs(config.database.path) os.makedirs(config.database.path)
except FileNotFoundError: except FileNotFoundError:
dbg(self.db_path) log.error(f"Path {config.database.path} not found")
if not os.path.exists(config.database.backupLocation): if not os.path.exists(config.database.backupLocation):
os.makedirs(config.database.backupLocation) os.makedirs(config.database.backupLocation)
#if main path does not exist, try to create it. if that fails, use the backuplocation #if main path does not exist, try to create it. if that fails, use the backuplocation
dbg(self.db_path) log.debug("Checking Database Path", self.db_path)
self.checkDatabaseStatus() self.checkDatabaseStatus()
def handle_folder_reachability(self, original_path, backup_path): def handle_folder_reachability(self, original_path, backup_path):
@@ -59,7 +58,7 @@ class Database:
return backup_path +"/" + FILE return backup_path +"/" + FILE
else: else:
dbg("Original Path Exists, using this path") log.info("Original Path Exists, using this path")
# Original folder is reachable, check for backup # Original folder is reachable, check for backup
if os.path.exists(backup_file): if os.path.exists(backup_file):
# Restore backup # Restore backup

4
src/logic/k10plus.py Normal file
View File

@@ -0,0 +1,4 @@
import requests
URL = "https://sru.k10plus.de/opac-de-627!rec=1?version=1.1&operation=searchRetrieve&query="

View File

@@ -1,8 +1,9 @@
from src import log
from .sources.Ui_dialog_createUser import Ui_Dialog from .sources.Ui_dialog_createUser import Ui_Dialog
from PyQt6 import QtCore, QtGui, QtWidgets from PyQt6 import QtCore, QtGui, QtWidgets
from PyQt6.QtGui import QRegularExpressionValidator from PyQt6.QtGui import QRegularExpressionValidator
from src.logic import Database from src.logic import Database
from src.utils import Icon, Log from src.utils import Icon
class CreateUser(QtWidgets.QDialog, Ui_Dialog): class CreateUser(QtWidgets.QDialog, Ui_Dialog):
def __init__(self, fieldname, data): def __init__(self, fieldname, data):
@@ -38,6 +39,7 @@ class CreateUser(QtWidgets.QDialog, Ui_Dialog):
self.userno.textChanged.connect( self.userno.textChanged.connect(
lambda: self.validateInputUserno(self.userno.text(), "int") lambda: self.validateInputUserno(self.userno.text(), "int")
) )
log.info("User creation dialog opened")
def checkFields(self): def checkFields(self):
if ( if (
self.username.hasAcceptableInput() self.username.hasAcceptableInput()
@@ -58,7 +60,11 @@ class CreateUser(QtWidgets.QDialog, Ui_Dialog):
usermail = self.user_mail.text() usermail = self.user_mail.text()
if self.db.insertUser(username, userno, usermail): if self.db.insertUser(username, userno, usermail):
self.userid = userno self.userid = userno
log.info(f"User {username} created")
else: else:
log.error(
f"User {username} could not be created, input was: {username}, {userno}, {usermail}"
)
self.setStatusTipMessage( self.setStatusTipMessage(
"Benutzer konnte nicht erstellt werden, bitte überprüfen Sie die Eingaben" "Benutzer konnte nicht erstellt werden, bitte überprüfen Sie die Eingaben"
) )

View File

@@ -1,9 +1,9 @@
from .sources.Ui_main_Loans import Ui_MainWindow from .sources.Ui_main_Loans import Ui_MainWindow
from PyQt6 import QtCore, QtGui, QtWidgets from PyQt6 import QtCore, QtGui, QtWidgets
from src import log
from .user import UserUI from .user import UserUI
from src.logic import Database from src.logic import Database
from src.utils import stringToDate, Icon from src.utils import stringToDate, Icon
from src.utils import debugMessage as dbg
from icecream import ic from icecream import ic
TABLETOFIELDTRANSLATE = { TABLETOFIELDTRANSLATE = {
@@ -23,8 +23,7 @@ class LoanWindow(QtWidgets.QMainWindow, Ui_MainWindow):
QtWidgets.QHeaderView.ResizeMode.Stretch QtWidgets.QHeaderView.ResizeMode.Stretch
) )
self.db = Database() self.db = Database()
self.loans = [] self.loans = self.loadLoans()
self.loadLoans()
# lineedits # lineedits
self.searchbar.textChanged.connect(self.limitResults) self.searchbar.textChanged.connect(self.limitResults)
@@ -37,6 +36,7 @@ class LoanWindow(QtWidgets.QMainWindow, Ui_MainWindow):
# table # table
self.loanTable.doubleClicked.connect(self.showUser) self.loanTable.doubleClicked.connect(self.showUser)
log.info("Loan history window opened")
self.show() self.show()
def selfpass(self): def selfpass(self):
@@ -44,7 +44,7 @@ class LoanWindow(QtWidgets.QMainWindow, Ui_MainWindow):
def insertRow(self, data): def insertRow(self, data):
dbg(contents=data) log.debug(f"Inserting row: {data}")
retdate = "" retdate = ""
if data.returned_date != "": if data.returned_date != "":
@@ -77,9 +77,10 @@ class LoanWindow(QtWidgets.QMainWindow, Ui_MainWindow):
def loadLoans(self): def loadLoans(self):
loans = self.db.getAllLoans() loans = self.db.getAllLoans()
loanlist = []
for loan in loans: for loan in loans:
self.insertRow(loan) self.insertRow(loan)
self.loans = loans return loanlist
def filterResults(self): def filterResults(self):
mode = ( mode = (
@@ -112,7 +113,7 @@ class LoanWindow(QtWidgets.QMainWindow, Ui_MainWindow):
limiter = str(limiter) limiter = str(limiter)
searchfield = self.searchFields.currentText() searchfield = self.searchFields.currentText()
searchfield = TABLETOFIELDTRANSLATE[searchfield] searchfield = TABLETOFIELDTRANSLATE[searchfield]
dbg(limiter=limiter, search=searchfield) log.debug(f"Searching for: {limiter} in {searchfield}")
self.loanTable.setRowCount(0) self.loanTable.setRowCount(0)
for loan in self.loans: for loan in self.loans:
fielddata = eval(f"loan.{searchfield}") fielddata = eval(f"loan.{searchfield}")

View File

@@ -2,10 +2,9 @@ import sys
import atexit import atexit
import datetime import datetime
import webbrowser import webbrowser
from src import config, __email__, docport from src import config, __email__, docport, log
from src.logic import Database, Catalogue, Backup from src.logic import Database, Catalogue, Backup
from src.utils import stringToDate, Icon, Log from src.utils import stringToDate, Icon
from src.utils import debugMessage as dbg
from src.utils.createReport import generate_report from src.utils.createReport import generate_report
from src.schemas import Book from src.schemas import Book
from .sources.Ui_main_UserInterface import Ui_MainWindow from .sources.Ui_main_UserInterface import Ui_MainWindow
@@ -22,8 +21,6 @@ from omegaconf import OmegaConf
from src.logic.documentation_thread import DocumentationThread from src.logic.documentation_thread import DocumentationThread
backup = Backup() backup = Backup()
cat = Catalogue() cat = Catalogue()
log = Log("main")
dbg(backup=config.database.do_backup, catalogue=config.catalogue)
def getShortcut(shortcuts, name): def getShortcut(shortcuts, name):
shortcut = [cut for cut in shortcuts if cut["name"] == name][0] shortcut = [cut for cut in shortcuts if cut["name"] == name][0]
@@ -183,7 +180,7 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
def restart(self): def restart(self):
#log restart #log restart
dbg("Restarting Program") log.info("Restarting Program")
import os import os
python_executable = sys.executable python_executable = sys.executable
args = sys.argv[:] args = sys.argv[:]
@@ -192,8 +189,7 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
def changeMode(self): def changeMode(self):
log.info("Changing Mode") log.info("Changing Mode, current mode is {}", self.activeState)
dbg(f"Current mode: {self.activeState}")
self.input_username.clear() self.input_username.clear()
stayReturn = False stayReturn = False
if config.advanced_refresh and self.userdata.toPlainText() != "": if config.advanced_refresh and self.userdata.toPlainText() != "":
@@ -216,7 +212,7 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
self.activateReturnMode() self.activateReturnMode()
def activateLoanMode(self): def activateLoanMode(self):
dbg("Activating Loan Mode") log.info("Activating Loan Mode")
self.input_username.setEnabled(True) self.input_username.setEnabled(True)
self.input_userno.setEnabled(True) self.input_userno.setEnabled(True)
self.duedate.setEnabled(True) self.duedate.setEnabled(True)
@@ -234,7 +230,7 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
self.input_file_ident.setEnabled(True) self.input_file_ident.setEnabled(True)
def activateReturnMode(self): def activateReturnMode(self):
dbg("Activating Return Mode") log.info("Activating Return Mode")
self.input_username.setEnabled(False) self.input_username.setEnabled(False)
self.input_userno.setEnabled(False) self.input_userno.setEnabled(False)
# set mode background color to orange # set mode background color to orange
@@ -326,7 +322,7 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
self.mode.setText("Ausleihe") self.mode.setText("Ausleihe")
#print(self.activeUser.__dict__) #print(self.activeUser.__dict__)
loans = self.db.getActiveLoans(self.activeUser.id) loans = self.db.getActiveLoans(self.activeUser.id)
dbg(loans=loans) log.debug("Active Loans", loans)
self.btn_show_lentmedia.setText(loans) self.btn_show_lentmedia.setText(loans)
retdate = self.db.selectClosestReturnDate(self.activeUser.id) retdate = self.db.selectClosestReturnDate(self.activeUser.id)
if retdate: if retdate:
@@ -375,16 +371,16 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
self.mediaAdd(value) self.mediaAdd(value)
self.input_file_ident.setFocus() self.input_file_ident.setFocus()
def mediaAdd(self, identifier): def mediaAdd(self, identifier):
dbg("Adding Media", identifier = identifier) log.info("Adding Media", identifier=identifier)
self.input_file_ident.clear() self.input_file_ident.clear()
self.input_file_ident.setEnabled(False) self.input_file_ident.setEnabled(False)
user_id = self.activeUser.id user_id = self.activeUser.id
media = Book(signature=identifier) media = Book(signature=identifier)
book_id = self.db.checkMediaExists(media) book_id = self.db.checkMediaExists(media)
dbg(f"Book ID: {book_id}, User ID: {user_id}", media=media) log.debug(f"Book ID: {book_id}, User ID: {user_id}", media=media)
if not book_id: if not book_id:
dbg("Book not found, searching catalogue") log.info("Book not found, searching catalogue")
if config.catalogue == True: if config.catalogue == True:
media = cat.get_book(identifier) media = cat.get_book(identifier)
if not media: if not media:
@@ -441,7 +437,7 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
for entry in newentries: for entry in newentries:
book = self.db.getMedia(entry) book = self.db.getMedia(entry)
self.loanMedia(user_id, [entry], book) self.loanMedia(user_id, [entry], book)
dbg("inserted duplicated book into database") log.info("inserted duplicated book into database")
return return
else: else:
#print("Book not loaned, loaning now") #print("Book not loaned, loaning now")
@@ -506,7 +502,7 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
self.setStatusTipMessage("Buch nicht entliehen") self.setStatusTipMessage("Buch nicht entliehen")
self.input_file_ident.clear() self.input_file_ident.clear()
else: else:
dbg("Book not found") log.error("Book not found, identifier", identifier)
#print("Book not found") #print("Book not found")
#self.input_file_ident.setPlaceholderText(f"Buch {identifier} nicht gefunden") #self.input_file_ident.setPlaceholderText(f"Buch {identifier} nicht gefunden")
@@ -520,13 +516,13 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
dialog.setText(message) dialog.setText(message)
dialog.exec() dialog.exec()
def exit_handler(): def exit_handler():
dbg("Exiting, creating backup") log.info("Exiting, creating backup")
app = QtWidgets.QApplication(sys.argv) app = QtWidgets.QApplication(sys.argv)
#print(backup.backup) #print(backup.backup)
# generate report if monday # generate report if monday
if datetime.datetime.now().weekday() == config.report.report_day: if datetime.datetime.now().weekday() == config.report.report_day:
generate_report() generate_report()
dbg("Generated Report") log.info("Generated Report")
Database().renameInactiveUsers() Database().renameInactiveUsers()
if config.database.do_backup: if config.database.do_backup:
state = backup.createBackup() state = backup.createBackup()
@@ -541,7 +537,7 @@ def exit_handler():
dialog.setText("Backup konnte nicht erstellt werden") dialog.setText("Backup konnte nicht erstellt werden")
dialog.exec() dialog.exec()
dbg("Exiting", backupstate=state) log.info("Exiting, backup:", state)
else: else:
dialog = QtWidgets.QMessageBox() dialog = QtWidgets.QMessageBox()
# set icon # set icon

View File

@@ -1,8 +1,7 @@
from .sources.Ui_dialog_settings import Ui_Dialog from .sources.Ui_dialog_settings import Ui_Dialog
from PyQt6 import QtWidgets, QtCore from PyQt6 import QtWidgets, QtCore
from src import config, log
from src.utils import Icon from src.utils import Icon
from src import config
from src.utils import debugMessage as dbg
from omegaconf import OmegaConf from omegaconf import OmegaConf
import os import os
@@ -192,7 +191,7 @@ class Settings(QtWidgets.QDialog, Ui_Dialog):
if changed == original: if changed == original:
self.settingschanged = False self.settingschanged = False
self.restart_required = False self.restart_required = False
dbg("Settings not changed") log.info("Settings not changed")
else: else:
self.settingschanged = True self.settingschanged = True
#compare if database or shortcuts were changed #compare if database or shortcuts were changed
@@ -200,7 +199,11 @@ class Settings(QtWidgets.QDialog, Ui_Dialog):
shortcuts = self.shortcuts == self.sortShortcuts(changed.shortcuts) shortcuts = self.shortcuts == self.sortShortcuts(changed.shortcuts)
if not database or not shortcuts: if not database or not shortcuts:
self.restart_required = True self.restart_required = True
dbg(f"Settings changed, restart required: {self.restart_required}",database=database,shortcuts=shortcuts) log.info(
f"Settings changed, restart required: {self.restart_required}",
database=database,
shortcuts=shortcuts,
)
# save the new settings # save the new settings
if self.settingschanged: if self.settingschanged:

View File

@@ -1,10 +1,10 @@
from .sources.Ui_main_userData import Ui_MainWindow from .sources.Ui_main_userData import Ui_MainWindow
from PyQt6 import QtCore, QtGui, QtWidgets from PyQt6 import QtCore, QtGui, QtWidgets
from src import log
from src.logic import Database from src.logic import Database
from src.schemas import User from src.schemas import User
from .extendLoan import ExtendLoan from .extendLoan import ExtendLoan
from src.utils import stringToDate, Icon from src.utils import stringToDate, Icon
from src.utils import debugMessage as dbg
TABLETOFIELDTRANSLATE = { TABLETOFIELDTRANSLATE = {
"Titel": "title", "Titel": "title",
@@ -95,7 +95,6 @@ class UserUI(QtWidgets.QMainWindow, Ui_MainWindow):
limiter = self.searchbox.text().lower() limiter = self.searchbox.text().lower()
searchfield = self.searchfilter.currentText() searchfield = self.searchfilter.currentText()
searchfield = TABLETOFIELDTRANSLATE[searchfield] searchfield = TABLETOFIELDTRANSLATE[searchfield]
# dbg(limiter=limiter, search=searchfield)
self.UserMediaTable.setRowCount(0) self.UserMediaTable.setRowCount(0)
for loan in self.userMedia: for loan in self.userMedia:
@@ -166,7 +165,7 @@ class UserUI(QtWidgets.QMainWindow, Ui_MainWindow):
continue continue
elif mode == "overdue": elif mode == "overdue":
# book not returned and todays date is greater than todate # book not returned and todays date is greater than todate
dbg(book=book) log.debug("Book: {}".format(book))
if book.returned_date is not None: if book.returned_date is not None:
continue continue
# if todate is greater than current date, continue # if todate is greater than current date, continue

View File

@@ -1,5 +1,3 @@
from .log import Log
from .icon import Icon from .icon import Icon
from .debug import debugMessage
from .stringtodate import stringToDate from .stringtodate import stringToDate
from .documentation import launch_documentation from .documentation import launch_documentation

View File

@@ -1,18 +0,0 @@
from src import config
from icecream import ic
from src.utils import Log
log = Log("debugMessage")
def debugMessage(*args, **kwargs):
startmessage = "Logging debug message"
# join args and kwargs to a string
message = " ".join(args)
for key, value in kwargs.items():
message += f" {key}: {value}"
if config.debug:
if config.log_debug:
log.info(f"{startmessage}: {message}")
if config.ic_logging == True:
ic(message)
else: print(message)
return message

View File

@@ -1,7 +1,8 @@
from pyramid.config import Configurator from pyramid.config import Configurator
from wsgiref.simple_server import make_server from wsgiref.simple_server import make_server
from src import docport from src import docport, log
import os import os
import sys
def website(): def website():
config = Configurator() config = Configurator()
@@ -14,8 +15,17 @@ def website():
def launch_documentation(): def launch_documentation():
app = website() app = website()
server = make_server('localhost', 6543, app) server = make_server('localhost', 6543, app)
print("Serving MkDocs documentation on http://0.0.0.0:{}".format(docport)) log.info("Serving MkDocs documentation on http://0.0.0.0:{}".format(docport))
with open(os.devnull, "w") as devnull:
old_stdout = sys.stdout
old_stderr = sys.stderr
sys.stdout = devnull
sys.stderr = devnull
try:
server.serve_forever() server.serve_forever()
finally:
sys.stdout = old_stdout
sys.stderr = old_stderr
if __name__ == '__main__': if __name__ == '__main__':
pass pass

View File

@@ -1,26 +0,0 @@
import logging
class Log:
def __init__(self, name):
self.logger = logging.getLogger(name)
self.logger.setLevel(logging.DEBUG)
self.formatter = logging.Formatter(
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
)
self.file_handler = logging.FileHandler("log.log")
self.file_handler.setLevel(logging.DEBUG)
self.file_handler.setFormatter(self.formatter)
self.logger.addHandler(self.file_handler)
def info(self, message):
self.logger.info(message)
def debug(self, message):
self.logger.debug(message)
def error(self, message):
self.logger.error(message)
def warning(self, message):
self.logger.warning(message)

View File

@@ -1,6 +1,6 @@
# import qdate # import qdate
from PyQt6 import QtCore from PyQt6 import QtCore
from .debug import debugMessage from src import log
def stringToDate(date: str) -> QtCore.QDate: def stringToDate(date: str) -> QtCore.QDate:
"""Takes an input string and returns a QDate object. """Takes an input string and returns a QDate object.
@@ -10,7 +10,7 @@ def stringToDate(date: str) -> QtCore.QDate:
Returns: Returns:
QtCore.QDate: the QDate object in string format DD.MM.yyyy QtCore.QDate: the QDate object in string format DD.MM.yyyy
""" """
debugMessage(date=date) log.debug(f"stringToDate: {date}")
if not date: if not date:
return "" return ""
if isinstance(date, QtCore.QDate): if isinstance(date, QtCore.QDate):
@@ -21,22 +21,3 @@ def stringToDate(date: str) -> QtCore.QDate:
month = datedata[1] month = datedata[1]
year = datedata[0] year = datedata[0]
return QtCore.QDate(int(year), int(month), int(day)) return QtCore.QDate(int(year), int(month), int(day))
# else:
# datedata = date.split(" ")[1:]
# month = datedata[0]
# day = datedata[1]
# year = datedata[2]
# month = month.replace("Jan", "01")
# month = month.replace("Feb", "02")
# month = month.replace("Mar", "03")
# month = month.replace("Apr", "04")
# month = month.replace("May", "05")
# month = month.replace("Jun", "06")
# month = month.replace("Jul", "07")
# month = month.replace("Aug", "08")
# month = month.replace("Sep", "09")
# month = month.replace("Oct", "10")
# month = month.replace("Nov", "11")
# month = month.replace("Dec", "12")
# return QtCore.QDate(int(year), int(month), int(day)).toString("dd.MM.yyyy")