49 lines
2.3 KiB
Python
49 lines
2.3 KiB
Python
import argparse
|
|
import os
|
|
from manage_configs import MigrationStatus
|
|
import update_database
|
|
|
|
class FetchSivasTeilestamm:
|
|
def __init__(self, assembly_json_name, assembly_json_out_dir=os.environ.get('CREMIG_DATA'), csv_out_dir=os.environ.get('CREMIG_DATA')):
|
|
self.assembly_json_out_dir = assembly_json_out_dir
|
|
self.assembly_json_name = str(assembly_json_name).replace('.json', "") + ".json"
|
|
self.csv_out_dir = csv_out_dir
|
|
self.migration = None
|
|
|
|
def fetch_from_db(self, use_local=False):
|
|
self.migration = MigrationStatus(self.assembly_json_out_dir, self.assembly_json_name)
|
|
if use_local:
|
|
self.migration.use_local()
|
|
|
|
def get_unmigrated_teilstamm_csvs(self):
|
|
"""Generiert CSV-Dateien für alle noch nicht migrierten Stücklistenteile der angegebenen Baugruppennummer"""
|
|
if self.migration == None:
|
|
raise Exception("not yet connected to local data or database")
|
|
unmigrated_ids = self.migration.get_unmigrated_ids()
|
|
update_database.get_sivas_teilestamm(unmigrated_ids, self.csv_out_dir)
|
|
|
|
def get_red_ids(self):
|
|
if self.migration == None:
|
|
raise Exception("not yet connected to local data or database")
|
|
return self.migration.get_unmigrated_ids()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
parser = argparse.ArgumentParser(description='fetches data from sivas or ruledesigner fusion', prog='update_database')
|
|
parser.add_argument('-s', '--sivasid', action='store', help='fetch teilestamm-data for all unmigrated parts in the bom of a given asm-id. Specifiy multiple ids as comma separated values without space, e.g. 200000089,200000090', metavar='id(s)')
|
|
parser.add_argument('-l', '--uselocal', action='store_true', help='Do not connect to database. Use local files (if already existing) for the given asm-id')
|
|
|
|
args = parser.parse_args()
|
|
|
|
out_dir = os.environ.get('CREMIG_DATA')
|
|
|
|
if args.sivasid:
|
|
sivas_asm_id = args.sivasid.strip().replace(".json","")
|
|
sivas_teilestamm = FetchSivasTeilestamm(sivas_asm_id, out_dir)
|
|
if args.uselocal:
|
|
sivas_teilestamm.use_local(args.uselocal)
|
|
sivas_teilestamm.fetch_from_db()
|
|
sivas_teilestamm.get_unmigrated_teilstamm_csvs()
|
|
|
|
else:
|
|
parser.print_help() |