360 lines
14 KiB
Python
Executable File
360 lines
14 KiB
Python
Executable File
from PyQt5.QtWidgets import QApplication, QDialog, QFileDialog
|
|
from PyQt5.uic import loadUi
|
|
import sys
|
|
from pathlib import Path
|
|
import pandas as pd
|
|
from icecream import ic
|
|
import numpy as np
|
|
class MainUI(QDialog): # erbt von QDialog
|
|
def __init__(self):
|
|
#super (MainUI, self).__init__() #Aufrufen des Konstruktors von QDialog
|
|
super().__init__()
|
|
loadUi ("Aufbaumaster2CSV.ui", self)
|
|
self.filename = None
|
|
self.path = None
|
|
self.df_vte = None
|
|
self.df_cmdb = None
|
|
self.dfb = None
|
|
self.openBtn.clicked.connect(self.open_file_dialog)
|
|
self.saveBtn.clicked.connect(self.save_file_dialog)
|
|
self.filter = "Hostnamen"
|
|
self.group = None
|
|
self.typ = None
|
|
|
|
def changegroup(self):
|
|
self.group = self.gruppierung.currentText()
|
|
# ic("Gruppen: ", self.group)
|
|
|
|
def changegtyp(self):
|
|
self.typ = self.geraetetyp.currentText()
|
|
# ic("Typ: ", self.typ)
|
|
|
|
def open_file_dialog(self):
|
|
self.filename, _ = QFileDialog.getOpenFileName(
|
|
self,
|
|
"Aufbaumaster",
|
|
"\\Volumes\\Daten01\\Documents\\toCSV",
|
|
"Images (*.xls *.xlsx *.xlsb)"
|
|
)
|
|
# self.filename_edit.setPixmap(QPixmap(self.filename))
|
|
self.lblCMDBPath.setText(self.filename)
|
|
|
|
if self.filename:
|
|
self.path = Path(self.filename)
|
|
|
|
#self.changetable()
|
|
self.collectdata()
|
|
|
|
def onClicked(self):
|
|
pass
|
|
|
|
|
|
def collectdata(self):
|
|
|
|
# Einlesen der Sheets
|
|
self.df_vte = pd.read_excel(self.filename,header=7,na_filter=False,sheet_name="VTE-Input",engine='pyxlsb',usecols=['Hostname','Gruppierung','CONFIG-ID','CMDB Status'])
|
|
#print(self.df_vte.head)
|
|
self.df_cmdb = pd.read_excel(self.filename,header=2,sheet_name="CMDB", engine='pyxlsb')
|
|
#self.df_sw_asset = pd.read_excel(self.filename,sheet_name="SW-Asset", engine='pyxlsb')
|
|
|
|
|
|
# Nach relevanten Spalten filtern
|
|
self.df_vte = self.df_vte[self.df_vte['Gruppierung']=='Grundgerät']
|
|
#self.df_vte = self.df_vte.drop(columns=['RAM','Bestelldatum','Hersteller','Lieferant','SAP-Nr.','Lieferdatum','Lieferschein-Nr.','WV-Start','WV-Ende','Aufgaben Schritt','Verkehrsart','Anz.\nHE '])
|
|
self.df_cmdb = self.df_cmdb[self.df_cmdb['Filter'].isin(['Grundgerät','Erweiterung'])]
|
|
|
|
self.df_cmdb = self.df_cmdb.drop(columns=['WV-Start','WV-Ende','CMDB-Status','Aufgabe Schritt'])
|
|
|
|
|
|
# Einfügen von Spalten in die CMDB-Tabelle
|
|
self.dfb = self.df_vte.merge(self.df_cmdb, on=['Hostname'], how='left')
|
|
|
|
# Zeile einfügen für HE
|
|
self.dfb.insert(loc=11, column='HE', value='')
|
|
|
|
self.dfb = self.dfb.apply(self.prüfe_und_setze_wert, axis=1)
|
|
|
|
# Setzen von int für HE und Anz. HE
|
|
self.dfb['HE'] = self.dfb['HE'].apply(lambda x: x if pd.isnull(x) else str(int(x)))
|
|
self.dfb['belegte\nHE'] = self.dfb['belegte\nHE'].apply(lambda x: x if pd.isnull(x) else str(int(x)))
|
|
|
|
#self.dfb = self.dfb.T.drop_duplicates().T
|
|
# self.dfb = self.dfb.drop(columns=['Bestelldatum_y','Hersteller_y','Lieferant_y','RAM_y','SAP-Nr._y'])
|
|
# self.dfb = self.dfb.rename(columns={'Bestelldatum_x':'Bestelldatum','Hersteller_x':'Hersteller','Lieferant_x':'Lieferant'})
|
|
|
|
# ic(self.df_cmdb)
|
|
|
|
|
|
# Zusammenfassen aller geänderten Werte
|
|
# Wenn Gruppierung nicht ausgewählt wurde, muss es separat ausgelesen werden
|
|
|
|
#self.changegroup()
|
|
#ic(self.changegroup())
|
|
#self.changegtyp()
|
|
#ic(self.changegtyp())
|
|
|
|
#if self.filter: # Wenn True dann nur mit Hostnamen
|
|
# print("Filter ", self.filter)
|
|
#ic(self.filter)
|
|
|
|
def prüfe_und_setze_wert(self, zeile):
|
|
ic(zeile)
|
|
if zeile['ID\nStandort'] not in ("Ber-PS","Bon-BTW"):
|
|
print("Kein Standort P40 oder BTW")
|
|
sys.exit(0)
|
|
else:
|
|
if len((zeile['Montageort'][8:13])) !=2:
|
|
zeile['HE'] = zeile['Montageort'][8:10]
|
|
zeile['Montageort'] = zeile['Montageort'][0:7]
|
|
else:
|
|
zeile['HE'] = zeile['Montageort'][8:10]
|
|
zeile['Montageort'] = zeile['Montageort'][0:7]
|
|
|
|
|
|
if zeile['Hersteller'].lower() == "cisco":
|
|
zeile['Hersteller'] = "Cisco Systems"
|
|
elif zeile['Hersteller'].lower() == "genua":
|
|
zeile['Hersteller'] = "genua GmbH"
|
|
elif zeile['Hersteller'].lower() == "digi":
|
|
zeile['Hersteller'] = "Digi International Inc."
|
|
else:
|
|
pass
|
|
|
|
return zeile
|
|
|
|
|
|
|
|
|
|
def save_file_dialog(self):
|
|
ic(self.dfb)
|
|
options = QFileDialog.Options()
|
|
options |= QFileDialog.DontUseNativeDialog
|
|
self.savefilename, _ = QFileDialog.getSaveFileName(self,
|
|
"Save File", "", "CSV(*.csv);;CSV Files(*.csv)", options = options)
|
|
|
|
self.dfb.to_csv(self.savefilename, index=None, header=True, encoding='utf-8')
|
|
print("Datei wurde gespeichert:", self.savefilename)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# match item(self.df['Hostname'].str[4:6]):
|
|
# case '10':
|
|
# self.df["Mandanten ID"] = "m10 CMP Plattform / iM.0 / iM.4 / PAP sIMCP"
|
|
# case other:
|
|
# self.df["Mandanten ID"] = ""
|
|
# m19 Testumgebung 19
|
|
# m20 iM.1 Interner Mandant (Schutzbedarf sehr hoch) 20
|
|
# m21 iM.2 Interner Mandant (Schutzbedarf normal) 21
|
|
# m22 iM.3 Interner Mandant (Schutzbedarf hoch) 22
|
|
# m50 sEMCP.Instanz-1 (CMP Zentral) 50
|
|
# m51 Classified OPS 51
|
|
# m73 FWP Lüftersteuerung 73
|
|
# m75 Fawkes 75
|
|
# m76 Demo 76
|
|
# m77 Fritz54 77
|
|
# m78 ITZBund mSBC 78
|
|
# m79 BOS-Spur 79
|
|
# m99 Releasemanagement 99
|
|
# m80 ACDC 80
|
|
|
|
|
|
# ic(self.df)
|
|
|
|
#self.df = self.df['Gerätetyp'] = self.gruppierung.currentText()
|
|
#print(self.gruppierung.currentText())
|
|
|
|
# if self.selected_typ_value != "VM":
|
|
# self.df = self.df[self.df['Gruppierung'] == selected_group_value]
|
|
|
|
|
|
|
|
# def changetable(self):
|
|
# with self.path:
|
|
# self.df = pd.DataFrame(pd.read_excel(self.filename))#,dtype=str)
|
|
# self.dfb = self.df
|
|
#
|
|
# self.unique_groups = self.df['Gruppierung'].unique().tolist()
|
|
# #print("unique_group: ",self.unique_groups)
|
|
# self.unique_typs = self.df['Gerätetyp'].unique().tolist()
|
|
|
|
# for i in self.unique_groups:
|
|
# if isinstance(i, str): # Check ob i ein str ist
|
|
# if i !="nan":
|
|
# self.gruppierung.addItem(i)
|
|
|
|
|
|
# for i in self.unique_typs:
|
|
# if isinstance(i, str):
|
|
# if i !="nan":
|
|
# self.geraetetyp.addItem(i)
|
|
|
|
|
|
|
|
#print(self.df)
|
|
# def mandantenid(self,id):
|
|
# ic("MandantenID = ",id," ",id[1][4:6])
|
|
# return int(id[1][4:6])
|
|
#
|
|
# #return id.get( key= "Hostname")
|
|
# pass
|
|
|
|
""" def prüfe_und_setze_wert(self, zeile):
|
|
#ic(zeile)
|
|
if zeile['Mandanten ID'][4:6] == "10": # Indexe 4 und 5 entsprechen den Stellen 5 und 6
|
|
zeile['Mandanten ID'] = 'm10 CMP Plattform / iM.0 / iM.4 / PAP sIMCP'
|
|
elif zeile['Mandanten ID'][4:6] == "19":
|
|
zeile['Mandanten ID'] = 'm19 Testumgebung'
|
|
elif zeile['Mandanten ID'][4:6] == "20":
|
|
zeile['Mandanten ID'] = 'm20 iM.1 Interner Mandant (Schutzbedarf sehr hoch)'
|
|
elif zeile['Mandanten ID'][4:6] == "21":
|
|
zeile['Mandanten ID'] = 'm21 iM.2 Interner Mandant (Schutzbedarf normal)'
|
|
elif zeile['Mandanten ID'][4:6] == "22":
|
|
zeile['Mandanten ID'] = 'm22 iM.3 Interner Mandant (Schutzbedarf hoch)'
|
|
elif zeile['Mandanten ID'][4:6] == "50":
|
|
zeile['Mandanten ID'] = 'm50 sEMCP.Instanz-1 (CMP Zentral)'
|
|
elif zeile['Mandanten ID'][4:6] == "51":
|
|
zeile['Mandanten ID'] = 'm51 Classified OPS'
|
|
elif zeile['Mandanten ID'][4:6] == "73":
|
|
zeile['Mandanten ID'] = 'm73 FWP Lüftersteuerung'
|
|
elif zeile['Mandanten ID'][4:6] == "75":
|
|
zeile['Mandanten ID'] = 'm75 Fawkes'
|
|
elif zeile['Mandanten ID'][4:6] == "76":
|
|
zeile['Mandanten ID'] = 'm76 Demo'
|
|
elif zeile['Mandanten ID'][4:6] == "77":
|
|
zeile['Mandanten ID'] = 'm77 Fritz54 '
|
|
elif zeile['Mandanten ID'][4:6] == "78":
|
|
zeile['Mandanten ID'] = 'm78 ITZBund mSBC'
|
|
elif zeile['Mandanten ID'][4:6] == "79":
|
|
zeile['Mandanten ID'] = 'm79 BOS-Spur'
|
|
elif zeile['Mandanten ID'][4:6] == "99":
|
|
zeile['Mandanten ID'] = 'm99 Releasemanagement'
|
|
elif zeile['Mandanten ID'][4:6] == "80":
|
|
zeile['Mandanten ID'] = 'm80 ACDC'
|
|
|
|
if zeile['Segment'][6:8] == "00":
|
|
zeile['Segment'] = 'm10 mgmt CMP Core'
|
|
ic('m10 mgmt CMP Core')
|
|
elif zeile['Segment'][6:8] == "01":
|
|
zeile['Segment'] = 'm10 mgmt Infrastructure'
|
|
elif zeile['Segment'][6:8] == "02":
|
|
zeile['Segment'] = 'm10 mgmt Administration'
|
|
elif zeile['Segment'][6:8] == "03":
|
|
zeile['Segment'] = 'm10 mgmt zLightsOut'
|
|
elif zeile['Segment'][6:8] == "04":
|
|
zeile['Segment'] = 'm10 CTS'
|
|
elif zeile['Segment'][6:8] == "05":
|
|
zeile['Segment'] = 'm10-OSS'
|
|
elif zeile['Segment'][6:8] == "10":
|
|
zeile['Segment'] = 'm10 CMP2sIM'
|
|
elif zeile['Segment'][6:8] == "11":
|
|
zeile['Segment'] = 'm10 Intern-CMP iM0'
|
|
elif zeile['Segment'][6:8] == "12":
|
|
zeile['Segment'] = 'm20 iM.1 Interner Mandant 1 (SB sehr hoch)'
|
|
elif zeile['Segment'][6:8] == "13":
|
|
zeile['Segment'] = 'm21 iM.2 Interner Mandant 2 (SB normal)'
|
|
elif zeile['Segment'][6:8] == "14":
|
|
zeile['Segment'] = 'm22 iM.3 Interner Mandant 3 (SB hoch)'
|
|
elif zeile['Segment'][6:8] == "15":
|
|
zeile['Segment'] = 'm10 iM.4 Interner Mandant 4 (CNMS2CMP)'
|
|
elif zeile['Segment'][6:8] == "20":
|
|
zeile['Segment'] = 'VRD-Plattform (PAP-Anbindung)'
|
|
elif zeile['Segment'][6:8] == "21":
|
|
zeile['Segment'] = 'VRD-Plattform (LightsOut + Basisinfrastruktur + Cache)'
|
|
elif zeile['Segment'][6:8] == "22":
|
|
zeile['Segment'] = 'VRD-Plattform (Admin)'
|
|
elif zeile['Segment'][6:8] == "23":
|
|
zeile['Segment'] = 'VRD-Plattform (Basisinfrastruktur Mandant zentral)'
|
|
elif zeile['Segment'][6:8] == "24":
|
|
zeile['Segment'] = 'Spare'
|
|
elif zeile['Segment'][6:8] == "25":
|
|
zeile['Segment'] = 'Spare'
|
|
elif zeile['Segment'][6:8] == "26":
|
|
zeile['Segment'] = 'Spare'
|
|
elif zeile['Segment'][6:8] == "27":
|
|
zeile['Segment'] = 'Spare'
|
|
elif zeile['Segment'][6:8] == "28":
|
|
zeile['Segment'] = 'Spare'
|
|
elif zeile['Segment'][6:8] == "29":
|
|
zeile['Segment'] = 'Spare'
|
|
elif zeile['Segment'][6:8] == "30":
|
|
zeile['Segment'] = 'Spare'
|
|
elif zeile['Segment'][6:8] == "31":
|
|
zeile['Segment'] = 'VRD-Mandant (Infrastruktur)'
|
|
elif zeile['Segment'][6:8] == "32":
|
|
zeile['Segment'] = 'VRD-Mandant (Admin)'
|
|
elif zeile['Segment'][6:8] == "33":
|
|
zeile['Segment'] = 'VRD-Mandant (Anbindung)'
|
|
elif zeile['Segment'][6:8] == "34":
|
|
zeile['Segment'] = 'Spare'
|
|
elif zeile['Segment'][6:8] == "35":
|
|
zeile['Segment'] = 'Spare'
|
|
elif zeile['Segment'][6:8] == "36":
|
|
zeile['Segment'] = 'Spare'
|
|
elif zeile['Segment'][6:8] == "37":
|
|
zeile['Segment'] = 'Spare'
|
|
elif zeile['Segment'][6:8] == "38":
|
|
zeile['Segment'] = 'Spare'
|
|
elif zeile['Segment'][6:8] == "39":
|
|
zeile['Segment'] = 'Spare'
|
|
elif zeile['Segment'][6:8] == "40":
|
|
zeile['Segment'] = 'Spare'
|
|
elif zeile['Segment'][6:8] == "41":
|
|
zeile['Segment'] = 'Spare'
|
|
elif zeile['Segment'][6:8] == "42":
|
|
zeile['Segment'] = 'Spare'
|
|
elif zeile['Segment'][6:8] == "43":
|
|
zeile['Segment'] = 'Spare'
|
|
elif zeile['Segment'][6:8] == "44":
|
|
zeile['Segment'] = 'Spare'
|
|
elif zeile['Segment'][6:8] == "45":
|
|
zeile['Segment'] = 'Spare'
|
|
elif zeile['Segment'][6:8] == "46":
|
|
zeile['Segment'] = 'Spare'
|
|
elif zeile['Segment'][6:8] == "47":
|
|
zeile['Segment'] = 'Spare'
|
|
elif zeile['Segment'][6:8] == "48":
|
|
zeile['Segment'] = 'Spare'
|
|
elif zeile['Segment'][6:8] == "49":
|
|
zeile['Segment'] = 'Spare'
|
|
elif zeile['Segment'][6:8] == "50":
|
|
zeile['Segment'] = 'Spare'
|
|
elif zeile['Segment'][6:8] == "51":
|
|
zeile['Segment'] = 'VRD-Mandant (Kundensegment Infra)'
|
|
elif zeile['Segment'][6:8] == "52":
|
|
zeile['Segment'] = 'VRD-Mandant (Kundensegment Admin)'
|
|
elif zeile['Segment'][6:8] == "53":
|
|
zeile['Segment'] = 'VRD-Mandant (Kundensegment)'
|
|
elif zeile['Segment'][6:8] == "b0":
|
|
zeile['Segment'] = 'mgmt BS Übergang zum CMP Core'
|
|
elif zeile['Segment'][6:8] == "ba":
|
|
zeile['Segment'] = 'mgmt BS Bon BTW'
|
|
elif zeile['Segment'][6:8] == "bb":
|
|
zeile['Segment'] = 'mgmt BS Bon LRS'
|
|
elif zeile['Segment'][6:8] == "bc":
|
|
zeile['Segment'] = 'mgmt BS Ber W55'
|
|
elif zeile['Segment'][6:8] == "bd":
|
|
zeile['Segment'] = 'mgmt BS Ber PS'
|
|
elif zeile['Segment'][6:8] == "be":
|
|
zeile['Segment'] = 'mgmt BS Ber NDA'
|
|
elif zeile['Segment'][6:8] == "bf":
|
|
zeile['Segment'] = 'mgmt BS HanTMX'
|
|
elif zeile['Segment'][6:8] == "bg":
|
|
zeile['Segment'] = 'mgmt BS Ber DS'
|
|
elif zeile['Segment'][6:8] == "c0":
|
|
zeile['Segment'] = 'mgmt CMP Übergang Internet'
|
|
elif zeile['Segment'][6:8] == "x1":
|
|
zeile['Segment'] = 'm10 SecA2sIM'
|
|
|
|
return zeile """
|
|
|
|
|
|
if __name__ == "__main__" :
|
|
app = QApplication (sys.argv)
|
|
ui = MainUI()
|
|
ui.show()
|
|
app.exec_()
|