Files
CreoMigrate/lib/update_database.py
T

62 lines
2.2 KiB
Python

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
"""
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")
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)
else:
print(f"no such executable ${outDir} of env CREMIG_DATA")
if os.path.isfile(outFilePath):
print("done")
else:
print("failure - did not get .json file")
else:
print(f"no such file ${exePath} of environment variable SIVAS_DATABASE_QUERY. have a look at 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()
outDir = 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)
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)