Keine direkten funktionalen Änderungen vorgenommen. Vor allem Errorhandling erweitert und Code an PEP8 angepasst. Zudem Anpassungen von Umgebungsvariablen in cremig_setenv.bat in diese Datei übernommen
This commit is contained in:
+43
-36
@@ -2,43 +2,52 @@ import argparse
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
# import configparser
|
||||
# import json
|
||||
|
||||
"""
|
||||
Dieses Programm holt sich aus
|
||||
- RD Fusion eine aktuellen Stand der exisitierenden IDS
|
||||
- Sivas eine Liste der gewünschten Teile
|
||||
|
||||
Dieses Programm:
|
||||
- Kopiert die CSV-Datei mit allen RuleDesigner-Nummern
|
||||
- Fragt Sivas ab und generiert dabei eine json-Datei, in der alle Teilenummern aufgelistet sind,
|
||||
die in Verbindung mit einer angegebenen Teilenummer migriert werden müssen.
|
||||
"""
|
||||
def get_rd_database(inPath, outDir, outFileName):
|
||||
if os.path.isfile(inPath):
|
||||
|
||||
outFilePath = os.path.join(outDir, outFileName)
|
||||
if os.path.isdir(outDir):
|
||||
shutil.copyfile(inPath, outFilePath)
|
||||
else:
|
||||
print(f"no such directory ${outDir} of env CREMIG_DATA")
|
||||
def get_rd_dbase(out_dir):
|
||||
|
||||
rd_csv_source_dir = os.environ.get('RD_DATABASE_SOURCE')
|
||||
rd_csv_filename = os.environ.get('RD_DATABASE_NAME')
|
||||
csv_source_filepath = os.path.join(rd_csv_source_dir, rd_csv_filename)
|
||||
|
||||
if os.path.isfile(csv_source_filepath):
|
||||
csv_out_filepath = os.path.join(out_dir, rd_csv_filename)
|
||||
|
||||
if os.path.isdir(out_dir):
|
||||
print("Copying CSV-file of RuleDesigner database...")
|
||||
shutil.copyfile(rd_csv_source_dir, csv_out_filepath)
|
||||
print("done")
|
||||
else:
|
||||
print(f"no such file ${inPath} of environment variable RD_DATABASE_SOURCE. have a look at cremig_setenv.bat")
|
||||
|
||||
|
||||
def get_sivas_databse(exePath, sivasId, outFilePath):
|
||||
if os.path.isfile(exePath):
|
||||
|
||||
if os.path.isdir(outDir):
|
||||
#subprocess.Popen([exePath, "-o", outDir, "--format json", "-number", sivasId ])
|
||||
cmd = ' '.join([exePath, "-o", outDir, "--format json", "-number", sivasId ])
|
||||
os.system(cmd)
|
||||
print(f"Can't copy RuleDesigner-database, because output directory ${out_dir} doesn't exist. Check path of %CREMIG_DATA% in cremig_setenv.bat")
|
||||
else:
|
||||
print(f"no such executable ${outDir} of env CREMIG_DATA")
|
||||
if os.path.isfile(outFilePath):
|
||||
print(f"no such file ${rd_csv_source_dir} of environment variable RD_DATABASE_SOURCE. Check cremig_setenv.bat")
|
||||
|
||||
|
||||
def get_sivas_dbase(sivas_id, out_dir):
|
||||
sivas_exe_path = os.environ.get('SIVAS_DATABASE_QUERY')
|
||||
|
||||
if os.path.isfile(sivas_exe_path):
|
||||
|
||||
if os.path.isdir(out_dir):
|
||||
print(f"Attempting to generate a json-file of all parts to be migrated in relation with '{sivas_id}'")
|
||||
subprocess.run(f"{sivas_exe_path} -o {out_dir} --format json -number {sivas_id}")
|
||||
|
||||
if os.path.isfile(os.path.join(out_dir, sivas_id + ".json")):
|
||||
print("done")
|
||||
else:
|
||||
print("failure - did not get .json file")
|
||||
print(f"Failure - Couldn't generate {sivas_id}.json. Check for any spelling/typing errors. Otherwise given number is a part without a BOM.")
|
||||
exit()
|
||||
else:
|
||||
print(f"no such file ${exePath} of environment variable SIVAS_DATABASE_QUERY. have a look at cremig_setenv.bat")
|
||||
print(f"'Output directory for .json-file {out_dir}' doesn't exist.")
|
||||
else:
|
||||
print(f"Can't execute SIVAS-database query. Check if you have established a VPN connection to the company's network and check the path of %SIVAS_DATABASE_QUERY% in cremig_setenv.bat")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(description='fetches data from sivas or ruledesigner fusion', prog='update_database')
|
||||
@@ -47,15 +56,13 @@ if __name__ == '__main__':
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
outDir = os.environ.get('CREMIG_DATA')
|
||||
out_dir = os.environ.get('CREMIG_DATA')
|
||||
|
||||
if args.rd:
|
||||
inPath = os.environ.get('RD_DATABASE_SOURCE')
|
||||
outFileName = "RD_Bestandspool.csv"
|
||||
get_rd_database(inPath, outDir, outFileName)
|
||||
get_rd_dbase(out_dir)
|
||||
|
||||
elif args.sivas:
|
||||
get_sivas_dbase(args.sivas, out_dir)
|
||||
|
||||
if args.sivas:
|
||||
exePath = os.environ.get('SIVAS_DATABASE_QUERY')
|
||||
sivasId = str(args.sivas)
|
||||
outFilePath = os.path.join(outDir, sivasId + ".json")
|
||||
get_sivas_databse(exePath, sivasId, outFilePath)
|
||||
else:
|
||||
print("ERROR - Missing flags!")
|
||||
|
||||
Reference in New Issue
Block a user