FIX - Die Metadaten-CSV von Teilenummern mit Leerzeichen, z.B. 'TOS Auswahl FGN' wurde bisher nicht abgeleitet. Dies funktioniert nun. Zudem Denesting durchgeführt und spezifischere Error-Checks eingebaut
This commit is contained in:
+15
-29
@@ -90,43 +90,29 @@ def get_sivas_teilestamm(sivas_ids, out_dir=os.environ.get('CREMIG_DATA'), overw
|
|||||||
"""call the sivas exe for getting all csv files with the item data for the given sivas ids"""
|
"""call the sivas exe for getting all csv files with the item data for the given sivas ids"""
|
||||||
|
|
||||||
sivas_teilestamm_exe = os.environ.get('SIVAS_TEILESTAMM')
|
sivas_teilestamm_exe = os.environ.get('SIVAS_TEILESTAMM')
|
||||||
|
if not os.path.isfile(sivas_teilestamm_exe):
|
||||||
|
raise FileNotFoundError(f"Check VPN connection or path of %SIVAS_DATABASE_QUERY% in cremig_setenv.bat")
|
||||||
|
|
||||||
|
if not os.path.isdir(out_dir):
|
||||||
|
raise NotADirectoryError(f"Output directory for .csv-file(s) ${out_dir} doesn't exist.")
|
||||||
|
|
||||||
if isinstance(sivas_ids, str):
|
if isinstance(sivas_ids, str):
|
||||||
sivas_ids = list(set(sivas_ids.strip().split(",")))
|
sivas_ids = list(set(sivas_ids.strip().split(",")))
|
||||||
|
|
||||||
ids_to_generate = []
|
ids_to_generate = []
|
||||||
for id in sivas_ids:
|
for id in sivas_ids:
|
||||||
id = id.replace(" ", "")
|
out_file = os.path.join(out_dir, id + ".csv")
|
||||||
if not overwrite:
|
if not overwrite and os.path.isfile(out_file):
|
||||||
out_file = os.path.join(out_dir, id + ".csv")
|
continue
|
||||||
if not os.path.isfile(out_file):
|
ids_to_generate.append(f'"{id}"') # Anführungszeichen erforderlich, damit Art.Nr. mit Leerzeichen, z.B. "TOS Auswahl ILS" funktionieren
|
||||||
ids_to_generate.append(id)
|
|
||||||
continue
|
|
||||||
else:
|
|
||||||
ids_to_generate.append(id)
|
|
||||||
|
|
||||||
if not id.isnumeric():
|
if len(ids_to_generate) == 0:
|
||||||
print(f"Partnumber '{id}' contains invalid characters. Please check given partnumber. Multiple partnumbers have to be specified as comma separated values without space, e.g. 200000089,200000090")
|
print("CSV-file(s) already exist or given partnumber(s) are migrated.")
|
||||||
|
return
|
||||||
|
|
||||||
|
ids_to_generate = ",".join(ids_to_generate)
|
||||||
if os.path.isfile(sivas_teilestamm_exe):
|
os.environ["SIVAS_EXCEL_EXPORT_DIR"] = out_dir
|
||||||
|
subprocess.run(f'{sivas_teilestamm_exe} -teilenr={ids_to_generate} -open_target_dir=n')
|
||||||
if os.path.isdir(out_dir):
|
|
||||||
|
|
||||||
if len(ids_to_generate) == 0:
|
|
||||||
print("CSV-file(s) already exist or given partnumber(s) are migrated.")
|
|
||||||
return
|
|
||||||
|
|
||||||
else:
|
|
||||||
print(f"Attempting to generate csv-file(s) for given partnumber(s)...")
|
|
||||||
|
|
||||||
ids_to_generate = ",".join(ids_to_generate)
|
|
||||||
os.environ["SIVAS_EXCEL_EXPORT_DIR"] = out_dir
|
|
||||||
subprocess.run(f"{sivas_teilestamm_exe} -teilenr={ids_to_generate} -open_target_dir=n")
|
|
||||||
else:
|
|
||||||
print(f"Output directory for .csv-file(s) ${out_dir} doesn't exist.")
|
|
||||||
else:
|
|
||||||
print(f"Can't execute SIVAS-database query. Check VPN connection or check the path of %SIVAS_DATABASE_QUERY% in cremig_setenv.bat")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Reference in New Issue
Block a user