2017-01-16 23:32:28 +01:00
|
|
|
# coding: utf-8
|
|
|
|
|
|
|
|
import os
|
|
|
|
import os.path
|
|
|
|
import codecs
|
|
|
|
|
|
|
|
import json
|
|
|
|
|
|
|
|
#----------------------------------------------------------
|
|
|
|
class Database_cl(object):
|
|
|
|
#----------------------------------------------------------
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
def __init__(self, type_spl):
|
|
|
|
#-------------------------------------------------------
|
|
|
|
self.type_s = type_spl
|
|
|
|
self.path_s = os.path.join('data', type_spl)
|
|
|
|
self.data_o = {}
|
|
|
|
self.readData_p()
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
def create_px(self, data_opl):
|
|
|
|
#-------------------------------------------------------
|
|
|
|
# Überprüfung der Datenn müsste ergänzt werden!
|
|
|
|
id_s = self.nextId_p()
|
2017-01-17 14:23:08 +01:00
|
|
|
data_opl['id'] = id_s
|
2017-01-16 23:32:28 +01:00
|
|
|
# Datei erzeugen
|
|
|
|
file_o = codecs.open(os.path.join(self.path_s , id_s+'.dat'), 'w', 'utf-8')
|
|
|
|
file_o.write(json.dumps(data_opl, indent=3, ensure_ascii=True))
|
|
|
|
file_o.close()
|
|
|
|
|
|
|
|
self.data_o[id_s] = data_opl
|
|
|
|
|
|
|
|
return id_s
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
def read_px(self, id_spl = None):
|
|
|
|
#-------------------------------------------------------
|
|
|
|
# hier zur Vereinfachung:
|
|
|
|
# Aufruf ohne id: alle Einträge liefern
|
|
|
|
data_o = None
|
|
|
|
if id_spl == None:
|
|
|
|
data_o = self.data_o
|
|
|
|
elif id_spl == '0':
|
|
|
|
data_o = self.getDefault_px()
|
|
|
|
else:
|
|
|
|
if id_spl in self.data_o:
|
|
|
|
data_o = self.data_o[id_spl]
|
|
|
|
|
|
|
|
return data_o
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
def update_px(self, id_spl, data_opl):
|
|
|
|
#-------------------------------------------------------
|
|
|
|
# Überprüfung der Daten müsste ergänzt werden!
|
|
|
|
status_b = False
|
|
|
|
if id_spl in self.data_o:
|
|
|
|
# Datei aktualisieren
|
|
|
|
file_o = codecs.open(os.path.join(self.path_s, id_spl+'.dat'), 'w', 'utf-8')
|
|
|
|
file_o.write(json.dumps(data_opl, indent=3, ensure_ascii=True))
|
|
|
|
file_o.close()
|
|
|
|
|
|
|
|
self.data_o[id_spl] = data_opl
|
|
|
|
status_b = True
|
|
|
|
|
|
|
|
return status_b
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
def delete_px(self, id_spl):
|
|
|
|
#-------------------------------------------------------
|
|
|
|
status_b = False
|
|
|
|
if id_spl in self.data_o:
|
|
|
|
# Datei entfernen
|
|
|
|
os.remove(os.path.join(self.path_s, id_spl+'.dat'))
|
|
|
|
|
|
|
|
del self.data_o[id_spl]
|
|
|
|
status_b = True
|
|
|
|
|
|
|
|
return status_b
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
def getDefault_px(self):
|
|
|
|
#-------------------------------------------------------
|
|
|
|
# sollte überschrieben werden!
|
|
|
|
return {}
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
def readData_p(self):
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
files_a = os.listdir(self.path_s)
|
|
|
|
for fileName_s in files_a:
|
|
|
|
if fileName_s.endswith('.dat') and fileName_s != 'maxid.dat':
|
|
|
|
file_o = codecs.open(os.path.join(self.path_s, fileName_s), 'rU', 'utf-8')
|
|
|
|
content_s = file_o.read()
|
|
|
|
file_o.close()
|
|
|
|
id_s = fileName_s[:-4]
|
|
|
|
self.data_o[id_s] = json.loads(content_s)
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
def nextId_p(self):
|
|
|
|
#-------------------------------------------------------
|
|
|
|
file_o = open(os.path.join(self.path_s, 'maxid.dat'), 'r+')
|
|
|
|
maxId_s = file_o.read()
|
|
|
|
maxId_s = str(int(maxId_s)+1)
|
|
|
|
file_o.seek(0)
|
|
|
|
file_o.write(maxId_s)
|
|
|
|
file_o.close()
|
|
|
|
|
|
|
|
return maxId_s
|
|
|
|
|
2017-01-19 17:28:35 +01:00
|
|
|
|
|
|
|
#----------------------------------------------------------
|
|
|
|
class LoadDatabase_cl(Database_cl):
|
|
|
|
#----------------------------------------------------------
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
def __init__(self):
|
|
|
|
#-------------------------------------------------------
|
|
|
|
super().__init__('projekt')
|
|
|
|
super().__init__('komponente')
|
|
|
|
super().__init__('qsmitarbeiter')
|
|
|
|
super().__init__('swentwickler')
|
|
|
|
super().__init__('projekt')
|
|
|
|
super().__init__('fehler')
|
|
|
|
super().__init__('katursache')
|
|
|
|
super().__init__('katfehler')
|
|
|
|
|
2017-01-16 23:32:28 +01:00
|
|
|
#----------------------------------------------------------
|
|
|
|
class ProjektDatabase_cl(Database_cl):
|
|
|
|
#----------------------------------------------------------
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
def __init__(self):
|
|
|
|
#-------------------------------------------------------
|
|
|
|
super().__init__('projekt')
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
def getDefault_px(self):
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
return {
|
|
|
|
'name': '',
|
|
|
|
'id': ''
|
|
|
|
}
|
|
|
|
|
|
|
|
#----------------------------------------------------------
|
|
|
|
class KomponenteDatabase_cl(Database_cl):
|
|
|
|
#----------------------------------------------------------
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
def __init__(self):
|
|
|
|
#-------------------------------------------------------
|
|
|
|
super().__init__('komponente')
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
def getDefault_px(self):
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
return {
|
|
|
|
'name': '',
|
|
|
|
'id': '',
|
2017-01-18 18:14:35 +01:00
|
|
|
'projektid': ''
|
2017-01-16 23:32:28 +01:00
|
|
|
}
|
|
|
|
|
2017-01-19 11:27:12 +01:00
|
|
|
#-------------------------------------------------------
|
|
|
|
def deleteDependencies_px(self, id):
|
|
|
|
#-------------------------------------------------------
|
2017-01-19 17:28:35 +01:00
|
|
|
komponenten = {}
|
2017-01-19 11:27:12 +01:00
|
|
|
for komponente in list(self.data_o):
|
2017-01-19 17:28:35 +01:00
|
|
|
print(komponente)
|
2017-01-19 11:27:12 +01:00
|
|
|
if self.data_o[komponente]['projektid'] == id:
|
|
|
|
self.delete_px(komponente)
|
2017-01-19 17:28:35 +01:00
|
|
|
komponenten[komponente] = komponente
|
|
|
|
return komponenten
|
|
|
|
|
2017-01-19 11:27:12 +01:00
|
|
|
|
2017-01-16 23:32:28 +01:00
|
|
|
#----------------------------------------------------------
|
|
|
|
class QsMitarbeiterDatabase_cl(Database_cl):
|
|
|
|
#----------------------------------------------------------
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
def __init__(self):
|
|
|
|
#-------------------------------------------------------
|
|
|
|
super().__init__('qsmitarbeiter')
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
def getDefault_px(self):
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
return {
|
|
|
|
'name': '',
|
|
|
|
'id': ''
|
|
|
|
}
|
|
|
|
|
|
|
|
#----------------------------------------------------------
|
|
|
|
class SwEntwicklerDatabase_cl(Database_cl):
|
|
|
|
#----------------------------------------------------------
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
def __init__(self):
|
|
|
|
#-------------------------------------------------------
|
|
|
|
super().__init__('swentwickler')
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
def getDefault_px(self):
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
return {
|
|
|
|
'name': '',
|
|
|
|
'id': ''
|
|
|
|
}
|
|
|
|
|
|
|
|
#----------------------------------------------------------
|
|
|
|
class KatfehlerDatabase_cl(Database_cl):
|
|
|
|
#----------------------------------------------------------
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
def __init__(self):
|
|
|
|
#-------------------------------------------------------
|
|
|
|
super().__init__('katfehler')
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
def getDefault_px(self):
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
return {
|
|
|
|
'name': '',
|
|
|
|
'id': ''
|
|
|
|
}
|
|
|
|
|
|
|
|
#----------------------------------------------------------
|
|
|
|
class KatursacheDatabase_cl(Database_cl):
|
|
|
|
#----------------------------------------------------------
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
def __init__(self):
|
|
|
|
#-------------------------------------------------------
|
|
|
|
super().__init__('katursache')
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
def getDefault_px(self):
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
return {
|
|
|
|
'name': '',
|
|
|
|
'id': ''
|
|
|
|
}
|
|
|
|
|
|
|
|
#----------------------------------------------------------
|
|
|
|
class FehlerDatabase_cl(Database_cl):
|
|
|
|
#----------------------------------------------------------
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
def __init__(self):
|
|
|
|
#-------------------------------------------------------
|
|
|
|
super().__init__('fehler')
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
def getDefault_px(self):
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
return {
|
|
|
|
'name': '',
|
|
|
|
'id': '',
|
2017-01-18 18:14:35 +01:00
|
|
|
'komponenteid': '',
|
|
|
|
'katfehlerid': '',
|
|
|
|
'katursacheid': '',
|
|
|
|
'qsmitarbeiterid': '',
|
|
|
|
'swentwicklerid': '',
|
2017-01-19 11:27:12 +01:00
|
|
|
'status': '',
|
|
|
|
'beschreibung': '',
|
|
|
|
'beschreibungursache': '',
|
|
|
|
'zeiterfasst': '',
|
|
|
|
'zeitbehoben': ''
|
2017-01-16 23:32:28 +01:00
|
|
|
}
|
2017-01-18 18:14:35 +01:00
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
def readErkannt_px(self):
|
|
|
|
#-------------------------------------------------------
|
|
|
|
# hier zur Vereinfachung:
|
|
|
|
# Aufruf ohne id: alle Einträge liefern
|
|
|
|
data_o = {}
|
|
|
|
for entry in self.data_o:
|
|
|
|
if self.data_o[entry]['status'] != "geprueft":
|
|
|
|
data_o[entry] = self.data_o[entry]
|
|
|
|
|
|
|
|
return data_o
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
def readBehoben_px(self):
|
|
|
|
#-------------------------------------------------------
|
|
|
|
# hier zur Vereinfachung:
|
|
|
|
# Aufruf ohne id: alle Einträge liefern
|
|
|
|
data_o = {}
|
|
|
|
for entry in self.data_o:
|
|
|
|
if self.data_o[entry]['status'] == "geprueft":
|
|
|
|
data_o[entry] = self.data_o[entry]
|
|
|
|
return data_o
|
2017-01-19 17:28:35 +01:00
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
def deleteDependencies_px(self, id):
|
|
|
|
#-------------------------------------------------------
|
|
|
|
for fehler in list(self.data_o):
|
|
|
|
if self.data_o[fehler]['komponenteid'] == id:
|
|
|
|
self.delete_px(fehler)
|
2017-01-16 23:32:28 +01:00
|
|
|
# EOF
|