Pfadkonstruktionen für Multiplattform umgestellt

This commit is contained in:
Alexander Malzkuhn 2025-05-16 10:25:43 +02:00
parent 8fcc2e1b4e
commit 67e68ffa2c

View File

@ -17,9 +17,9 @@ from definitions import userfolder, scriptpath, usersettingsfilename, photofilen
class user:
def __init__(self, name):
self.userfolder = f"{scriptpath}/{userfolder}/{name}"
self.settingsfile = f"{self.userfolder}/{usersettingsfilename}"
self.photofile = f"{self.userfolder}/{photofilename}"
self.userfolder = os.path.join(scriptpath, userfolder, name)
self.settingsfile = os.path.join(self.userfolder, usersettingsfilename)
self.photofile = os.path.join(self.userfolder, photofilename)
# Stammdaten einlesen
try:
@ -43,7 +43,7 @@ class user:
else:
year = str(datetime.datetime.fromtimestamp(time_stamp).year)
month = str(datetime.datetime.fromtimestamp(time_stamp).month)
completepath = f"{self.userfolder}/{year}-{month}"
completepath = os.path.join(self.userfolder, f"{year}-{month}")
return completepath
def timestamp(self, stamptime=-1):
@ -87,7 +87,7 @@ class user:
# Zähle die Zeilen
lines = file.readlines()
except FileNotFoundError:
print(f"Die Datei {self.get_stamp_file()} wurde nicht gefunden.")
print(f"Die Datei {self.get_stamp_file()}.txt wurde nicht gefunden.")
print("Lege die Datei an.")
with open(f'{self.get_stamp_file()}.txt', 'w') as file:
file.write("")
@ -132,10 +132,10 @@ class user:
outputfile.write(json_dict)
pathcheck = self.userfolder
pathcheck = pathcheck.removeprefix(f"{scriptpath}/{userfolder}/")
pathcheck = pathcheck.removeprefix(os.path.join(scriptpath, userfolder))
if pathcheck != self.username:
os.rename(self.userfolder, f"{scriptpath}/{userfolder}/{self.username}")
os.rename(self.userfolder, os.path.join(scriptpath, userfolder, self.username))
def del_user(self):
shutil.rmtree(self.userfolder)
@ -204,7 +204,7 @@ class user:
def get_timestamps(self, year, month):
try:
with open(f"{self.userfolder}/{year}-{month}.txt", "r") as file:
with open(os.path.join(self.userfolder, f"{year}-{month}.txt"), "r") as file:
timestamps = file.readlines()
timestamps.sort()
return timestamps
@ -218,14 +218,14 @@ class user:
def get_archive_status(self, year, month):
try:
with open(f"{self.userfolder}/{year}-{month}.json", 'r') as json_file:
with open(os.path.join(self.userfolder, f"{year}-{month}.json"), 'r') as json_file:
data = json.load(json_file)
return data["archived"]
except:
return -1
def archiving_validity_check(self, year: int, month: int):
timestampfilename = f"{self.userfolder}/{year}-{month}.txt"
timestampfilename = os.path.join(self.userfolder, f"{year}-{month}.txt")
try:
with open(timestampfilename) as timestampfile:
timestamps = timestampfile.readlines()
@ -246,7 +246,7 @@ class user:
def archive_hours(self, year, month, overtime: int):
filename = f"{self.userfolder}/{year}-{month}.json"
filename = os.path.join(self.userfolder, f"{year}-{month}.json")
with open(filename, 'r') as json_file:
data = json.load(json_file)
data["archived"] = 1
@ -258,7 +258,7 @@ class user:
outputfile.write(json_dict)
# Dateien auf readonly setzen
os.chmod(filename, S_IREAD)
filename_txt = f"{self.userfolder}/{year}-{month}.txt"
filename_txt = os.path.join(self.userfolder, f"{year}-{month}.txt")
os.chmod(filename_txt, S_IREAD)
def get_last_months_overtime(self, year, month):
@ -268,7 +268,7 @@ class user:
month = str(12)
else:
month = str(int(month) - 1)
with open(f"{self.userfolder}/{year}-{month}.json", "r") as json_file:
with open(os.path.join(self.userfolder, f"{year}-{month}.json"), "r") as json_file:
json_data = json.load(json_file)
if json_data["archived"] == 1:
@ -281,7 +281,7 @@ class user:
def get_absence(self, year, month):
try:
with open(f"{self.userfolder}/{year}-{month}.json", "r") as json_file:
with open(os.path.join(self.userfolder, f"{int(year)}-{int(month)}.json"), "r") as json_file:
json_data = json.load(json_file)
absence = json_data["absence"]
return absence
@ -290,7 +290,7 @@ class user:
def get_day_notes(self, year, month, day):
try:
with open(f"{self.userfolder}/{int(year)}-{int(month)}.json", "r") as json_file:
with open(os.path.join(self.userfolder, f"{int(year)}-{int(month)}.json"), "r") as json_file:
json_data = json.load(json_file)
day_note = json_data["notes"][str(day)]
return day_note
@ -298,7 +298,7 @@ class user:
return { }
def write_notes(self, year, month, day, note_dict):
with open(f"{self.userfolder}/{int(year)}-{int(month)}.json", "r") as json_file:
with open(os.path.join(self.userfolder, f"{int(year)}-{int(month)}.json"), "r") as json_file:
json_data = json.load(json_file)
if len(note_dict) == 1:
json_data["notes"][str(day)] = { }
@ -309,16 +309,16 @@ class user:
json_data["notes"][str(day)] = note_dict
json_output = json.dumps(json_data, indent=4)
with open(f"{self.userfolder}/{int(year)}-{int(month)}.json", "w") as json_file:
with open(os.path.join(self.userfolder, f"{int(year)}-{int(month)}.json"), "w") as json_file:
json_file.write(json_output)
def update_absence(self, year, month, day, absence_type):
try:
with open(f"{self.userfolder}/{int(year)}-{int(month)}.json", "r") as json_file:
with open(os.path.join(self.userfolder, f"{int(year)}-{int(month)}.json"), "r") as json_file:
json_data = json.load(json_file)
except:
with open(f"{self.userfolder}/{year}-{month}.json", "w") as json_file:
with open(os.path.join(self.userfolder, f"{int(year)}-{int(month)}.json"), "w") as json_file:
json_data = { }
json_data["archived"] = 0
json_data["overtime"] = 0
@ -330,17 +330,17 @@ class user:
json_data.update({ "absence": { str(int(day)): absence_type}})
json_dict = json.dumps(json_data, indent=4)
with open(f"{self.userfolder}/{int(year)}-{int(month)}.json", "w") as json_file:
with open(os.path.join(self.userfolder, f"{int(year)}-{int(month)}.json"), "w") as json_file:
json_file.write(json_dict)
def del_absence(self, year, month, day):
with open(f"{self.userfolder}/{int(year)}-{int(month)}.json", "r") as json_file:
with open(os.path.join(self.userfolder, f"{int(year)}-{int(month)}.json"), "r") as json_file:
json_data = json.load(json_file)
del json_data["absence"][str(day)]
json_dict = json.dumps(json_data, indent=4)
with open(f"{self.userfolder}/{int(year)}-{int(month)}.json", "w") as json_file:
with open(os.path.join(self.userfolder, f"{int(year)}-{int(month)}.json"), "w") as json_file:
json_file.write(json_dict)
def get_day_workhours(self, year, month, day):
@ -482,7 +482,7 @@ def new_user(username: str):
# Admineinstellungen auslesen
def load_adminsettings():
# Settingsdatei einlesen
settings_filename = f"{scriptpath}/{usersettingsfilename}"
settings_filename = os.path.join(scriptpath, usersettingsfilename)
if not os.path.exists(settings_filename):
print("Keine Einstellungsdatei gefunden. Lege Standarddatei an.")
with open(settings_filename, 'w') as json_file: