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