Files
CreoMigrate/lib/update_database.py
T

69 lines
2.7 KiB
Python

import argparse
import os
import shutil
import subprocess
"""
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_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"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 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(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"'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')
parser.add_argument('-s', '--sivas', action='store', help='fetch data of this id from sivas fo local database folder')
parser.add_argument('-r', '--rd', action='store_true', help='fetch list of existing parts from network drive')
args = parser.parse_args()
out_dir = os.environ.get('CREMIG_DATA')
if args.rd:
get_rd_dbase(out_dir)
elif args.sivas:
get_sivas_dbase(args.sivas, out_dir)
else:
print("ERROR - Missing flags!")