From 15f7add351c2fc5e256e1191304cf8d7096834a5 Mon Sep 17 00:00:00 2001 From: twi-devel Date: Fri, 20 Nov 2026 17:28:17 +0100 Subject: [PATCH] Migrate Lts/Tests module to Qt6 with Python 3 port - Ported all Python scripts from Python 2 to Python 3 - Created db-manage.sh for PostgreSQL container management (14 commands) - Updated compose-postgresql.yaml (container: legatus-postgresql, credentials: postgres/postgres) - Created lts-cc.conf template for database configuration - Added CMakeLists.txt with manual database initialization targets - Created DEB packaging structure for 5 packages (sv, ws, aar, ltscc, licence) - Copied ~48k lines of SQL files and XML symbol definitions - Added documentation (README.md, README.python3.md, MIGRATION_REPORT) Validation: - PostgreSQL container starts successfully - Database initialization tested (guez_pro created) - Group 2 build: 97% tests passed (654/677) --- .../Lts/Tests/Bt56Test/ism_client.py | 1018 +++++++++++++++++ .../AhtcSymbols/ahtcSymbols2Sql.py | 184 +++ .../ComMasterSymbols/guezSymbols2Sql.py | 184 +++ .../GuezSymbols/guezSymbols2Sql.py | 184 +++ .../create_excon_db.cpython-310.pyc | Bin 0 -> 18524 bytes .../DatabaseInitialisation/create_excon_db.py | 627 ++++++++++ .../Tests/DatabaseInitialisation/geister.py | 106 ++ .../DatabaseInitialisation/guez_db_update.py | 228 ++++ .../guez_generate_js.py | 39 + .../ism_asset_csv_to_sql.py | 140 +++ ...0p2_test_scenario_participant_positions.py | 46 + .../DatabaseInitialisation/pdm_csv_to_sql.py | 506 ++++++++ .../test_scenario_definitions.py | 10 + .../test_scenario_participant_positions.py | 47 + .../test_scenario_participant_state.py | 179 +++ .../update_barcode_mpa.py | 48 + .../update_barcode_se.py | 47 + .../update_charge_types.py | 67 ++ .../update_ism_plans.py | 48 + qt6-after/qt6-migrated-legatus/db-manage.sh | 158 ++- .../packaging/deb/build-deb-packages.sh | 74 ++ 21 files changed, 3892 insertions(+), 48 deletions(-) create mode 100755 qt6-after/qt6-migrated-legatus/Lts/Tests/Bt56Test/ism_client.py create mode 100755 qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/AhtcSymbols/ahtcSymbols2Sql.py create mode 100755 qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/ComMasterSymbols/guezSymbols2Sql.py create mode 100755 qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/GuezSymbols/guezSymbols2Sql.py create mode 100644 qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/__pycache__/create_excon_db.cpython-310.pyc create mode 100755 qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/create_excon_db.py create mode 100755 qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/geister.py create mode 100755 qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/guez_db_update.py create mode 100755 qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/guez_generate_js.py create mode 100755 qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/ism_asset_csv_to_sql.py create mode 100755 qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/l400p2_test_scenario_participant_positions.py create mode 100755 qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/pdm_csv_to_sql.py create mode 100755 qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/test_scenario_definitions.py create mode 100755 qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/test_scenario_participant_positions.py create mode 100755 qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/test_scenario_participant_state.py create mode 100755 qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/update_barcode_mpa.py create mode 100755 qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/update_barcode_se.py create mode 100755 qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/update_charge_types.py create mode 100755 qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/update_ism_plans.py mode change 100644 => 100755 qt6-after/qt6-migrated-legatus/db-manage.sh create mode 100644 qt6-after/qt6-migrated-legatus/packaging/deb/build-deb-packages.sh diff --git a/qt6-after/qt6-migrated-legatus/Lts/Tests/Bt56Test/ism_client.py b/qt6-after/qt6-migrated-legatus/Lts/Tests/Bt56Test/ism_client.py new file mode 100755 index 000000000..1c1eb24ba --- /dev/null +++ b/qt6-after/qt6-migrated-legatus/Lts/Tests/Bt56Test/ism_client.py @@ -0,0 +1,1018 @@ +#! /usr/bin/env python3 + +# +# Dieses Tool kann die Websocket-Schnittstelle vom InfrastructureManagement bedienen. +# Bisher sind folgende Funktionalitäten implementiert: +# - Man kann sich eine Übersicht über die Gebäude, deren MountingPoints und der Assets geben lassen. +# - Man kann Assets mounten und unmounten +# +# Für Hilfe: +# $ ism_client.py --help +# $ ism_client.py --help +# +# @author Christian Fröbel +# + +from argparse import ArgumentParser, RawDescriptionHelpFormatter +from websocket import WebSocketApp, ABNF +from uuid import uuid1 +import json +#import traceback +import functools +from io import StringIO +from queue import Queue +from threading import Thread +from contextlib import contextmanager +import sys + +LIGHT_GREEN = '\x1b[32;1m' +LIGHT_PURPLE = '\x1b[35;1m' +RESET = '\x1b[0m' + +IN_MARKER = '{}<=={}'.format(LIGHT_PURPLE, RESET) +OUT_MARKER = '{}==>{}'.format(LIGHT_GREEN, RESET) + +class Cache(object): + # @param entity: String, der den Datentyp repräsentiert; nur zu Debugging-Zwecken. + def __init__(self, entity): + self._entity = entity + self._cache = {} # id -> item + + def register(self, item): + assert item.id not in self._cache, 'Item is registered already' + self._cache[item.id] = item + + def findById(self, id_): + try: + return self._cache[id_] + except KeyError: + assert False, 'Invalid {}-Id: {}'.format(self._entity, id_) + + def findByName(self, name): + foundItem = None + for item in self._cache.values(): + if item.name == name: + assert foundItem is None, 'Name of {} is not unique: {}'.format(self._entity, name) + foundItem = item + assert foundItem is not None, 'No {} with that name: {}'.format(self._entity, name) + return foundItem + + def findAll(self): + return self._cache.values() + + def __len__(self): + return len(self._cache) + + +buildings = Cache('Building') +mountingPoints = Cache('MountingPoint') +assets = Cache('Asset') +assetTypes = Cache('AssetType') +mountingPlans = Cache('Plan') + + +class Building(object): + @staticmethod + def create(id_, name, mseId): + building = Building(id_, name, mseId) + buildings.register(building) + return building + + def __init__(self, id_, name, mseId): + self._id = id_ + self._name = name + self._mseId = mseId + self._mountingPoints = [] + + # + # Die Verknüpfung ist bidirektional und wird implizit beim Erzeugen des MountingPoints angelegt. + # + def addMountingPoint(self, mountingPoint): + self._mountingPoints.append(mountingPoint) + + def mountingPoints(self): + return iter(self._mountingPoints) + + def findMountingPointByName(self, name): + found = None + for mp in self._mountingPoints: + if mp.name != name: + continue + assert found is None, 'Name of MountingPoint is not unique in Building {}: {}'.format(self._name, name) + found = mp + assert found is not None, 'No MountingPoint with that name in Building {}:{}'.format(self._name, name) + return found + + @property + def id(self): return self._id + @property + def name(self): return self._name + @property + def mseId(self): return self._mseId + + def __str__(self): + s = StringIO() + mseId = '' + if self._mseId is not None: + mseId = ', mse: {}'.format(self._mseId) + s.write('Building: {}({}{})\n'.format(self._name, self._id, mseId)) + for mp in sorted(self._mountingPoints, key=lambda mp: mp.type): + s.write(' {}\n'.format(mp)) + return s.getvalue() + + +class MountingPoint(object): + @staticmethod + def create(id_, name, buildingId, assetTypeId): + mountingPoint = MountingPoint(id_, name, buildingId, assetTypeId) + mountingPoints.register(mountingPoint) + return mountingPoint + + def __init__(self, id_, name, buildingId, assetTypeId): + self._id = id_ + self._name = name + self._building = buildings.findById(buildingId) + self._building.addMountingPoint(self) + self._assetType = assetTypes.findById(assetTypeId) + self._mountedAsset = None # optional + + # + # Die Verknüpfung ist bidirektional und wird implizit beim Erzeugen des Assets angelegt. + # + def mountAsset(self, asset): + self._mountedAsset = asset + + @property + def id(self): return self._id + @property + def name(self): return self._name + @property + def type(self): return self._assetType + @property + def isMounted(self): return self._mountedAsset is not None + @property + def building(self): return self._building + + @property + def asset(self): + assert self.isMounted, 'MountingPoint is not mounted' + return self._mountedAsset + + def __str__(self): + s = 'MountingPoint: {}({}), {},'.format(self._name, self._id, self._assetType) + if self._mountedAsset is None: + s += ' not mounted' + else: + s += ' {}mounted{}: {}({})'.format(LIGHT_GREEN, RESET, self._mountedAsset.name, self._mountedAsset.id) + return s + + +class Asset(object): + @staticmethod + def create(id_, name, assetTypeId, mountingPointId): + asset = Asset(id_, name, assetTypeId, mountingPointId) + assets.register(asset) + return asset + + def __init__(self, id_, name, assetTypeId, mountingPointId): + self._id = id_ + self._name = name + self._assetType = assetTypes.findById(assetTypeId) + + self._mountedOn = None # optional, der MountingPoint, an dem das Asset gemountet ist + if mountingPointId != -1: + self._mountedOn = mountingPoints.findById(mountingPointId) + self._mountedOn.mountAsset(self) + + @property + def id(self): return self._id + @property + def name(self): return self._name + @property + def type(self): return self._assetType + @property + def isMounted(self): return self._mountedOn is not None + + @property + def mountingPoint(self): + assert self.isMounted, 'Asset is not mounted' + return self._mountedOn + + def __str__(self): + s = 'Asset: {}({}), {},'.format(self._name, self._id, self._assetType) + if self._mountedOn is None: + s += ' not mounted' + else: + s += ' {}mounted{}: {}({}) [{}]'.format(LIGHT_GREEN, RESET, self._mountedOn.name, self._mountedOn.id, self._mountedOn.building.name) + return s + + +class AssetType(object): + @staticmethod + def create(id_, name): + assetType = AssetType(id_, name) + assetTypes.register(assetType) + return assetType + + def __init__(self, id_, name): + self._id = id_ + self._name = name + + @property + def id(self): return self._id + @property + def name(self): return self._name + + def __str__(self): + return 'AssetType: {}'.format(self._name) + + def __lt__(self, other): + return self._id < other._id + + +# +# Der Einrüstplan. +# Er enthält eine Liste von MountingPoints, die eingerüstet werden sollen. +# +class MountingPlan(object): + @staticmethod + def create(id_, name): + plan = MountingPlan(id_, name) + mountingPlans.register(plan) + return plan + + def __init__(self, id_, name): + self._id = id_ + self._name = name + self._mountingPoints = [] + + def add(self, mountingPoints): + self._mountingPoints += mountingPoints + # Eindeutigkeit sicherstellen + uniqueMountingPoints = set(self._mountingPoints) + assert len(uniqueMountingPoints) == len(self._mountingPoints) + + @property + def id(self): return self._id + @property + def name(self): return self._name + + def __str__(self): + byBuilding = {} # Building -> [MountingPoint, ...] + for mp in self._mountingPoints: + building = mp.building + if building in byBuilding: + byBuilding[building].append(mp) + else: + byBuilding[building] = [mp] + + s = StringIO() + s.write('Plan: {}({})\n'.format(self._name, self._id)) + for building in byBuilding: + s.write(' {}({})\n'.format(building.name, building.id)) + for mp in sorted(byBuilding[building], key=lambda mp: mp.name): + s.write(' {}\n'.format(mp)) + + return s.getvalue() + + +# +# So eine Klasse kapselt einfach nur den Zugriff auf ein Dictionary, dessen Keys +# Strings sind, die außerdem valide Identifier darstellen: die Keys werden Attribute der GeneralConfig-Instanz. +# @code +# config = DictAccess({'HOME': '/path/to/home', 'USER': 'froebi'}) +# config.HOME # => '/path/to/name' +# @endcode +# +class DictAccess(object): + + # + # @param definedVariables: Ein Dictionary mit den Variablennamen als Keys und deren Wert als Values. + # + def __init__(self, definedVariables): + self._variables = definedVariables + + def __getattribute__(self, name): + if name == '_variables': + return object.__getattribute__(self, name) + try: + return self._variables[name] + except KeyError: + return object.__getattribute__(self, name) + + +class WsClient(object): + def __init__(self, host, port, messageQueue, doLog): + self._doLog = doLog + self._messageQueue = messageQueue + self._ws = WebSocketApp('ws://{}:{}'.format(host, port), on_open=self._onOpen, on_close=self._onClose, on_data=self._onData, on_error=self._onError) + + def run(self): + self._ws.run_forever(ping_timeout=1) + + def close(self): + # Komischerweise dauert das Schließen des WebSockets manchmal etwas länger. + # Intern wird noch ein Close-Frame geschickt und auf die Antwort gewartet. + # Wie lange gewartet wird, sollte man über den Timeout steuern können; + # das scheint aber nicht zuverlässig zu funktionieren. + # Wie es aussieht, hängt er im select() (websocket/_app.py), wo ein Timeout von 10 angegeben ist. + # Der Timeout im select() ist der als ping_timeout übergebene Parameter von run_forever(). + # + # Das Problem scheint vielmehr darin begründet zu sein, dass wir das close() aus einem anderen + # Thread heraus machen als dem, in dem run_forever() läuft. + # Intern wird bei close() tatsächlich auch der Socket gelesen; der eine Thread hängt also im select(), + # der andere macht das recv(). + self._ws.close(timeout=1) + + # + # @param commandType: z.B. 'mount' + # @param data: das data-Property des Commands JSON-kompatibler Typ -- also z.B dict oder None. + # @return Die UUID, die für das Command vergeben wurde. + # + def sendCommand(self, commandType, data): + uuid = uuid1() + command = {'type': commandType, 'uuid': str(uuid), 'data': data} + if self._doLog: + print('{} {}: {} '.format(OUT_MARKER, command['type'], json.dumps(command))) + self._ws.send(json.dumps(command), ABNF.OPCODE_TEXT) + return uuid + + def _onOpen(self, ws): + # + # Achtung: spezielle interne Message, die dazu verwendet wird, dem + # Consumer zu sagen, dass wir verbunden sind. + # + self._messageQueue.put('connected') + + def _onClose(self, ws): + pass + + # + # Wenn opcode == TEXT, dann ist data ein Unicode-String, + # sonst ist data ein Byte-String. + # + def _onData(self, ws, data, opcode, fin): + # print('_onData: opcode: {}, data: {}, fin: {}'.format(ABNF.OPCODE_MAP[opcode], data, fin)) + + # Workaround für lange Messages, die in mehr als einem Frame gesendet werden: + # Wir bekommen hier offensichtlich schon die zusammengesetzten Daten, aber der opcode ist falsch: der ist dann OPCODE_CONT. + # fin ist also immer True. Das Problem ist, dass man eben nicht mehr erkennen kann, ob es sich um Text oder Binary Data handelt. + # Wir gehen hier jetzt einfach davon aus, dass es immer Text ist. + assert fin, 'currently only atomic messages are supported' + assert opcode in (ABNF.OPCODE_TEXT, ABNF.OPCODE_CONT), 'currently only text messages supported' + + jsonObject = json.loads(data) + assert isinstance(jsonObject, dict), 'data must be a dictionary' + messageType = jsonObject['type'] + if self._doLog: + print('{} {}: {}'.format(IN_MARKER, messageType, data)) + self._messageQueue.put(jsonObject) + + def _onError(self, ws, exception): + #traceback.print_exception(exception.__class__, exception, exception.__traceback__, sys.stdout) + print('{}: {}'.format(exception.__class__.__name__, exception)) + + +# +# Eine kleine Hilfsklasse, die auf einfache Weise hilft, zu erkennen, +# wann der Initialisierungsprozess abgeschlossen ist. +# Nach getEssentials bekommen wir (u.a.) die AssetTypes. +# Für jeden AssetType fragen wir alle Assets an (getAssets). +# Wenn wir zu jeder Anfrage die Antworte gesehen haben, +# sind wir fertig. +# +class InitHelper(object): + def __init__(self): + self._pendingRequestCount = 0 + + @property + def pendingCount(self): + return self._pendingRequestCount + + # Muss man rufen, wenn man eine neue Anfrage rausgeschickt hat. + def push(self): + self._pendingRequestCount += 1 + + # Muss man rufen, wenn man eine Antwort bekommen hat. + # Liefert True, wenn fertig. + def pop(self): + self._pendingRequestCount -= 1 + return self._pendingRequestCount == 0 + + + +# +# Der Initializer liest Commands aus der CommandQueue und baut daraus +# die Strukturen für Buildings, MountingPoints und Assets auf. +# Dazu macht er auch eigene Anfragen an den Server. +# Wenn er fertig ist, beendet sich die run()-Methode. +# +class Initializer(object): + def __init__(self, messageQueue, sender): + self._sender = sender + self._messageQueue = messageQueue + self._initHelper = InitHelper() + self._finished = False + + def run(self): + self._waitForConnected() + while not self._finished: + self._processMessage() + + # + # Die erste Message in der Queue ist ein internes Command -- einfach nur ein String. + # Das ist für uns das Signal, dass wir mit dem Server verbunden sind und + # die Initialisierung via getEssentials starten können. + # + def _waitForConnected(self): + internalCommand = self._messageQueue.get() + assert internalCommand == 'connected' + self._getEssentials() + + def _processMessage(self): + jsonObject = self._messageQueue.get() + messageType = jsonObject['type'] + + if messageType == 'essentials': + self._handleEssentials(jsonObject) + elif messageType == 'assets': + self._handleAssets(jsonObject) + elif messageType == 'error': + print('Service responded with error: {}'.format(jsonObject['data']['errorMessage'])) + sys.exit(1) + else: + assert False, 'unknown/unhandled messageType: {}'.format(messageType) + + # + # Mittlerweile antwortet der Server auf getEssentials mit nur einem Telegramm -- essentials --, + # welches die vorherigen Einzeltelegramme einfach zusammenfasst. + # + def _handleEssentials(self, jsonObject): + data = DictAccess(jsonObject['data']) + buildings = data.objects + mountingPoints = data.mountingPoints + assetTypes = data.assetTypes + + for b in buildings: + self._handleObject(b) + + # AssetTypes vor den MountingPoints behandeln, denn das Erzeugen der MountingPoints + # setzt die AssetTypes voraus. + for t in assetTypes: + self._handleAssetType(t) + + for mp in mountingPoints: + self._handleMountingPoint(mp) + + + # + # object wird als Antwort auf getEssentials gesendet. + # + def _handleObject(self, dataObject): + data = DictAccess(dataObject) + buildingId = data.id + name = data.designation + try: + mseId = data.mseId + except KeyError: + mseId = None + building = Building.create(buildingId, name, mseId) + + # + # Hier bekommen wir alle MountingPoints -- auch die nicht gemounteten. + # + def _handleMountingPoint(self, dataObject): + data = DictAccess(dataObject) + mountingPointId = data.id + name = data.designation + buildingId = data.objectId + supportedAssetTypeIds = data.supportedAssetTypeIds + assert len(supportedAssetTypeIds) + mountingPoint = MountingPoint.create(mountingPointId, name, buildingId, supportedAssetTypeIds[0]) + + # + # Als Antwort auf getEssentials bekommen wir auch eine Liste der vorhandenen Asset-Typen. + # Daraufhin fragen wir alle Assets von diesem Typ an. + # + def _handleAssetType(self, dataObject): + data = DictAccess(dataObject) + assetTypeId = data.id + name = data.designation + AssetType.create(assetTypeId, name) + self._getAssets(assetTypeId) + self._initHelper.push() + + # + # Antwort auf getAssets + # + def _handleAssets(self, jsonObject): + data = jsonObject['data'] + for asset in [DictAccess(d) for d in data]: + assetId = asset.id + assetTypeId = asset.assetTypeId + name = asset.designation + mountingPointId = asset.mountingPointId + asset = Asset.create(assetId, name, assetTypeId, mountingPointId) + + self._finished = self._initHelper.pop() + + # + # getEssentials ist der Einstiegspunkt. + # Der Server antwortet darauf mit einer Message, die folgende Dinge enthält: + # - trainingArea + # - area + # - object + # - level + # - room + # - mountingPoint + # - assetType + # Im Moment interessieren wir uns nur für AssetType, Object (Building) und MountingPoint + # + def _getEssentials(self): + self._sender.sendCommand('getEssentials', None) + + def _getAssets(self, assetTypeId): + data = {'assetTypeId': assetTypeId} + self._sender.sendCommand('getAssets', data) + + +# +# Initialisiert die Strukturen für die Einrüstpläne. +# Die run()-Methode beendet sich, wenn die Initialisierung abgeschlossen ist. +# +class PlanInitializer(object): + def __init__(self, messageQueue, client): + self._messageQueue = messageQueue + self._client = client + self._initHelper = InitHelper() + self._finished = False + + def run(self): + self._getPlannedMounting() + while not self._finished: + self._processMessage() + + def _getPlannedMounting(self): + self._client.sendCommand('getPlannedMountings', None) + + def _getObjectMounting(self, planId, buildingId): + data = {'plannedMountingId': planId, 'objectId': buildingId} + self._client.sendCommand('getObjectMounting', data) + + def _processMessage(self): + jsonObject = self._messageQueue.get() + messageType = jsonObject['type'] + + if messageType == 'plannedMountings': + self._handlePlannedMountings(jsonObject) + elif messageType == 'objectMounting': + self._handleObjectMounting(jsonObject) + elif messageType == 'error': + print('Service responded with error: {}'.format(jsonObject['data']['errorMessage'])) + sys.exit(1) + + def _handlePlannedMountings(self, jsonObject): + mountings = jsonObject['data'] + for m in mountings: + self._handlePlannedMounting(m) + + # Falls es keine Pläne gibt oder alle Pläne noch leer sind, werden ja keine + # getObjectMounting-Anfragen gemacht. Für den Fall müssen wir hier explizit + # self._finished auf True setzen. + if self._initHelper.pendingCount == 0: + self._finished = True + + def _handlePlannedMounting(self, dataObject): + data = DictAccess(dataObject) + planId = data.plannedMountingId + name = data.designation + MountingPlan.create(planId, name) + + buildings = data.mounting + for building in buildings: + buildingId = building['id'] + self._getObjectMounting(planId, buildingId) + self._initHelper.push() + + def _handleObjectMounting(self, jsonObject): + data = jsonObject['data'] + plan = mountingPlans.findById(data['plannedMountingId']) + mps = [] + for mp in data['planned']: + mps.append(mountingPoints.findById(mp['id'])) + plan.add(mps) + self._finished = self._initHelper.pop() + + +# +# Hilfsklasse für das Abfragen des ISM-Ports über das WebSocket-Interface +# des ServiceManagements. +# +class IsmPortFinder(object): + def __init__(self, messageQueue, client): + self._messageQueue = messageQueue + self._sender = client + self._ismPort = None + self._finished = False + + @property + def port(self): + assert self._ismPort is not None + return self._ismPort + + def run(self): + self._waitForConnected() + while not self._finished: + self._processMessage() + + # + # Die erste Message in der Queue ist ein internes Command -- einfach nur ein String. + # Das ist für uns das Signal, dass wir mit dem Server verbunden sind und + # die Initialisierung via getEssentials starten können. + # + def _waitForConnected(self): + internalCommand = self._messageQueue.get() + assert internalCommand == 'connected' + self._getPortInfo() + + def _processMessage(self): + jsonObject = self._messageQueue.get() + messageType = jsonObject['type'] + assert messageType == 'servicePortsInformation' + self._handlePortInfo(jsonObject) + + def _getPortInfo(self): + self._sender.sendCommand('servicePortsInformationRequest', None) + + def _handlePortInfo(self, jsonObject): + data = jsonObject['data'] + for exerciseInfo in [DictAccess(d) for d in data]: + if exerciseInfo.exerciseId != 0: + continue + for serviceInfo in [DictAccess(d) for d in exerciseInfo.services]: + if serviceInfo.nameAbbrevation != 'ism': + continue + assert len(serviceInfo.ports) == 1 # Wie finden wir den gewünschten Port, wenn es mehrere gibt? + self._ismPort = serviceInfo.ports[0]['number'] + break + assert self._ismPort is not None + self._finished = True + + +# +# Kleine Hilfsklasse, die einfach nur auf die Ok- oder Error-Reponse +# wartet, die z.B. auf ein mount-Command gesendet wird. +# +class ResponseWaiter(object): + # + # @param uuid: die UUID des Commands, auf dessen Response wir warten. + # + def __init__(self, messageQueue, uuid): + self._messageQueue = messageQueue + self._uuid = uuid + + def wait(self): + while True: + jsonObject = self._messageQueue.get() + messageType = jsonObject['type'] + data = DictAccess(jsonObject['data']) + if data.uuid != str(self._uuid): + continue + if messageType == 'ok': + return True, data.info + if messageType == 'error': + return False, data.errorMessage + assert False, 'Response must be either ok or error' + + +@contextmanager +def autoClose(client): + try: + yield client + finally: + client.close() + +@contextmanager +def autoJoin(thread): + try: + yield thread + finally: + thread.join() + + +def _mainList(args, messageQueue, client): + for b in sorted(buildings.findAll(), key=lambda b: b.name): + mseId = '' + if b.mseId is not None: + mseId = ', mseId: {}'.format(b.mseId) + print('Building: {}({}{})'.format(b.name, b.id, mseId)) + return 0 + + +def _mainListBuildingByName(args, messageQueue, client): + print(buildings.findByName(args.building)) + return 0 + + +def _mainListBuildingById(args, messageQueue, client): + print(buildings.findById(args.buildingId)) + return 0 + + +def _mainListAssets(args, messageQueue, client): + for a in sorted(assets.findAll(), key=lambda a: a.type): + print(a) + return 0 + + +def _mainMountByName(args, messageQueue, client): + building = None + if args.building is not None: + building = buildings.findByName(args.building) + return _mountByName(args.asset, args.mountingPoint, building, messageQueue, client) + + +def _mainMountById(args, messageQueue, client): + asset = assets.findById(args.assetId) + mountingPoint = mountingPoints.findById(args.mountingPointId) + return _mount(asset, mountingPoint, messageQueue, client) + + +def _mainMountBarcode(args, messageQueue, client): + data = {'assetTag': args.asset, 'mountingPointTag': args.mountingPoint} + uuid = client.sendCommand('mountTag', data) + + waiter = ResponseWaiter(messageQueue, uuid) + return _waitForRequest(waiter, 'mounted successfully', 'mounting failed') + + +def _mainMountManyByName(args, messageQueue, client): + building = None + if args.building is not None: + building = buildings.findByName(args.building) + jsonList = json.loads(args.json) + for assetMountingPoint in jsonList: + assetName = assetMountingPoint[0] + mountingPointName = assetMountingPoint[1] + status = _mountByName(assetName, mountingPointName, building, messageQueue, client) + if status != 0: + return status + return 0 + + +def _findMountingPointByName(name, buildingContext=None): + if buildingContext is None: + return mountingPoints.findByName(name) + else: + return buildingContext.findMountingPointByName(name) + +def _mountByName(assetName, mountingPointName, building, messageQueue, client): + asset = assets.findByName(assetName) + mountingPoint = _findMountingPointByName(mountingPointName, building) + return _mount(asset, mountingPoint, messageQueue, client) + +def _mount(asset, mountingPoint, messageQueue, client): + print('mounting {}({}) -> {}({})'.format(asset.name, asset.id, mountingPoint.name, mountingPoint.id)) + + data = {'assetId': asset.id, 'mountingPointId': mountingPoint.id} + uuid = client.sendCommand('mount', data) + + waiter = ResponseWaiter(messageQueue, uuid) + return _waitForRequest(waiter, 'mounted successfully', 'mounting failed') + + +def _mainUnmountAssetByName(args, messageQueue, client): + asset = assets.findByName(args.asset) + return _unmountMountingPoint(asset.mountingPoint, messageQueue, client) + + +def _mainUnmountAssetById(args, messageQueue, client): + asset = assets.findById(args.assetId) + return _unmountMountingPoint(asset.mountingPoint, messageQueue, client) + + +def _mainUnmountMountingPointByName(args, messageQueue, client): + building = None + if args.building is not None: + building = buildings.findByName(args.building) + mountingPoint = _findMountingPointByName(args.mountingPoint, building) + return _unmountMountingPoint(mountingPoint, messageQueue, client) + + +def _mainUnmountMountingPointById(args, messageQueue, client): + mountingPoint = mountingPoints.findById(args.mountingPointId) + return _unmountMountingPoint(mountingPoint, messageQueue, client) + + +def _mainUnmountBuildingByName(args, messageQueue, client): + building = buildings.findByName(args.building) + return _unmountBuilding(building, messageQueue, client) + + +def _mainUnmountBuildingById(args, messageQueue, client): + building = buildings.findById(args.buildingId) + return _unmountBuilding(building, messageQueue, client) + + +def _unmountBuilding(building, messageQueue, client): + for mountingPoint in building.mountingPoints(): + if not mountingPoint.isMounted: + continue + status = _unmountMountingPoint(mountingPoint, messageQueue, client) + if status != 0: + return status + return 0 + + +def _mainUnmountAll(args, messageQueue, client): + for a in assets.findAll(): + if not a.isMounted: + continue + status = _unmountMountingPoint(a.mountingPoint, messageQueue, client) + if status != 0: + return status + return 0 + + +def _unmountMountingPoint(mountingPoint, messageQueue, client): + asset = mountingPoint.asset + print('unmounting {}({}) from {}({})'.format(asset.name, asset.id, mountingPoint.name, mountingPoint.id)) + data = {'mountingPointId': mountingPoint.id} + uuid = client.sendCommand('unmountMountingPoint', data) + waiter = ResponseWaiter(messageQueue, uuid) + return _waitForRequest(waiter, 'unmounted successfully', 'unmounting failed') + + +def _mainListMountingPlans(args, messageQueue, client): + planInitializer = PlanInitializer(messageQueue, client) + planInitializer.run() + + if len(mountingPlans) == 0: + print('No mounting plans available') + return 0 + + for p in mountingPlans.findAll(): + print('Plan: {}({})'.format(p.name, p.id)) + return 0 + + +def _mainListMountingPlanByName(args, messageQueue, client): + planInitializer = PlanInitializer(messageQueue, client) + planInitializer.run() + + plan = mountingPlans.findByName(args.plan) + print(plan) + + +def _mainListMountingPlanById(args, messageQueue, client): + planInitializer = PlanInitializer(messageQueue, client) + planInitializer.run() + + plan = mountingPlans.findById(args.planId) + print(plan) + + +def _waitForRequest(waiter, okMessage, errorMessage): + status, info = waiter.wait() + if status: + print(okMessage) + return 0 + else: + print('{}: {}'.format(errorMessage, info)) + return 1 + + +def _parseCmdLine(): + description = 'hello' + parser = ArgumentParser(description=description, formatter_class=RawDescriptionHelpFormatter) + + sharedArgs = ArgumentParser(add_help=False) + sharedArgs.add_argument('--host', default='localhost', help='hostname/ip; default: localhost') + sharedArgs.add_argument('--port', type=int, help='ISM port; if not given, the port will be determined via SCM WebSocket interface on port 7300') + sharedArgs.add_argument('--log-messages', '-l', action='store_true', default=False, dest='doLog', help='log ingoing and outgoing messages') + + subparsers = parser.add_subparsers() + + parser_list = subparsers.add_parser('list', parents=[sharedArgs], help='list all buildings', description='List buildings.') + parser_list.set_defaults(commandFunc=_mainList) + + parser_listBuildingByName = subparsers.add_parser('list-building', parents=[sharedArgs], help='list a building', description='List all mounting points for a given building.') + parser_listBuildingByName.add_argument('building', help='name of building') + parser_listBuildingByName.set_defaults(commandFunc=_mainListBuildingByName) + + parser_listBuildingById = subparsers.add_parser('list-building-by-id', parents=[sharedArgs], help='list a building by ID', description='List all mounting points for a given building.') + parser_listBuildingById.add_argument('buildingId', type=int, help='building ID') + parser_listBuildingById.set_defaults(commandFunc=_mainListBuildingById) + + parser_listAssets = subparsers.add_parser('list-assets', parents=[sharedArgs], help='list all assets', description='List all assets.') + parser_listAssets.set_defaults(commandFunc=_mainListAssets) + + + parser_mountByName = subparsers.add_parser('mount', parents=[sharedArgs], help='mount asset', description='Mount an asset to a mounting point by name.') + parser_mountByName.add_argument('asset', help='name of asset') + parser_mountByName.add_argument('mountingPoint', help='name of mounting point') + parser_mountByName.add_argument('--building', help='search for mounting point in the building with that name in case the name is not globally unique') + parser_mountByName.set_defaults(commandFunc=_mainMountByName) + + parser_mountById = subparsers.add_parser('mount-by-id', parents=[sharedArgs], help='mount by ID', description='Mount an asset to a mounting point by ID') + parser_mountById.add_argument('assetId', type=int, help='ID of asset') + parser_mountById.add_argument('mountingPointId', type=int, help='ID of mounting point') + parser_mountById.set_defaults(commandFunc=_mainMountById) + + parser_mountBarcode = subparsers.add_parser('mount-barcode', parents=[sharedArgs], help='mount asset via barcode', description='Mount an asset to a mounting point by barcode.') + parser_mountBarcode.add_argument('asset', help='barcode of asset') + parser_mountBarcode.add_argument('mountingPoint', help='barcode of mounting point') + parser_mountBarcode.set_defaults(commandFunc=_mainMountBarcode) + + parser_mountManyByName = subparsers.add_parser('mount-many', parents=[sharedArgs], help='mount many assets', description='Mount several assets to mounting points at once using their names.') + parser_mountManyByName.add_argument('json', help='JSON list of asset-mounting point pairs, e.g. [ ["asset1", "mp1"], ["asset2", "mp2"] ]') + parser_mountManyByName.add_argument('--building', help='search for mounting point in the building with that name in case the name is not globally unique') + parser_mountManyByName.set_defaults(commandFunc=_mainMountManyByName) + + parser_unmountAssetByName = subparsers.add_parser('unmount-asset', parents=[sharedArgs], help='unmout asset', description='Unmount an asset by name.') + parser_unmountAssetByName.add_argument('asset', help='name of asset') + parser_unmountAssetByName.set_defaults(commandFunc=_mainUnmountAssetByName) + + parser_unmountAssetById = subparsers.add_parser('unmount-asset-by-id', parents=[sharedArgs], help='unmout asset by ID', description='Unmount an asset by ID.') + parser_unmountAssetById.add_argument('assetId', type=int, help='ID of asset') + parser_unmountAssetById.set_defaults(commandFunc=_mainUnmountAssetById) + + parser_unmountMountingPointByName = subparsers.add_parser('unmount-mounting-point', parents=[sharedArgs], help='unmout mounting point', description='Unmount a mounting point by name.') + parser_unmountMountingPointByName.add_argument('mountingPoint', help='name of mounting point') + parser_unmountMountingPointByName.add_argument('--building', help='search for mounting point in the building with that name in case the name is not globally unique') + parser_unmountMountingPointByName.set_defaults(commandFunc=_mainUnmountMountingPointByName) + + parser_unmountMountingPointById = subparsers.add_parser('unmount-mounting-point-by-id', parents=[sharedArgs], help='unmout mounting point', description='Unmount a mounting point by ID.') + parser_unmountMountingPointById.add_argument('mountingPointId', type=int, help='ID of mounting point') + parser_unmountMountingPointById.set_defaults(commandFunc=_mainUnmountMountingPointById) + + parser_unmountBuildingByName = subparsers.add_parser('unmount-building', parents=[sharedArgs], help='unmount building', description='Unmount all assets in a building.') + parser_unmountBuildingByName.add_argument('building', help='name of building') + parser_unmountBuildingByName.set_defaults(commandFunc=_mainUnmountBuildingByName) + + parser_unmountBuildingById = subparsers.add_parser('unmount-building-by-id', parents=[sharedArgs], help='unmount building by ID', description='Unmount all assets in a building.') + parser_unmountBuildingById.add_argument('buildingId', type=int, help='ID of building') + parser_unmountBuildingById.set_defaults(commandFunc=_mainUnmountBuildingById) + + parser_unmountAll = subparsers.add_parser('unmount-all', parents=[sharedArgs], help='unmount all assets', description='Unmount all assets.') + parser_unmountAll.set_defaults(commandFunc=_mainUnmountAll) + + + parser_listPlans = subparsers.add_parser('list-plans', parents=[sharedArgs], help='list available mounting plans', description='List available mounting plans') + parser_listPlans.set_defaults(commandFunc=_mainListMountingPlans) + + parser_listPlanByName = subparsers.add_parser('list-plan', parents=[sharedArgs], help='list a mounting plan', description='List a mounting plan.') + parser_listPlanByName.add_argument('plan', help='name of plan') + parser_listPlanByName.set_defaults(commandFunc=_mainListMountingPlanByName) + + parser_listPlanById = subparsers.add_parser('list-plan-by-id', parents=[sharedArgs], help='list a mounting plan by ID', description='List a mounting plan by ID.') + parser_listPlanById.add_argument('planId', type=int, help='ID of plan') + parser_listPlanById.set_defaults(commandFunc=_mainListMountingPlanById) + + return parser.parse_args() + + +# +# Herausfinden des ISM-Ports über das Abfragen der WebSocket-Schnittstelle +# des ServiceManagements. +# +def _determineIsmPort(args): + messageQueue = Queue() + client = WsClient(args.host, 7300, messageQueue, args.doLog) # SCM-Port is fix + + portFinder = IsmPortFinder(messageQueue, client) + + clientThread = Thread(target=client.run) + clientThread.start() + + with autoJoin(clientThread): + with autoClose(client): + portFinder.run() # beendet sich, wenn der Port gefunden wurde + + return portFinder.port + + +def _main(): + args = _parseCmdLine() + + ismPort = args.port + if ismPort is None: + ismPort = _determineIsmPort(args) + + messageQueue = Queue() + + client = WsClient(args.host, ismPort, messageQueue, args.doLog) + initializer = Initializer(messageQueue, client) + + clientThread = Thread(target=client.run) + clientThread.start() + + with autoJoin(clientThread): + with autoClose(client): + initializer.run() # beendet sich, wenn initialisiert + retVal = args.commandFunc(args, messageQueue, client) + + return retVal + +if __name__ == '__main__': + sys.exit(_main()) diff --git a/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/AhtcSymbols/ahtcSymbols2Sql.py b/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/AhtcSymbols/ahtcSymbols2Sql.py new file mode 100755 index 000000000..31c46a549 --- /dev/null +++ b/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/AhtcSymbols/ahtcSymbols2Sql.py @@ -0,0 +1,184 @@ +#!/usr/bin/python +import os +import re +import sys +import shutil + +if len(sys.argv) != 2 and len(sys.argv) != 4 : + print("Usage %s [path to ahtc_ppm_values_types.sql]" % sys.argv[0]) + sys.exit + +dirPath = os.path.abspath(sys.argv[1]) + +if not os.path.isdir(dirPath) : + print("directory \"%s\" doesn't exists. Abort ..." % dirPath) + sys.exit + +fdSql = open("ahtc_flm_symbols.sql", "wt") + +maxId = -1 +nameDict = {} +idDict = {} +symbolCount = 0 + +print ("\nParsing XML symbol definitions:") + +for fileN in os.listdir(dirPath) : + symbolId = -1 + if fileN.endswith(".xml") : + fd = open(dirPath + "/"+ fileN,"rt") + xmlContent = fd.read() + fd.close() + + # print(xmlContent) + + idBegin = xmlContent.find("id=\"") + idEnd = xmlContent.find("\"",idBegin+4) + + if idBegin > 0 and idEnd > 0 : + idBegin = idBegin + 4 + symbolId = int(xmlContent[idBegin:idEnd],0) + + if symbolId >= 0 : + + if symbolId > maxId : + maxId = symbolId + + nameBegin = xmlContent.find("") + nameEnd = xmlContent.find("") + + name = "" + if nameBegin > 0 and nameEnd > 0 : + nameBegin = nameBegin + 6 + name = xmlContent[nameBegin:nameEnd] + else : + name = "noname" + + nameCount = nameDict.get(name,0) + 1 + nameDict[name] = nameCount + + if nameCount > 1 : + name = name +"(" + str(nameCount)+")" + + symbolCount = symbolCount+1 + + print(" [%3d] : Insert symbol %s with id=%d to sql database" % (symbolCount,name,symbolId) ) + + fdSql.write("INSERT INTO flm.flm_file_content (id, name, folder_id, file_category_id, file_type_id, file_status_id, operator_id, is_used_by, used_by, properties )") + fdSql.write(" VALUES (" + str(symbolId) + ",'" + name + "', 30, 1, 8, 0, 99, true, 1, '{\"imageFormat\": \"xml\"}');\n") + + symbolPath = "@CMAKE_SOURCE_DIR@/Lts/Tests/DatabaseInitialisation/AhtcSymbols/" + fileN + fdSql.write("UPDATE flm.flm_file_content SET content = ( SELECT bytea_import('" + symbolPath + "')) WHERE id = " + str(symbolId) + "; \n") + +maxId = maxId + 1 +fdSql.write("ALTER SEQUENCE flm.flm_file_content_id_seq RESTART WITH " + str(maxId) + ";") + +fdSql.close() + +print("\n"+str(symbolCount)+" symbols added to sql script") + +if len(sys.argv) == 4 : + + typeDump = os.path.abspath(sys.argv[2]) + + if not os.path.exists(typeDump) : + print("types dump file \"%s\" doesn't exists. Abort ..." % typeDump) + sys.exit + + print("\nParsing db type dump \"%s\" ..." % typeDump) + + fdTypen = open(typeDump,"rt") + + while True: + + line = fdTypen.readline() + if (line == "") : + break + typeDataList = line.split("|") + if len(typeDataList) > 4 : + name = typeDataList[2] + symbolId = int(typeDataList[3]) + if symbolId > 0 : + nameId = re.sub(r"\s+", "", name, flags=re.UNICODE) + idDict[nameId] = symbolId + print(nameId + " ---> " + str(idDict[nameId])) + fdTypen.close() + + # ------------------------------------------------------------------------------------------- + + print("\nModify ahtc_ppm_values_types.sql ...") + + ppm_script_template = os.path.abspath(sys.argv[3]) + "/ahtc_ppm_values_types.sql" + ppm_script = os.path.abspath(sys.argv[3]) + "/ahtc_ppm_values_types_with_symbols.sql" + flm_script = os.path.abspath(sys.argv[3]) + "/update_flm_used_by.sql" + + fdRead = open( ppm_script_template,"rt") + fdWrite = open( ppm_script,"wt") + fdFlmWrite = open(flm_script, "wt") + flm_update_lines = set() + + ppmValueCnt = 0 + changeLine = False + while True: + + line = fdRead.readline() + + if (line == "") : + break + + flmLine = "" + + if line.startswith("INSERT INTO ppm.ppm_type (") : + fdWrite.write(line) + changeLine = True + continue + + if line.startswith(" VALUES (") and changeLine == True : + nameBegin = line.find("'") + 1 + nameEnd = line.find("'",nameBegin) + sidc = "" + if nameBegin > 0 and nameEnd > 0 : + name = line[nameBegin:nameEnd] + name = re.sub(r"\s+", "", name, flags=re.UNICODE) + + keyName = name + + for key in idDict : + if key != "" : + if name.startswith(key): + keyName = key + break + if key.startswith("BPz3B") and name.startswith("BPz3B"): + keyName = key + break + if idDict.get(keyName,0) > 0 : + symbolBegin = line.find("'",nameEnd+1)+1 + symbolEnd = line.find("'",symbolBegin) + + if symbolBegin == symbolEnd : + sidc = "NONE|CVLX|" + str(idDict.get(keyName,0)) + tmpLine = line[:symbolBegin]+sidc+line[symbolEnd:] + line = tmpLine + ppmValueCnt += 1 + else : + sidc = line[symbolBegin:symbolEnd] # only for logging + + flmLine = "UPDATE flm.flm_file_content SET used_by = ( SELECT COUNT(*) FROM ppm.ppm_type WHERE symbol = '"+ sidc + "') WHERE id = "+str(idDict.get(keyName,0))+"; \n" + if flmLine not in flm_update_lines: + fdFlmWrite.write(flmLine) + flm_update_lines.add(flmLine) + + if sidc == "" : + print("\"" + name + "\" not found in db type dump." ) + print(name + " : " + sidc) + + fdWrite.write(line) + changeLine = False + + fdWrite.close() + fdRead.close() + + fdFlmWrite.write("UPDATE flm.flm_file_content SET is_used_by = true WHERE used_by > 0; \n") + fdFlmWrite.close() + + print("\n%d symbols added to ppm types\n" % ppmValueCnt) diff --git a/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/ComMasterSymbols/guezSymbols2Sql.py b/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/ComMasterSymbols/guezSymbols2Sql.py new file mode 100755 index 000000000..8bbe903f9 --- /dev/null +++ b/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/ComMasterSymbols/guezSymbols2Sql.py @@ -0,0 +1,184 @@ +#!/usr/bin/python +import os +import re +import sys +import shutil + +if len(sys.argv) != 2 and len(sys.argv) != 4 : + print("Usage %s [path to insert_ppm_values_types.sql]" % sys.argv[0]) + sys.exit + +dirPath = os.path.abspath(sys.argv[1]) + +if not os.path.isdir(dirPath) : + print("directory \"%s\" doesn't exists. Abort ..." % dirPath) + sys.exit + +fdSql = open("guez_flm_symbols.sql", "wt") + +maxId = -1 +nameDict = {} +idDict = {} +symbolCount = 0 + +print ("\nParsing XML symbol definitions:") + +for fileN in os.listdir(dirPath) : + symbolId = -1 + if fileN.endswith(".xml") : + fd = open(dirPath + "/"+ fileN,"rt") + xmlContent = fd.read() + fd.close() + + # print(xmlContent) + + idBegin = xmlContent.find("id=\"") + idEnd = xmlContent.find("\"",idBegin+4) + + if idBegin > 0 and idEnd > 0 : + idBegin = idBegin + 4 + symbolId = int(xmlContent[idBegin:idEnd],0) + + if symbolId >= 0 : + + if symbolId > maxId : + maxId = symbolId + + nameBegin = xmlContent.find("") + nameEnd = xmlContent.find("") + + name = "" + if nameBegin > 0 and nameEnd > 0 : + nameBegin = nameBegin + 6 + name = xmlContent[nameBegin:nameEnd] + else : + name = "noname" + + nameCount = nameDict.get(name,0) + 1 + nameDict[name] = nameCount + + if nameCount > 1 : + name = name +"(" + str(nameCount)+")" + + symbolCount = symbolCount+1 + + print(" [%3d] : Insert symbol %s with id=%d to sql database" % (symbolCount,name,symbolId) ) + + fdSql.write("INSERT INTO flm.flm_file_content (id, name, folder_id, file_category_id, file_type_id, file_status_id, operator_id, is_used_by, used_by, properties )") + fdSql.write(" VALUES (" + str(symbolId) + ",'" + name + "', 30, 1, 8, 0, 99, true, 1, '{\"imageFormat\": \"xml\"}');\n") + + symbolPath = "@CMAKE_SOURCE_DIR@/Lts/Tests/DatabaseInitialisation/GuezSymbols/" + fileN + fdSql.write("UPDATE flm.flm_file_content SET content = ( SELECT bytea_import('" + symbolPath + "')) WHERE id = " + str(symbolId) + "; \n") + +maxId = maxId + 1 +fdSql.write("ALTER SEQUENCE flm.flm_file_content_id_seq RESTART WITH " + str(maxId) + ";") + +fdSql.close() + +print("\n"+str(symbolCount)+" symbols added to sql script") + +if len(sys.argv) == 4 : + + typeDump = os.path.abspath(sys.argv[2]) + + if not os.path.exists(typeDump) : + print("types dump file \"%s\" doesn't exists. Abort ..." % typeDump) + sys.exit + + print("\nParsing db type dump \"%s\" ..." % typeDump) + + fdTypen = open(typeDump,"rt") + + while True: + + line = fdTypen.readline() + if (line == "") : + break + typeDataList = line.split("|") + if len(typeDataList) > 4 : + name = typeDataList[2] + symbolId = int(typeDataList[3]) + if symbolId > 0 : + nameId = re.sub(r"\s+", "", name, flags=re.UNICODE) + idDict[nameId] = symbolId + print(nameId + " ---> " + str(idDict[nameId])) + fdTypen.close() + + # ------------------------------------------------------------------------------------------- + + print("\nModify insert_ppm_values_types.sql ...") + + ppm_script_template = os.path.abspath(sys.argv[3]) + "/insert_ppm_values_types.sql" + ppm_script = os.path.abspath(sys.argv[3]) + "/insert_ppm_values_types_with_symbols.sql" + flm_script = os.path.abspath(sys.argv[3]) + "/update_flm_used_by.sql" + + fdRead = open( ppm_script_template,"rt") + fdWrite = open( ppm_script,"wt") + fdFlmWrite = open(flm_script, "wt") + flm_update_lines = set() + + ppmValueCnt = 0 + changeLine = False + while True: + + line = fdRead.readline() + + if (line == "") : + break + + flmLine = "" + + if line.startswith("INSERT INTO ppm.ppm_type (") : + fdWrite.write(line) + changeLine = True + continue + + if line.startswith(" VALUES (") and changeLine == True : + nameBegin = line.find("'") + 1 + nameEnd = line.find("'",nameBegin) + sidc = "" + if nameBegin > 0 and nameEnd > 0 : + name = line[nameBegin:nameEnd] + name = re.sub(r"\s+", "", name, flags=re.UNICODE) + + keyName = name + + for key in idDict : + if key != "" : + if name.startswith(key): + keyName = key + break + if key.startswith("BPz3B") and name.startswith("BPz3B"): + keyName = key + break + if idDict.get(keyName,0) > 0 : + symbolBegin = line.find("'",nameEnd+1)+1 + symbolEnd = line.find("'",symbolBegin) + + if symbolBegin == symbolEnd : + sidc = "NONE|CVLX|" + str(idDict.get(keyName,0)) + tmpLine = line[:symbolBegin]+sidc+line[symbolEnd:] + line = tmpLine + ppmValueCnt += 1 + else : + sidc = line[symbolBegin:symbolEnd] # only for logging + + flmLine = "UPDATE flm.flm_file_content SET used_by = ( SELECT COUNT(*) FROM ppm.ppm_type WHERE symbol = '"+ sidc + "') WHERE id = "+str(idDict.get(keyName,0))+"; \n" + if flmLine not in flm_update_lines: + fdFlmWrite.write(flmLine) + flm_update_lines.add(flmLine) + + if sidc == "" : + print("\"" + name + "\" not found in db type dump." ) + print(name + " : " + sidc) + + fdWrite.write(line) + changeLine = False + + fdWrite.close() + fdRead.close() + + fdFlmWrite.write("UPDATE flm.flm_file_content SET is_used_by = true WHERE used_by > 0; \n") + fdFlmWrite.close() + + print("\n%d symbols added to ppm types\n" % ppmValueCnt) diff --git a/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/GuezSymbols/guezSymbols2Sql.py b/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/GuezSymbols/guezSymbols2Sql.py new file mode 100755 index 000000000..8bbe903f9 --- /dev/null +++ b/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/GuezSymbols/guezSymbols2Sql.py @@ -0,0 +1,184 @@ +#!/usr/bin/python +import os +import re +import sys +import shutil + +if len(sys.argv) != 2 and len(sys.argv) != 4 : + print("Usage %s [path to insert_ppm_values_types.sql]" % sys.argv[0]) + sys.exit + +dirPath = os.path.abspath(sys.argv[1]) + +if not os.path.isdir(dirPath) : + print("directory \"%s\" doesn't exists. Abort ..." % dirPath) + sys.exit + +fdSql = open("guez_flm_symbols.sql", "wt") + +maxId = -1 +nameDict = {} +idDict = {} +symbolCount = 0 + +print ("\nParsing XML symbol definitions:") + +for fileN in os.listdir(dirPath) : + symbolId = -1 + if fileN.endswith(".xml") : + fd = open(dirPath + "/"+ fileN,"rt") + xmlContent = fd.read() + fd.close() + + # print(xmlContent) + + idBegin = xmlContent.find("id=\"") + idEnd = xmlContent.find("\"",idBegin+4) + + if idBegin > 0 and idEnd > 0 : + idBegin = idBegin + 4 + symbolId = int(xmlContent[idBegin:idEnd],0) + + if symbolId >= 0 : + + if symbolId > maxId : + maxId = symbolId + + nameBegin = xmlContent.find("") + nameEnd = xmlContent.find("") + + name = "" + if nameBegin > 0 and nameEnd > 0 : + nameBegin = nameBegin + 6 + name = xmlContent[nameBegin:nameEnd] + else : + name = "noname" + + nameCount = nameDict.get(name,0) + 1 + nameDict[name] = nameCount + + if nameCount > 1 : + name = name +"(" + str(nameCount)+")" + + symbolCount = symbolCount+1 + + print(" [%3d] : Insert symbol %s with id=%d to sql database" % (symbolCount,name,symbolId) ) + + fdSql.write("INSERT INTO flm.flm_file_content (id, name, folder_id, file_category_id, file_type_id, file_status_id, operator_id, is_used_by, used_by, properties )") + fdSql.write(" VALUES (" + str(symbolId) + ",'" + name + "', 30, 1, 8, 0, 99, true, 1, '{\"imageFormat\": \"xml\"}');\n") + + symbolPath = "@CMAKE_SOURCE_DIR@/Lts/Tests/DatabaseInitialisation/GuezSymbols/" + fileN + fdSql.write("UPDATE flm.flm_file_content SET content = ( SELECT bytea_import('" + symbolPath + "')) WHERE id = " + str(symbolId) + "; \n") + +maxId = maxId + 1 +fdSql.write("ALTER SEQUENCE flm.flm_file_content_id_seq RESTART WITH " + str(maxId) + ";") + +fdSql.close() + +print("\n"+str(symbolCount)+" symbols added to sql script") + +if len(sys.argv) == 4 : + + typeDump = os.path.abspath(sys.argv[2]) + + if not os.path.exists(typeDump) : + print("types dump file \"%s\" doesn't exists. Abort ..." % typeDump) + sys.exit + + print("\nParsing db type dump \"%s\" ..." % typeDump) + + fdTypen = open(typeDump,"rt") + + while True: + + line = fdTypen.readline() + if (line == "") : + break + typeDataList = line.split("|") + if len(typeDataList) > 4 : + name = typeDataList[2] + symbolId = int(typeDataList[3]) + if symbolId > 0 : + nameId = re.sub(r"\s+", "", name, flags=re.UNICODE) + idDict[nameId] = symbolId + print(nameId + " ---> " + str(idDict[nameId])) + fdTypen.close() + + # ------------------------------------------------------------------------------------------- + + print("\nModify insert_ppm_values_types.sql ...") + + ppm_script_template = os.path.abspath(sys.argv[3]) + "/insert_ppm_values_types.sql" + ppm_script = os.path.abspath(sys.argv[3]) + "/insert_ppm_values_types_with_symbols.sql" + flm_script = os.path.abspath(sys.argv[3]) + "/update_flm_used_by.sql" + + fdRead = open( ppm_script_template,"rt") + fdWrite = open( ppm_script,"wt") + fdFlmWrite = open(flm_script, "wt") + flm_update_lines = set() + + ppmValueCnt = 0 + changeLine = False + while True: + + line = fdRead.readline() + + if (line == "") : + break + + flmLine = "" + + if line.startswith("INSERT INTO ppm.ppm_type (") : + fdWrite.write(line) + changeLine = True + continue + + if line.startswith(" VALUES (") and changeLine == True : + nameBegin = line.find("'") + 1 + nameEnd = line.find("'",nameBegin) + sidc = "" + if nameBegin > 0 and nameEnd > 0 : + name = line[nameBegin:nameEnd] + name = re.sub(r"\s+", "", name, flags=re.UNICODE) + + keyName = name + + for key in idDict : + if key != "" : + if name.startswith(key): + keyName = key + break + if key.startswith("BPz3B") and name.startswith("BPz3B"): + keyName = key + break + if idDict.get(keyName,0) > 0 : + symbolBegin = line.find("'",nameEnd+1)+1 + symbolEnd = line.find("'",symbolBegin) + + if symbolBegin == symbolEnd : + sidc = "NONE|CVLX|" + str(idDict.get(keyName,0)) + tmpLine = line[:symbolBegin]+sidc+line[symbolEnd:] + line = tmpLine + ppmValueCnt += 1 + else : + sidc = line[symbolBegin:symbolEnd] # only for logging + + flmLine = "UPDATE flm.flm_file_content SET used_by = ( SELECT COUNT(*) FROM ppm.ppm_type WHERE symbol = '"+ sidc + "') WHERE id = "+str(idDict.get(keyName,0))+"; \n" + if flmLine not in flm_update_lines: + fdFlmWrite.write(flmLine) + flm_update_lines.add(flmLine) + + if sidc == "" : + print("\"" + name + "\" not found in db type dump." ) + print(name + " : " + sidc) + + fdWrite.write(line) + changeLine = False + + fdWrite.close() + fdRead.close() + + fdFlmWrite.write("UPDATE flm.flm_file_content SET is_used_by = true WHERE used_by > 0; \n") + fdFlmWrite.close() + + print("\n%d symbols added to ppm types\n" % ppmValueCnt) diff --git a/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/__pycache__/create_excon_db.cpython-310.pyc b/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/__pycache__/create_excon_db.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..591855013c92776bb137adf4c11de9dd56378bf8 GIT binary patch literal 18524 zcmc(HTW}oLncj3y&wX&=fCO(6)x1dyv#H8}efr#Q|9}4T-%H zP?k!4H=$Ba@k#RjkV>n}cN6!ARaWKj9&tuh{(Yq5QyI#{U`dr!7T%bU zO5>eU8I{F5t#T@lcSe;}Q4M|9z;cGw2y$}B8C6G+lUF4*hMa;rs*d4ZRO9M6-b3ny zI*IqNI;BqIJ))jd&*MF+E~yukjh08$S#=IMC3Rk1zs-9OfF!|0eg$N(6%rjA<6757qhlVl`HP^+!@g6#^2Sf^9;*KMu3)eU>D-f+C>ySkUf zuiu{T1AvK*&*B*)0A57EiF|8h*YFeT#-1r*@&}2wv2X4hF1GJ?%q?><@oA!Lg=WhO zt<9>x7N+W+s=J}J-l{jtW@t`b4z0THY{HP@;7PQ`gtYc(rsd1~`PcX9rt->dZAS4Ud3&z4-BdQ~+V$p)jXg#*%yycDX;{3{x1GpZ}^yb+8Yf>||UUFXL*3F8eso{ylN z*uyQ>HpW5D44uM>jABV2XLUajmnHXc-$)Bw2m2sJhvqONx6hX-+L2x36;KjX& z8n5|T-&ASbivg6U$ol9W?!fh7TqM7a8I+Wi z0tJVOf^t`mHPH$sxG~p<;}Z5fjQpb!TH`L2-j1PGdLKtZ_aH4x{`mU%-f6i z?9VxhoIN?ZB>Tm+4gVX2j1<$vGseoIv!mm{)} zR?G9a{|2c-p3o#$5jZ!|kM}NuJdS_f$b-n2%)FTgIY^r&GaKbGKW`SLJZ}yQ*(f0| zYo0R3kt(6yQM4=?!Lc3^(jBLdau9n+ql9w24jKY1yv_%-V%=Ct z@`}LOHar{kQ=}lQA73P?xMeyzYZ19gFyht@UK*=Lj_R2KpXN?8M= z|NnvBxq*2Msq@I`LhnL9^wiBoeS$9zwCm#Ki@ha~w_jQ{ca!ZTAcQk8M-&w-&C?10xn@$(KU!Mb5Faz1Y{dn=hXuI)bm2 zsX?WL8N@sF+8<_C&Z7;P)6GB1oY0A$(PRuHK_;!|)dI6Uur-9+iH@`&B6UU9A@Xi; zAzE4oAbmZ>E44Y?p+W(n&Jmu0zbgWH-~|*d*yqaZ!or<}%HqH7l^awYo9bDM2b^zWI)4y~#hAq7%0vvpYdxbi8j$$v53#&e z$0Go%$br5Q%2pfdF05>8+i5~S5*=3V_;-H6$k%V*w(l;y_W`7_TeFKqa^?WdZzF}@ zd-L|5Ou;teK!*$D35Ql(jlPeOg>tX8@w9Z&tDwh<_jqHu z)eutjbnJZR_~U*AbSU3Hg|>9$TMz}s^Q=!xNjM4}HAtUR!Td#0?w(?q=pCr42$QPrbTts}980Nr2v2L& zr~saRSJSO=D9k~9DcyOZ#|V!_l?PPaqk3C)A6&6J$^NN%cV`ilGg_^g#B#!%X4GKr z2!}aaL0h7R7aA*2-%HF~X%1>RGSL!u(4qHl5tNKmrX@Pv1)r-W z(X{j9B4P!SwlGAh=TWMjX=&)HpSduf;w3EDPt4ygQSjVL!76A#kVi~ejD3g=u<-XJ z3DGk9YQlSY2f6(FChZZX`=*b6pCFI@$!4YIgLAhd20$2K$`Fsid64^QY%>C z1|CI(Dt*fsh6b-_Joj@eSv0KAgW>)yJz%Ygk%G!cB8A?agL~Ok<;xCO^TEgpj&H*j z6GOb*&j_q?N)xXB)oPXK49W+Wv4*^HE`vq|E(7+6-id=C^&tVP@eyqPO++*{6ZjgV zeb^ufa`(8O+_ShO4f_4WuGM_rPeS8nC=2g2o{UQU$m*5@;IFrn>)E{=YNz~sI|YO) zs5I>vu%~ApB;D(<+h-$G>n(waxtyDSI@)``P?DPyt@+ZY$uI>WveAHHN5hm05G)aT zACzWkt^qeByeTfHi(a{?x6)?Kvk1bxx4kTvvgd`VyMjR0PPOib*4_8+&W7p5rJHx| zExF%jT?;&d(#mNL1uPVsQLeV3VD!XY5f;3))=mZZwYlww#-_W$W+{Q`Ae49mohFoc ztBitP@oyZo(ZYLJs9e?vj`Sd$zM1-Pt`Bs3=%@=iIhDp9h!RXjF!1=M59bg7@r-Z5 zRAi_W-f28g?gC(Dvk>KH`t#f7UKXHBw$1h2UY;OtTYCipQ^v}+MRiCDpmG4_ZNCUp zkDse*tyrHT&-(4l$vk71rq%}FOPC$|KYb8Z`1OF_Y2UU2*w5!W>cj~@h~ zJpnKZl>Y~IFY#)5SU?(PTnEfi4ZyuX zzsDNiXFw3TKVV&pvl|5C3Q8_@z{txbk1LH}q~@Ps9LE#b2f#SMVDv#Xg+8-*1*lse0xpEbA}F$-dOV{kv7d&)khDFs zp4CTD0m68!Z^rd^z&y-Tx+l_WkxScI=D;VAK!xdBVs{UVHzU!19?FYww3B)lDh1{Q zXK%E&8_Fh8->kZxLklqMHCim>fj%qXg!#6pOQe$syKLj?b1N`Qf;S3tvyWD_cYO~Aq?`WBpR zNMn=GLYli7fHKvFg%+2k*-k$++}CjZraO5+hYV~x8PI6}8+B5s0}6;b*-o9U;Vtxn zgO{FvYLUqfjS6jn+P_4zleT6$3Dmi8WYB9Orw!_$ij44tf}xDZjBp|sNPmkWJTA=tW##)|6tmKOJRFUJoQoW?qv%wV&d!Yoc)-#QvYGTP z`h;Om39C2YHI}BA7~+@V7iR2bNbL4aq+cRDg;-jCZau$8i&e30!M_YWDCGO;&I{j-tSvbRobl`wV!SfIxq;;jmd7}-w%6Ta2X zpssiWY~9s9Y;v1^PuIYF#&@&+XgdQBw^8(+JqiD}2Pya4(k?64g9%%_#J1MDJ$R~3 zKLPj`0Bhj`aL$|3Zj=BPu6hdjL$9GiN1VRjBGSkV`Jv?G60 zpOHCozrx^m8DPs3<&q}erVHO9!XLE7O`;&Q=%AxfiWD%+LPS>J>)>a!>bABwdqgUc zb}q3}vf(t{KO@Z_IFBi_QkdOrZI*KpHwY^)`e=s5-dO`3w;CjC92Jftsg0^%TMI|y zI**rHQe0>{JB-|>^H35)4BQ6cIS<=Z=@Zf*+rqV~yG0)me_zKOaaG7Qp)vOrVDB)o z_kWw8r?X-rMyd$5^C(zQP@<2EKh0-?$=-|P7mn43@ZA2GDE(<9i17R5$w8RtK&s6n z>qO<(iTLZ5=I(cK6eN{y!`nz%ClhcD(K$rTtV+QMYXX^31~eZAIyQ;V}G z>KYI5Em?Q{{sDx3D*wjtNEUdJkmjNGP-_>uolG zjF0><1M1?z{;%B)R@sy;1(En6Vg|TEnT>X#%W*0a9Y7xU0owV*j&Ve?bP@nPI|`}z zD3}PqpH2b2j6_X#rXSn9zI%v_L=5u3fzOtSMFZ7)1!`jc+cz8R%KJMaQAQv*$ z5ZFQ-!Cf$cd@JnhZmMZ13pwC3v?H&0iGgJVL#TZ~aQEzHq|D;2<4s5P(j5jKSO8dy zFV`FJ9s|pWgAX4Ka44wnegm*fL3X2!G#5cp?z1SKqA0MJ*-x}nLJFi#6P_MuRlvQM z>E?oToss1E`0oR6LNMCS8ESU>Qx9 zg69PzaN;kbo&AAy(4&rg4!jUOpXTo@*>iX9&EF&&WKTeFgq(qUBR>9Gt0wBdS#+$i zh$s@Kw!r|o`rK=-$Nk65&#yEqbZ=a#KN77VJau&{EJP9d61pzyW>^<~yaV{;Hc;%ys2}F_i`P^s%mu z_T#&GztGNs>nUIc`H1UzEPdpK>q+hv+Y;NVb$jqC?Hp(ht{tkbyZjCijK0JXXH)vs zN!ZC}??UIiIAc#tT`FG?jz%mJ5uxJs13n?TS#0t#Vrru$_mX{GL6`yy;o0P(p(!}P zKZ$K`u;PJQntdA5SomYW(*1J`$UC`zo&mWg_b)K`iwwvWxt}ulO9;XoY-oXllA~ey(nhcKT^0sjQDudr={S3(8JO!t}#;m`tv-H-4d8~HvVU0|Y`!`uUKoUpD z6hX<~*~%XiorME}gB;P92u!`L`E&F0Vmb}&u-4|{&dV^?<$$bAaH{Qc#t|CFzJsk{b?~O)(sp2@jGy zxN~siz`7S83$X73ZZq+%+bhDU8egE`1Qh8^t-ycprtn3H1qtnaU@JX!Kote6r_iJD z^1Er3M{lQhGpc|Slt%pMZccipuT~a*Z#hjhAvutaTJ1c}7gn(KD_i%F9#unv;}VN~ zUq{tQoI9dMqc!5YADz2?1mk4IGY85YRg(UGTY4K)N8{RKaUWwneH@E(kM-uN@wnab zp8VtLM4W#zZh2Cj>gM*;J{`@kq@Dwx@gHSI&&RFKs2Ac^XO!I&Ka1~lk^Uy#!d4w8vZ*qu_J*HOw%nCPZ`kEW9fB<5kq- zrDycG{Y&)ta(|ET8G5A`(=o3<@rUn4O%C+&`-k_TeZJK6K<%G^rY9O>yYyBX+>xX0 z!rrlc@%&Vm2ipB7X*a%05AcKSiuCCw{K+2*kNE0*a4a&QZNx@2VGcC8jaWxkp(0qm zCc*9g+8182U%yh;;;OjVP$XDlEpfHzGx=(cOic+-(&aZl`y9W}L^tMV=Rs&b6A?5+ z-U9~spa^coc?33uvvC(m7nc~^M-W<^P?$tL_Z~ApVDKS>Z!q{KgO3<|i@~ols4)07 z2JbVNXK;tXT?PvXplE(ndF>1Gdi{#~b!O%CbSjrG!!QgLcM@7sx5^e|j@%joG04)W z8<|*p46?3bC5M%cMWyu(dC?v z_`)hU_w0H!Lp!Jg5AZI-HOtY(Ra@jLs^v5Tzs{Jj=#-iCeMbf!>RifY`m*~8i;4`$ zLutb(xwr8Av!@YHH!Qi^O|j|9%r;;+_rf!)PLp30IfpMXeBs$0OE2N6LpzYN@{ruX z!VGGySgC`rv1!@URx9Bx$GW8uO!P%4kguySOB@zCHHmARsuSo%czORTZp6P~(0@g{ zb>#hXUdz9Sh?U}{s|}?z)~4l>)*rT*ALo-<(?ZS(sw;k;w<7Z@loVR~t<&tG6Vs** z-6!h|^N+soy@prh9cGZVvdo9=4dwi#3fylLgF^Oa!HYf2KqNQ`47!^ml6RlEi=q^9 zOc;X|L_liftE#ps;z%SALoY#>c`E*J#S3#l+h=M8!Va!@sN%d=(J~Fg7qsXQX~9%P zF|rY{yL3#dVC8&%VY?~rQH01L%84&S@`$~X7+?A2{jl8ISPCRuIWKP_-t(Q)2`1@{ z;I1*~p0GJ2dsP+Md0~T<1~7yt@KqBSl1JpIaSm{pphdJ--oUQ+xkB{G8{ojYAG5uS z1aCgd8$TjPWm4YI<_s7wtbJ@I?r&(nBi;)#1}%%c<9%*6Qk{DMn(aA!HJw%tmB;Qj zx(-s?{>tQ=E~!&FA7<$|!z~X>fLcgRuumOxc(#oAdMK zaeiyaBU`D2`ATJ@rMBV0QwfWe%GP$Zp-bG?IJc_|zRJL3@CF0H0Rgoj0+C#-8}2$| zqTdq2`A?V>>i84JNCot&Ir|KfuC@D<=_#K3mx~Om-IbDubLR+&^IyD-ob~vjxBSG z_Nz0;P7lzeqekR`+u79_d+=+;axlqj3nTZSac7UVJt{}4SQ6{rGK2C3VU$|IFUYEe>9Bd8ow z_ay}*qRJyxl@t^Qs({p*r10NNs3KA=en?vxL24MOhf+3*)Cf|$k~*?A1Ae6xU8rNC zz~J2RX;(xOkIZXjR%vE)M$N3vRA;=I+KjV2voZrkD0yd>n;+mm6%e`*j0~LWpz~qA zpmGqI;B{iC@1zB}7`+4ep9ms?r`>m`94ede57`WIUDC%4736zJ8gtfIC7O`5sRl<5 zk{j0ag5iPlz}#9e)PJ5$_lI2M$N+6vlFpZdLhoT^2P^EL2idh|?xH5@DTb1I=lj%1!E>ur>#P1C#}jCPt#%g5%=iWWowoVGvs zF+a{iC>S=~|H-kzy$GLEDIX#Kva$_lTJSF}M!^o$T8)PO9{@b9u)KwA_rEdtF$3}2 zIm_68U?A-3?;sYYTg$wNWoz}0aWwZoGw7}==2pV&Rn0kF!?{m*q%*}F+&?kV-oH^Z R@g4n_odn}@0WP7R{~zhvSe5_) literal 0 HcmV?d00001 diff --git a/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/create_excon_db.py b/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/create_excon_db.py new file mode 100755 index 000000000..b6d7b5a6a --- /dev/null +++ b/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/create_excon_db.py @@ -0,0 +1,627 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# $Id$ +# $HeadURL$ +# $Author$ +# +# Ported to Python 3 for Qt6 Migration + +from __future__ import print_function +from collections import defaultdict + +import datetime +import getopt +import re +import subprocess +import sys +import tempfile +import os +import configparser + +class main_class(object): + def __init__(self): + self.project = None + self.database = None + self.db_host = "localhost" + self.db_user = "postgres" + self.database_backup = None + self.from_backup = None # '/opt/postgres/db-setup/backup/guez_db_lts_ets_pro.sql' + self.db_description = "Training Center EXCON " + self.log_dir = None + self.log_file_name = None + if hasattr(sys, 'getwindowsversion'): + # find postgresql version + root = "C:/Program Files/PostgreSQL/" + dirlist = [item for item in os.listdir(root) if os.path.isdir(os.path.join(root, item))] + highestVersion = "0.0" + for dirs in dirlist: + if float(dirs) > float(highestVersion): + highestVersion = str(dirs) + psql_dir = os.path.join("C:\\Program Files\\PostgreSQL", highestVersion, "bin") + self.psql_command = os.path.join(psql_dir, "psql.exe") + self.createdb_command = os.path.join(psql_dir, "createdb.exe") + self.dropdb_command = os.path.join(psql_dir, "dropdb.exe") + print("\n Found psql in: ", psql_dir) + else: + self.psql_command = 'psql' + self.createdb_command = 'createdb' + self.dropdb_command = 'dropdb' + self.with_exercise_data = False + # Path, where sql file(s) for configuring the db are + self.sql_path = None + self.setting_path = None + self.global_schemas = [] + self.service_operator_rights = [] + + def psql_error_log_info(self, message): + self.log(" Message: %s" % message) + self.log(" => Database accessed by other users:") + self.log(" current dir: %s" % os.getcwd()) + self.log_hline() + self.log("Open connection for postgresql: ", True) + self.log_hline() + self.system('%s postgres -h %s -U postgres -f check_connections.sql' % (self.psql_command, self.db_host), True) + self.log_hline() + sys.exit(2) + + def initialize(self): + if self.project is None: + print("No project given", file=sys.stderr) + sys.exit(1) + + if self.log_dir is None: + self.log_dir = '.' + + self.log_file_name = "%s/init_db_%s.log" % (self.log_dir, self.project) + + if self.setting_path is None: + if hasattr(sys, 'getwindowsversion'): + self.setting_path = "lts-cc.conf" # TODO: check path on Win + else: + self.setting_path = "/etc/lts-cc.conf" + + dbName, self.db_host = self.db_config(self.setting_path) + if dbName is None: + dbName = self.project + "_pro" + + if self.db_host is None: + self.db_host = "localhost" + + if self.database is None: + self.database = dbName + + if self.database_backup is None: + self.database_backup = self.database + "_old" + + if self.sql_path is None: + self.sql_path = "../../share/Lts/sql/" + + if self.from_backup is not None: + if os.path.isfile(self.from_backup): + self.log("# Restoring from backup: %s" % self.from_backup, True) + self.with_exercise_data = False + else: + self.log("# Invalid backup file: %s" % self.from_backup, True) + self.from_backup = None + + self.log_hline() + self.log("# LOGFILE : %s" % os.path.abspath(self.log_file_name), True) + self.log("# DATE : %s" % datetime.datetime.today(), True) + self.log("# PROJECT : %s" % self.project, True) + self.log("# DATABASE : %s" % self.database, True) + if self.from_backup is not None: + self.log("# FROM BACKUP : %s" % self.from_backup, True) + else: + self.log("# WITH TEST DATA : %s" % self.with_exercise_data, True) + self.log_hline() + + def execute(self): + self.log("# - Drop backup database %s ..." % self.database_backup, True) + + ret = self.system('%s -U postgres -h %s --if-exists %s' % (self.dropdb_command, self.db_host, self.database_backup)) + if not ret: + self.psql_error_log_info("Cannot drop database %s" % self.database_backup) + self.log("# => dropdb finished", True) + self.log_hline() + + # Check if db exists + # -t: tuples only + exists_db = self.system_returning_bool('%s -h %s -t -U postgres -c "SELECT CASE WHEN EXISTS ( SELECT datname FROM pg_database WHERE datname = \'%s\') THEN CAST(1 AS BIT) ELSE CAST(0 AS BIT) END " ' % (self.psql_command, self.db_host, self.database)) + + if exists_db: + self.log("# - Rename existing database %s ..." % self.database, True) + ret = self.system('%s -h %s -U postgres -c "ALTER DATABASE %s RENAME TO %s" postgres' % (self.psql_command, self.db_host, self.database, self.database_backup)) + if not ret: + self.psql_error_log_info("Failed to rename database %s" % self.database) + self.log("# => Rename DB from %s to %s finished" % (self.database, self.database_backup), True) + self.log_hline() + + self.log("# - Create database %s ..." % self.database, True) + self.db_description = "Training Center EXCON (" + self.project + ")" + ret = self.system('%s --host=%s -U postgres %s "%s"' % (self.createdb_command, self.db_host, self.database, self.db_description)) + if not ret: + self.psql_error_log_info("Failed to create database %s" % self.database) + self.log("# => Database %s created" % self.database, True) + self.log_hline() + + # GRANT create on database + self.log("# - Grant create on database %s to user ets_admin ..." % self.database, True) + self.system('%s -h %s -U postgres -c "GRANT CREATE ON DATABASE %s TO ets_admin;" %s' % (self.psql_command, self.db_host, self.database, self.database)) + self.log("# => grant finished", True) + self.log_hline() + self.log("# - Grant create on database %s to user ets_exm ..." % self.database, True) + self.system('%s -h %s -U postgres -c "GRANT CREATE ON DATABASE %s TO ets_exm;" %s' % (self.psql_command, self.db_host, self.database, self.database)) + self.log("# => grant finished", True) + self.log_hline() + + # create users and grants (if they dont exists, function in postgres database) + self.log("# - Creating default users on database %s ..." % self.database, True) + self.execute_sql_file('init_db_users_grants.sql', self.db_user) + # self.execute_sql_file('init_db_users_grants.sql', self.db_user) + self.log("# => create default users finished", True) + self.log_hline() + + if self.from_backup is not None: + # restore from backup + self.log("# - Restoring from backup %s ..." % self.from_backup, True) + ret = self.system('%s -h %s -U postgres -f "%s" --set ON_ERROR_STOP=on %s >> %s 2>&1' % (self.psql_command, self.db_host, self.from_backup, self.database, self.log_file_name)) + if not ret: + self.die("=> Execution of sql-commands for file %s failed\n => see logfile at %s\n\n" % (self.from_backup, os.path.abspath(self.log_file_name))) + self.log("# => Database %s restored from backup %s" % (self.database, self.from_backup), True) + self.log_hline() + + self.log("# - Grant admin on database %s to user ets_exm ..." % self.database, True) + self.system('%s -h %s -U postgres -c "GRANT ets_admin TO ets_exm;" %s' % (self.psql_command, self.db_host, self.database)) + self.log("# - Grant all privileges on all tables and sequences to %s ..." % self.database, True) + self.system('%s -h %s -U postgres -c "GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA asm, flm, ism, opm, ppm, exm, avm, msg TO ets_exm;" %s' % (self.psql_command, self.db_host, self.database)) + self.system('%s -h %s -U postgres -c "GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA asm, flm, ism, opm, ppm, exm, avm, msg TO ets_exm;" %s' % (self.psql_command, self.db_host, self.database)) + self.log("# => grant finished", True) + + self.log("# - Grant create on database %s to user ets_admin ..." % self.database, True) + self.system('%s -h %s -U postgres -c "GRANT CREATE ON DATABASE %s TO ets_admin;" %s' % (self.psql_command, self.db_host, self.database, self.database)) + self.log("# => grant finished", True) + self.log_hline() + self.log("# - Grant create on database %s to user ets_exm ..." % self.database, True) + self.system('%s -h %s -U postgres -c "GRANT CREATE ON DATABASE %s TO ets_exm;" %s' % (self.psql_command, self.db_host, self.database, self.database)) + self.log("# => grant finished", True) + self.log_hline() + + # update procedures + self.log("# - Update procedures on database %s ..." % self.database, True) + self.execute_sql_file('init_db_procedures.sql', self.db_user) + self.log("# => update procedures finished", True) + self.log_hline() + + else: + # create new db + self.log("# START initialisation of database %s ..." % self.database, True) + self.log_hline() + + # create procedures and schemas + self.log("# - Creating default procedures and schemas on database %s ..." % self.database, True) + sql_init_files = ['init_db_procedures.sql', 'init_db_schemas.sql'] + for f in sql_init_files: + self.execute_sql_file(f, self.db_user) + self.log("# => create default procedures and schemas finished", True) + self.log_hline() + + # Run sql script in specific directory + if self.with_exercise_data: + # make test-db + self.create_test_exercise_schema() + else: + # make db + files = self.get_files(self.sql_path) + self.create_global_schemas() + if self.project == 'guez': + self.insert_test_data('whg') + self.insert_test_data('ppm', 'types') + self.insert_test_data('aes', 'types') + self.insert_test_data('ppm', 'templates') + self.insert_test_data('pdm') + self.insert_test_data('pdm', 'translation') + for f in self.service_operator_rights: + self.execute_sql_file(f, "ets_opm") + self.insert_test_data('opm', 'initial') + self.insert_test_data('opm') + self.insert_test_data('flm') + self.insert_test_data('flm', 'file_content_san') + self.insert_test_data('asm') + self.insert_test_data('asm', 'workstations') + self.insert_test_data('ism') + self.insert_test_data('ism', 'asset') + self.insert_test_data('avm') + self.insert_test_data('avm', 'frequencysets') + self.insert_test_data('som') + # symbols in FLM + fn = os.path.join('%s_flm_symbols.sql' % self.project) + if os.path.isfile(fn): + self.log("# Executing sql: %s" % fn, True) + self.execute_sql_file(fn, self.db_user) + self.log("# => Symbols inserted.", True) + self.log_hline() + fn = os.path.join('%s_update_flm_used_by.sql' % self.project) + if os.path.isfile(fn): + self.log("# Executing sql: %s" % fn, True) + self.execute_sql_file(fn, self.db_user) + self.log("# => Symbols updated.", True) + self.log_hline() + else: + fn = "update_flm_used_by.sql" + if os.path.isfile(fn): + self.log("# Executing sql: %s" % fn, True) + self.execute_sql_file(fn, self.db_user) + self.log("# => Symbols updated.", True) + self.log_hline() + # end symbols + + self.log("# END initialisation for database %s." % self.database, True) + self.log_hline() + + return 0 + + def log_hline(self): + self.log("# -------------------------------------------------------------------------------", True) + + def log(self, logline, log_to_stdout=False): + if self.log_file_name is None: + print("Logfile name not yet set - log: %s" % logline, file=sys.stderr) + return + + with open(self.log_file_name, 'a') as f: + f.write(logline) + f.write("\n") + if log_to_stdout: + print(logline) + + def die(self, message): + self.log(message) + print("fatal error: %s" % message, file=sys.stderr) + sys.exit(3) + + def system(self, cmdstring, show_output=False): + self.log("# Executing '%s'" % cmdstring, False) + if hasattr(sys, 'getwindowsversion'): + p = subprocess.Popen(cmdstring) + ret = p.wait() + else: + p = subprocess.Popen(cmdstring, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + ret = p.wait() + if show_output: + error = p.stdout.read() + print(error, file=sys.stderr) + if ret != 0: + print("Error executing %s" % cmdstring, file=sys.stderr) + return ret == 0 + + def system_returning_bool(self, cmdstring): + self.log("# Executing '%s'" % cmdstring) + cmdstring = cmdstring.replace('-e', '-q') + if hasattr(sys, 'getwindowsversion'): + p = subprocess.Popen(cmdstring, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + else: + p = subprocess.Popen(cmdstring, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + ret = p.wait() + error = p.stdout.read() + bRet = error.strip() + self.log(" bRet: '%s'" % bRet) + if ret != 0: + print("Error executing %s (%s)" % (cmdstring, error), file=sys.stderr) + return bRet == b'1' + + def db_config(self, config_file): + config = configparser.ConfigParser() + self.log("# read from configFile: %s" % config_file) + config.read(config_file) + try: + db_name = config.get('Global', 'DatabaseName') + db_host = config.get('Global', 'DatabaseHostName') + except Exception: + print("Could not parse config file '%s'!" % config_file, file=sys.stderr) + # sys.exit(1) + db_name = None + db_host = None + return (db_name, db_host) + + def get_files(self, directory): + ret = [] + for path, subdirs, files in os.walk(directory): + for name in files: + if name.endswith('.sql'): + complete_file_name = os.path.join(path, name) + ret.append(complete_file_name) + if '_' not in name: + self.global_schemas.append(complete_file_name) + self.log("# Found global schema: %s" % complete_file_name, False) + if 'operator_rights' in name: + self.service_operator_rights.append(complete_file_name) + + return ret + + def sort_global_schema_by_dependencies(self): + self.log("# * Sorting global schemas by dependencies ...", True) + # searching for dependencies + pattern = re.compile(".+REFERENCES \\w\\w\\w\\.") # pattern thats used to determine the dependencies + dependencies = defaultdict(list) + for sqlFile in self.global_schemas: + for line in open(sqlFile): + for match in re.finditer(pattern, line): + line = match.group() + dependencyToFile = os.path.join(self.sql_path, line[len(line) - 4:len(line) - 1] + ".sql") + if dependencyToFile != sqlFile: + dependencies[sqlFile].append(dependencyToFile) + + # creating new schema list + newFileList = list() + # add files without dependencies + for sqlFile in self.global_schemas: + if sqlFile not in dependencies.keys(): + newFileList.append(sqlFile) + + # add files with dependencies + while len(dependencies) != 0: + for key in dependencies.keys(): + # print key, dependencies[key] + if set(newFileList) >= set(dependencies[key]): + newFileList.append(key) + dependencies.pop(key) + + self.global_schemas = newFileList + + def create_global_schemas(self): + + self.sort_global_schema_by_dependencies() + self.log("# * Create global schemas ...", True) + for f in self.global_schemas: + schema_name = os.path.basename(f) + user_name = "ets_" + os.path.splitext(schema_name)[0] + if os.path.getsize(self.sql_path + '/' + schema_name) > 0: + self.log("# Creating Schema %s as db-user %s" % (schema_name, user_name), False) + self.execute_sql_file(self.sql_path + '/' + schema_name, user_name) + + self.log("# => Global schemas created.", True) + self.log_hline() + + def create_global_schema(self, svc_name): + + self.log_hline() + self.log("# * Create global schema: " + svc_name, True) + for f in self.global_schemas: + schema_name = os.path.basename(f) + user_name = "ets_" + os.path.splitext(schema_name)[0] + if os.path.splitext(schema_name)[0] == svc_name and os.path.getsize(self.sql_path + '/' + schema_name) > 0: + self.log("# Creating Schema %s as db-user %s" % (schema_name, user_name), True) + self.execute_sql_file(self.sql_path + '/' + schema_name, user_name) + self.log("# Global schema created.", True) + + def insert_test_data(self, svc_name, fn_postfix=None, db_user=None): + if fn_postfix: + postfix = '_' + fn_postfix + postfix_log = ' (' + fn_postfix + ')' + else: + postfix = '' + postfix_log = '' + fn = os.path.join('%s_%s_values%s.sql' % (self.project, svc_name, postfix)) + fn_proj = fn + if not os.path.isfile(fn): + fn = os.path.join('insert_%s_values%s.sql' % (svc_name, postfix)) + if db_user is None: + db_user = 'ets_%s' % svc_name + if os.path.isfile(fn): + self.log("# Executing sql: %s" % fn, True) + self.execute_sql_file(fn, db_user) + self.log("# => %s%s Values inserted." % (svc_name.upper(), postfix_log), True) + else: + self.log("# FILE NOT FOUND: %s (or %s)" % (fn, fn_proj), True) + self.log_hline() + + def sorted_services(self, sqlFiles): + + self.log("# * Sorting services ...", True) + + pattern = re.compile("^-- DEPENDS: (.*)$") + dependencies = defaultdict(list) + for sqlFile, svcName in sqlFiles: + for line in open(sqlFile): + for match in re.finditer(pattern, line): + service = match.group(1) + dependencies[svcName].append(service) + + # creating new schema list + self.log("# * Creating new schema list ...", True) + newSvcList = list() + # add files without dependencies + self.log("# * Add files without dependencies ...", True) + for sqlFile, svcName in sqlFiles: + if svcName not in dependencies.keys(): + newSvcList.append(svcName) + + # add files with dependencies + # print "services without deps: " + # print newSvcList + # print "services with deps:" + # print dependencies + self.log("# * Add files with dependencies ...", True) + while len(dependencies) != 0: + for key in dependencies.keys(): + # >=: Test whether every element in other is in the set. + if frozenset(newSvcList) >= frozenset(dependencies[key]): + newSvcList.append(key) + dependencies.pop(key) + + return newSvcList + + def create_test_exercise_schema(self): + + # Create schema for Test exercise (ex_42, ex_35) + # Add Test User (ex_42, ex_35), grant privileges + + fn = "test_exm_exercise.sql" + if os.path.isfile(fn): + self.log("# * Create test exercises (35, 42) ...", True) + self.execute_sql_file(fn, self.db_user) + self.log("# => Test users and schemas created.", True) + self.log_hline() + + files = self.get_files(self.sql_path) + self.create_global_schemas() + + exercise_sql_files = list() + for f in files: + fn = os.path.basename(f) + svc_name = fn.split('_')[0].split('/')[-1] + if "42" in f: + exercise_sql_files.append((f, svc_name)) + + # sort exercise dependent sql files ("-- DEPENDS: ") + exercise_svc_sorted = self.sorted_services(exercise_sql_files) + + for ex_id in (35, 42): + # username = 'ets_ex_%s' % ex_id + username = 'ets_exm' + for svc in exercise_svc_sorted: + filename = os.path.join(self.sql_path, '%s_ex_%s.sql' % (svc, ex_id)) + self.execute_sql_file(filename, username) + # make test-db + self.insert_test_data('pdm') + self.insert_test_data('pdm', 'translation') + self.insert_test_data('asm') # needs to be exeucted after pdm because of foreign key + self.insert_test_data('asm', 'test') + # military + self.insert_test_data('exm') # needs to be executed after pdm, because of foreign key + for f in self.service_operator_rights: + self.execute_sql_file(f, "ets_opm") + self.insert_test_data('opm', 'initial') + self.insert_test_data('opm') + self.insert_test_data('opm', 'test') + self.insert_test_data('flm') + self.insert_test_data('flm', 'test') + self.insert_test_data('flm', 'file_content_san') + self.insert_test_data('ism', 'test') + self.insert_test_data('ism', 'asset') + self.insert_test_data('avm') + self.insert_test_data('avm', 'frequencysets') + self.insert_test_data('avm', 'test') + self.insert_test_data('som') + if self.project == 'guez': + self.insert_test_data('whg') + self.insert_test_data('ppm', 'types') + self.insert_test_data('ppm', 'templates') + self.insert_test_data('ppm', 'ex_35', 'ets_exm') + self.insert_test_data('ppm', 'ex_42', 'ets_exm') + self.insert_test_data('aes', 'types') + self.insert_test_data('aes', 'ex_35', 'ets_ex_00') + self.insert_test_data('aes', 'ex_42', 'ets_ex_00') + # self.insert_test_data('oss', 'ex_35', 'ets_ex_00') + self.insert_test_data('oss', 'ex_42', 'ets_ex_00') + self.insert_test_data('rep', 'ex_42', 'ets_ex_00') + + fn = os.path.join('%s_flm_symbols.sql' % self.project) + if os.path.isfile(fn): + self.log("# Executing sql: %s" % fn, True) + self.execute_sql_file(fn, self.db_user) + self.log("# => Symbols inserted.", True) + self.log_hline() + fn = os.path.join('%s_flm_update_used_by.sql' % self.project) + if os.path.isfile(fn): + self.log("# Executing sql: %s" % fn, True) + self.execute_sql_file(fn, self.db_user) + self.log("# => Symbols updated.", True) + self.log_hline() + else: + fn = "update_flm_used_by.sql" + if os.path.isfile(fn): + self.log("# Executing sql: %s" % fn, True) + self.execute_sql_file(fn, self.db_user) + self.log("# => Symbols updated.", True) + self.log_hline() + + # civil + # self.insert_test_data('pdm') + # self.insert_test_data('ppm') + # self.insert_test_data('ppm', 'ex_42', 'ets_ex_00') + + # needs to be executed as super user postgres + fn = 'update_images_opm.sql' + if os.path.isfile(fn): + self.log("# Executing sql: %s" % fn, True) + self.execute_sql_file(fn, 'postgres') + fn = 'test_scenario_participant_positions.py' + if os.path.isfile(fn): + import test_scenario_participant_positions + self.log("# Executing sql: %s" % fn, True) + self.run_sql_statements(test_scenario_participant_positions.generate_participant_positions()) + fn = 'test_scenario_participant_state.py' + if os.path.isfile(fn): + import test_scenario_participant_state + self.log("# Executing sql: %s" % fn, True) + self.run_sql_statements(test_scenario_participant_state.generate_participant_state()) + + def execute_sql_file(self, f, db_user): + self.log("Run sql-file %s as db-user %s" % (f, db_user), False) + ret = self.system('%s -h %s -U %s -f "%s" --set ON_ERROR_STOP=on %s >> %s 2>&1' % (self.psql_command, self.db_host, db_user, f, self.database, self.log_file_name)) + if not ret: + self.die("=> Execution of sql-commands for file %s failed\n => see logfile at %s\n\n" % (os.path.abspath(f), os.path.abspath(self.log_file_name))) + + def run_sql_statements(self, sql_stmts): + f = tempfile.NamedTemporaryFile(delete=False) + f.write('\n'.join(sql_stmts).encode('utf-8')) + f.close() + self.execute_sql_file(f.name, 'postgres') + os.remove(f.name) + + +def usage(): + print("Usage: %s " % sys.argv[0]) + print("usage: $0 -p -d -h -a -c -b -s -f ") + print(" -p (--project) : guez / ahtc / qatar / l400p2 ") + print(" -d (--database) : database name (default lts_ets_pro)") + print(" -h (--host) : database server hostname (default localhost)") + print(" -a (--archive-as-name) : Name of archive database") + print(" Old database will be renamed to the archive-name (Default _old) ") + print(" -e (--exercise-data) : with exercise (test) data ") + print(" -c (--config-path) : config-path - sql-files for configuring the database ") + print(" -b (--base-path) : base-path - config files (py-script & other sql-base scripts)") + print(" -s (--setting-path) : setting-path - path where the default database-settings are stored (Default: /etc/lts-cc.conf)") + print(" -f (--from-backup) : using a backup file") + + +def main(): + + p = main_class() + + try: + opts, args = getopt.getopt(sys.argv[1:], ":p:d:h:a:s:c:eb:f:", ["project", "database", "db-host", "archive-as-name", "setting-path", "config-path", "exercise-data", "base-path", "from-backup"]) + except getopt.GetoptError as err: + print(err, file=sys.stderr) + usage() + sys.exit(2) + for o, a in opts: + if o in ("-p", "--project"): + p.project = a + if o in ("-d", "--database"): + p.database = a + if o in ("-h", "--db-host"): + p.db_host = a + if o in ("-a", "--archive-as-name"): + p.save_as = a + if o in ("-s", "--setting-path"): + p.setting_path = a + if o in ("-c", "--config-path"): + p.sql_path = a + if o in ("-e", "--exercise-data"): + p.with_exercise_data = True + if o in ("-b", "--base-path"): + p.base_path = a + if o in ("-f", "--from-backup"): + p.from_backup = a + + p.initialize() + p.execute() + + sys.exit(0) + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/geister.py b/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/geister.py new file mode 100755 index 000000000..3f07ace21 --- /dev/null +++ b/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/geister.py @@ -0,0 +1,106 @@ +#!/usr/bin/env python3 +import subprocess +import os +import sys + +# 🔧 Verbindungseinstellungen (anpassen!) +DB_NAME = "guez_20250910" +DB_USER = "postgres" +DB_HOST = "localhost" +DB_PORT = "5432" + +# 🔍 Welche Schemata durchsuchen? +SCHEMA_PREFIX = "ex\_" +TABLE_NAME = "rec_equipment_state" + +# ⚙️ psql-Basisbefehl (mit -A = unaligned, -t = tuple-only) +PSQL_BASE = [ + "psql", + "-h", DB_HOST, + "-p", DB_PORT, + "-U", DB_USER, + "-d", DB_NAME, + "-A", "-t", "-c" +] + +def run_psql(query): + """Führt ein SQL-Statement aus und gibt den Text-Output zurück.""" + env = os.environ.copy(); + process = subprocess.Popen( + PSQL_BASE + [query], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + env=env, + universal_newlines=True + ) + stdout, stderr = process.communicate() + + if process.returncode != 0: + sys.stderr.write("Fehler bei psql: \n" + stderr + "\n") + return "" + + return stdout.strip() + +def main(): + # 🔹 1. Schemata abrufen + print("🔍 Suche nach Schemas ...") + schema_query = f"SELECT schema_name FROM information_schema.schemata WHERE schema_name LIKE '{SCHEMA_PREFIX}%' ORDER BY schema_name;" + schema_output = run_psql(schema_query) + + schemas = [s for s in schema_output.splitlines() if s.strip()] + print(f"Gefundene Schemata: {schemas}\n") + + # 🔹 2. Query pro Schema ausführen + for schema in schemas: + # Anzahl verschiedener Verursacher, wenn originator_id als equipment_number betrachtet wird: +# query = f"select COUNT(*) FROM (select originator_id, COUNT(*) from {schema}.{TABLE_NAME} \ +# where originator_type = 1 AND equipment_number not in \ +# (select equipment_number from {schema}.rec_participant where equipment_number > 0) \ +# AND position->>'reportingSource' = '3' GROUP BY originator_id)" + + # Verursacher EquipmentNumbers und Anzahl an Treffern, wenn originator_id als equipment_number betrachtet wird. + query = f"select originator_id, COUNT(*) from {schema}.{TABLE_NAME} \ + where originator_type = 1 AND equipment_number not in \ + (select equipment_number from {schema}.rec_participant where equipment_number > 0) \ + AND position->>'reportingSource' = '3' GROUP BY originator_id" + + # Gesamtanzahl an Treffern, wenn originator_id als equipment_number betrachtet wird. +# query = f"select COUNT(*) from {schema}.{TABLE_NAME} \ +# where originator_type = 1 AND equipment_number not in \ +# (select equipment_number from {schema}.rec_participant where equipment_number > 0) \ +# AND position is null" +# AND position->>'reportingSource' != '3'" +# AND position is null GROUP BY originator_id)" + +# queryParticpantIdsFromEqNo = f"select id from {schema}.rec_participant where equipment_number in " +# queryUnknownExternalEqNos = f"select equipment_number from {schema}.{TABLE_NAME} WHERE equipment_number not in " + +# Ausstattungsnummern aller externer Teilnehmer, die getroffen wurden: +# query = f"select equipment_number from {schema}.{TABLE_NAME} \ +# where equipment_number not in \ +# (select equipment_number from {schema}.rec_participant where equipment_number > 0) \ +# and position->>'reportingSource' = '3'" + +# and originator_type = 4 AND position is null" + +# query = f"select DISTINCT equipment_number from {schema}.{TABLE_NAME} \ +# where equipment_number not in \ +# (select equipment_number from {schema}.rec_participant where equipment_number > 0) ORDER BY equipment_number" + +# query = f"select COUNT(*) FROM (SELECT DISTINCT equipment_number from {schema}.{TABLE_NAME} \ +# where equipment_number not in \ +# (select equipment_number from {schema}.rec_participant where equipment_number > 0) )" + + print(f"▶️ {schema}") + + try: + result = run_psql(query) + if result.strip(): + print(result) + else: + print("(keine Ergebnisse)\n") + except subprocess.CalledProcessError as e: + print(f"❌ Fehler bei Schema {schema}: {e.stderr}\n") + +if __name__ == "__main__": + main() diff --git a/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/guez_db_update.py b/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/guez_db_update.py new file mode 100755 index 000000000..45483a2eb --- /dev/null +++ b/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/guez_db_update.py @@ -0,0 +1,228 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# +# $Id$ +# $HeadURL$ +# $Author$ +# + +from __future__ import print_function +from collections import defaultdict + +import datetime +import subprocess +import sys +import os + +class main_class(object): + def __init__( self ): + self.project = "guez" + self.database = "lts_ets_pro" + self.db_host = "localhost" + self.db_user = "postgres" + self.log_dir = '.' + self.log_file_name = "%s/update_db_%s.log" % (self.log_dir, self.project) + self.psql_command = 'psql' + self.pg_dump_command = 'pg_dump' + self.csv_file = 'guez_db_update_charge_types.csv' + self.chargeTypes = {} + + def initialize(self): + + self.log_hline() + self.log("# LOGFILE : %s" % os.path.abspath(self.log_file_name), True) + self.log("# DATE : %s" % datetime.datetime.today(), True) + self.log("# PROJECT : %s" % self.project, True) + self.log("# DATABASE : %s" % self.database, True) + self.log_hline() + + def execute(self): + +# execute sql files + self.log("# - Executings sql files on database %s ..." % self.database, True) + self.log_hline() + + f = 'guez_db_update_charge_types_before.sql' + self.log("# - Executing sql file %s ..." % f, True) + self.execute_sql_file(f) + self.log("# => %s sql finished" % f, True) + self.log_hline() + + self.log("# - Load charge types csv file %s" % self.csv_file, True) + self.chargeTypes = self.loadChargeTypes() + self.log_hline() + + f = 'guez_db_create_charge_types_foreign_keys.sql' + exercises = ['ex_14', 'ex_17', 'ex_21', 'ex_22', 'ex_26', 'ex_27', 'ex_28', 'ex_29', 'ex_30', 'ex_31', 'ex_32', 'ex_33', 'ex_34', 'ex_35', 'ex_36', 'ex_37', 'ex_38', 'ex_39', 'ex_40', 'ex_41', 'ex_42', 'ex_44', 'ex_45', 'ex_46', 'ex_51'] + tables = ['eem_event', 'rec_dynamic_participant_data', 'rec_history_state', 'rec_dus_mine_state', 'rec_equipment_gear_charge_state'] + for ex in exercises: + + self.dump_dynamic_tables(ex, tables) + + self.log("# - Creating foreign keys (sql file %s) in schema %s" % (f, ex), True) + self.execute_sql_file_schema(f, ex) + self.log("# => %s finished for exercise %s " % (f, ex), True) + self.log_hline() + + f = 'guez_db_update_charge_types_after.sql' + self.log("# - UPDATING ids - executing sql file %s ..." % f, True) + self.execute_sql_file(f) + self.log("# => %s sql finished" % f, True) + self.log_hline() + + for ex in exercises: + for tabl in tables: + # replace charge types + old_file = ex+"_"+tabl+".sql" + new_file = ex+"_"+tabl+"_new.sql" + self.log("# - Replace charge types in file %s" % old_file, True) + db = self.read(old_file) + db = self.replaceChargeTypes(db) + self.write(new_file, db) + + # delete from tables + self.log("# - Deleting dynamic data in schema %s" % ex, True) + cmd = '%s -h %s -U %s -c "DELETE FROM %s;" --set ON_ERROR_STOP=ON "dbname=%s options=--search_path=%s" >> %s 2>&1' % (self.psql_command, self.db_host, self.db_user, tabl, self.database, ex, self.log_file_name) + self.log(" Running command %s" % cmd, True) + ret = self.system(cmd) + if not ret: + self.die("=> Execution of delete commands %s failed\n => see logfile at %s\n\n" % (os.path.abspath(self.log_file_name))) + + # insert new data + self.log("# - Inserting new dynamic data in schema %s" % ex, True) + self.execute_sql_file_schema(new_file, ex) + self.log("# => %s finished for exercise %s " % (new_file, ex), True) + self.log_hline() + + self.log("# - Remove dynamic data files for exercise %s" % ex, True) + os.remove(old_file) + os.remove(new_file) + + self.log_hline() + self.log("#### END ####", True) + self.log_hline() + + return 0 + + def log_hline(self): + self.log("# -------------------------------------------------------------------------------", True) + + def log(self, logline, log_to_stdout = False): + if self.log_file_name == None: + print("Logfile name not yet set - log: %s" % logline, file=sys.stderr) + return + + with open( self.log_file_name, 'a' ) as f: + f.write(logline) + f.write("\n") + if log_to_stdout: + print(logline) + + def die( self, message ): + self.log( message ) + print("fatal error: %s" % message, file=sys.stderr) + sys.exit( 3 ) + + def system( self, cmdstring, show_output = False ): + self.log( "# Executing '%s'" % cmdstring, False) + if hasattr(sys, 'getwindowsversion'): + p = subprocess.Popen( cmdstring ) + ret = p.wait() + else: + p = subprocess.Popen( cmdstring, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT ) + ret = p.wait() + if show_output: + error = p.stdout.read() + print(error, file=sys.stderr) + if ( ret != 0 ): + print("Error executing %s" % cmdstring, file=sys.stderr) + return ret == 0 + + def execute_sql_file(self, f): + self.log( "Run sql-file %s " % f, True) + ret = self.system('%s -h %s -U %s -f "%s" --set ON_ERROR_STOP=on %s >> %s 2>&1' % (self.psql_command, self.db_host, self.db_user, f, self.database, self.log_file_name)) + if not ret: + self.die("=> Execution of sql-commands for file %s failed\n => see logfile at %s\n\n" % (os.path.abspath(f), os.path.abspath(self.log_file_name))) + + def execute_sql_file_schema(self, f, schema): + self.log( "Run sql-file %s " % f, True) + cmd = '%s -h %s -U %s -f "%s" --set ON_ERROR_STOP=ON "dbname=%s options=--search_path=%s" >> %s 2>&1' % (self.psql_command, self.db_host, self.db_user, f, self.database, schema, self.log_file_name) + self.log(" Running command %s" % cmd, True) + ret = self.system(cmd) + if not ret: + self.die("=> Execution of sql-commands for file %s failed\n => see logfile at %s\n\n" % (os.path.abspath(f), os.path.abspath(self.log_file_name))) + + def dump_dynamic_tables(self, schema, tables): + self.log("# - Dump dynamic tables in schema %s" % schema, True) + +# cmd = '%s -h %s -U %s -t %srec_dynamic_participant_data -t %seem_event -t %srec_dus_mine_state -t %srec_equipment_gear_charge_state -t %srec_history_state --column-inserts --data-only %s > %s' % (self.pg_dump_command, self.db_host, self.db_user, schema+".", schema+".", schema+".", schema+".", schema+".", self.database, schema+".sql") + + for tabl in tables: + cmd = '%s -h %s -U %s -t %s --column-inserts --data-only %s > %s' % (self.pg_dump_command, self.db_host, self.db_user, schema+"."+tabl, self.database, schema+"_"+tabl+".sql") + self.log(" Running command %s" % cmd, True) + ret = self.system(cmd) + if not ret: + self.die("=> Execution of pg_dump failed\n => see logfile at %s\n\n" % os.path.abspath(self.log_file_name)) + + def read(self, filename): + """Read a file and return a list of the lines.""" + with open(filename, 'r') as f: + lines = f.read().split('\n') + return lines + + def write(self, filename, lines): + """Write a file for a given list of lines.""" + with open(filename, 'w') as f: + for line in lines: + f.write(line + '\n') + + def loadChargeTypes(self): + """Read old and new charge types from a .csv file to a dictionary { old_id : new_id }.""" + chargeTypes = {} + with open(self.csv_file, 'r') as f: + lines = f.read().split('\n') + for line in lines[1:]: + line = line.replace('\r', '') + try: + old, new = line.split(';') + + if old in chargeTypes.keys(): + print("duplicate old charge type &s".arg(old)) + continue + + chargeTypes[old] = new + except: + pass + return chargeTypes + + def replaceChargeTypes(self,lines): + """Replace all 'chargeTypeId' entries with new ones.""" + def replace(iLine, line): + if "chargetypeid" in line.lower(): # ignore lines without charge type ID + items = line.split() # get all items in line separated by whitespace + for i, item in enumerate(map(lambda x: x.lower(), items)): # .lower() to catch all cases + if "chargetypeid" in item: + oldId = items[i+1].replace(',', '').replace('}', '').replace(']', '').replace("'", "") # remove characters to obtain ID + try: + newId = self.chargeTypes[oldId] # try lookup in chargeTypes + items[i+1] = items[i+1].replace(oldId, newId) # replace old ID with new ID + except: + if int(oldId) < -2: # any ID < -2 becomes 0 + items[i+1] = items[i+1].replace(oldId, '0') + else: # -1 and -2 are valid IDs + pass + line = ' '.join(items) # rejoin items to new line + return line + + return [replace(i, line) for i, line in enumerate(lines)] # simple list comprehension to get file content with updated IDs + +def main(): + + p = main_class() + p.initialize() + p.execute() + + sys.exit(0) + +if __name__ == "__main__": + main() diff --git a/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/guez_generate_js.py b/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/guez_generate_js.py new file mode 100755 index 000000000..ebfebe341 --- /dev/null +++ b/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/guez_generate_js.py @@ -0,0 +1,39 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +""" +Created on Mon Mar 22 12:07:33 2021 +@author: Filip Biedziak +Usage: guez_generate_js.py +""" +# +# $Id$ +# $HeadURL$ +# $Author$ +# + +import sys + +def toJson(assetBarcode, seBarcode): + string = ' exampleSocket.send(JSON.stringify({\n type: "mountTag",\n uuid: "UUID",\n data: {\n' + string += ' mountingPointTag: "' + assetBarcode + '",\n assetTag: "' + seBarcode + '"\n }\n }));\n' + return string + +if __name__ == "__main__": + infile = sys.argv[1] + outfile = sys.argv[2] + + strings = [] + with open(infile, "r") as f: + lines = f.read().split("\n") + for line in lines[1:]: + if line == "": + continue + items = line.split(",") + if (len(items[1].replace('""','').strip()) == 0 or len(items[3].replace('""','').strip()) == 0): + continue + strings.append(toJson(items[1], items[3])) + with open(outfile, "w") as f: + f.write("function sendMountTags() {\n") + for s in strings: + f.write(s) + f.write("}") diff --git a/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/ism_asset_csv_to_sql.py b/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/ism_asset_csv_to_sql.py new file mode 100755 index 000000000..ed1da4b60 --- /dev/null +++ b/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/ism_asset_csv_to_sql.py @@ -0,0 +1,140 @@ +#!/usr/bin/python +import csv +import os +import getopt +import sys +import time + +class sql_generator(object): + def __init__( self ): + self.project = None + self.subdir = None + self.ins_ism_asset = list() + self.csv_header = None + self.default_header = [] + + def initialize(self): + if self.project == None: + print >> sys.stderr, "No project given" + sys.exit(1) + + def execute(self): + + print '\nDo not forget to convert the files from CP850 to UTF-8!\n' + print 'for f in `ls -1 *csv`; do iconv -f cp850 -t utf-8 -o $f.out $f; mv $f.out $f; done' + print 'or' + print 'for f in `ls -1 *csv`; do iconv -f iso8859-1 -t utf-8 -o $f.out $f; mv $f.out $f; done\n\n' + print 'depending on the used excel version / export settings' + + self.read_csv('ism_asset.csv', self.ism_asset); + + + f = open(self.project + '_ism_values_asset.sql', 'wt') + head = """-- # $Id$ +-- # $HeadURL$ +-- # $Author$""" + f.write(head) + warning = '\n\n--- This file is automatically generated by ism_asset_csv_to_sql.py from csv (xls) files - do not modify here directly!' + f.write(warning) + f.write('\nBEGIN;\n-- ism_assets\n') + f.write('\n'.join(str(e) for e in self.ins_ism_asset)) + f.write('\nCOMMIT;\n-- END\n') + + def read_csv(self, filename, func): + print 'parsing %s' % filename + reader = csv.reader(open(os.path.join('./', filename), 'rt'), delimiter = ';') + self.parseHeader(reader) + for a in reader: + func(a) + + def parseHeader(self, reader): + self.translation_header = [] + self.default_header = [] + self.csv_header = next(reader, None) + for i in range(0, len(self.csv_header)): + h = self.csv_header[i] + if '[' in h and h.endswith(']'): + lang = h[h.index('[') + 1:-1] + if lang == self.default_language: + self.default_header.append(i) + else: + self.translation_header.append(i) + self.translation_lang.append(lang) + + def toBool(self, val): + if val == '': + return 'false' + if val == 'true' or val == '1': + return 'true' + if val == 'false' or val == '0': + return 'false' + if bool(val): + return 'true' + return 'false' + + def toInt(self, val): + if val == '': + return 'NULL' + return int(val, 0) + + def toFloat(self, val): + val = val.replace(',', '.') + if val == '': + return 0 + return float(val) + + def toString(self, val): + if val == '': + return 'NULL' + return "'" + val + "'" + + def toJson(self, val): + return self.toString(val) # for now + + def ism_asset(self, line): + if len(line[0]) == 0: + return + # Bezeichnung;TKZ;ArtikelNr.;SerienNr;Menge + article_no = self.toInt(line[2]) + serial_no = self.toInt(line[3]) + lastdigits = str(serial_no)[-4:] + name = str(article_no) + "_" + str(serial_no) + + #lastdigits.strip("0") + optical_code = "{ \"opticalCode\" : " + lastdigits.lstrip("0") + "}" + props = self.toJson(optical_code) + barcode = "OPS_" + str(article_no) + "0" + str(serial_no) + "_" + str(article_no) + "0" + str(serial_no) + "_0" + str(serial_no) + last_update = int(time.time()) * 1000 + + self.ins_ism_asset.append("INSERT INTO ism.ism_asset (name, mounting_point_type_id, barcode, asset_state_id, properties) VALUES (%s, 6, %s, 0, %s);" % (self.toString(name), self.toString(barcode), props)) + + + def usage(): + print "Usage: %s " % sys.argv[0] + print "usage: $0 -p " + print " -p (--project) : guez / ahtc " + +def main(): + + p = sql_generator() + + try: + opts, args = getopt.getopt(sys.argv[1:], "p:", ["project"]) + except getopt.GetoptError, err: + print >> sys.stderr, err + usage() + sys.exit(2) + for o, a in opts: + if o in ("-p", "--project"): + p.project = a + print >> sys.stderr, "PROJECT: %s" % a + + p.initialize() + + p.execute() + + sys.exit(0) + +if __name__ == "__main__": + main() + diff --git a/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/l400p2_test_scenario_participant_positions.py b/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/l400p2_test_scenario_participant_positions.py new file mode 100755 index 000000000..e053369e1 --- /dev/null +++ b/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/l400p2_test_scenario_participant_positions.py @@ -0,0 +1,46 @@ +#!/usr/bin/python + +from test_scenario_definitions import * +import time + +# Participant Ids +# 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 +PPM1_participant_id = str(' 5, 6, 7, 8, 9, 10, 11, 12, 13, 16, 18, 19, 20, 21, 24, 25, 57, 58, 30, 31, 32, 52, 53, 54, 55').split(', ') +PPM1_type_id = str(' 4, 5, 6, 7, 8, 9, 10, 11, 12, 55, 78, 78, 57, 57, 27, 29, 54, 54, 77, 77, 78, 78, 78, 57, 57').split(', ') +PPM1_party_id = str(' 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 3, 3, 3, 4, 4, 4, 4').split(', ') +PPM1_equip_no = str('1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010, 3801, 3802, 4401, 4402, 3803, 4403, 2501, 2502, 2001, 2002, 2003, 2011, 2012, 2013, 2014').split(', ') + + + + + +def generate_participant_positions(): + + start_time = int(time.time()) * 1000 + + stmts = [] + + data_lat = 0.925926; + data_lon = 0.155215; + for i in range(0, 25): + data_lat += 0.000002 + start_time += 100 + + stmt = 'INSERT INTO ex_42.rec_participant_position ( participant_id, participant_type_id, party_id, pos_lon, pos_lat, pos_z, sample_time ) VALUES ( %s, %s, 2, %s, %s, 0, %s )' % (PPM1_participant_id[i], PPM1_type_id[i], data_lon, data_lat, start_time ) + + stmt += ';' + stmts.append(stmt) + + for i in range(0, 25): + data_lon += 0.000005 + start_time += 100 + + stmt = 'INSERT INTO ex_42.rec_participant_position ( participant_id, participant_type_id, party_id, pos_lon, pos_lat, pos_z, sample_time ) VALUES ( %s, %s, 2, %s, %s, 0, %s )' % (PPM1_participant_id[i], PPM1_type_id[i], data_lon, data_lat, start_time ) + + stmt += ';' + stmts.append(stmt) + return stmts + +if __name__ == "__main__": + print '\n'.join(generate_participant_positions()) + diff --git a/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/pdm_csv_to_sql.py b/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/pdm_csv_to_sql.py new file mode 100755 index 000000000..08b49df67 --- /dev/null +++ b/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/pdm_csv_to_sql.py @@ -0,0 +1,506 @@ +#!/usr/bin/python +import csv +import os +import getopt +import sys + +class sql_generator(object): + def __init__( self ): + self.project = None + self.subdir = None + self.ins_gear_type = list() + self.ins_charge_type = list() + self.upd_charge_type = list() + self.ins_gear_type_charge_type = list() + self.ins_igniter_type = list() + self.ins_igniter_function = list() + self.ins_charge_type_igniter_type_igniter_function = list() + self.ins_load_type = list() + self.ins_charge_type_load_type = list() + self.ins_building_charge_effect = list() + self.ins_can_component_string = list() + self.ins_bite_component_text = list() + self.ins_pdm_equipment_system_event_filter = list() + self.ins_pdm_event_filter_hgr_mine_search = list() + self.ins_radio_group = list() + self.ins_fire_purpose = list() + self.ins_target_type = list() + self.ins_target_subtype = list() + self.ins_target_type_target_subtype = list() + self.ins_nuclear_preset = list() + self.ins_vulnerability_kind = list() + self.ins_translation = list() + self.csv_header = None + self.translation_header = [] + self.translation_lang = [] + self.default_header = [] + self.default_language = 'de_DE' + + def initialize(self): + if self.project == None: + print >> sys.stderr, "No project given" + sys.exit(1) + + def execute(self): + self.subdir = self.project+'_pdm' + print >> sys.stderr, "Looking into dir %s" % self.subdir + + print '\nDo not forget to convert the files from CP850 to UTF-8!\n' + print 'for f in `ls -1 *csv`; do iconv -f cp850 -t utf-8 -o $f.out $f; mv $f.out $f; done' + print 'or' + print 'for f in `ls -1 *csv`; do iconv -f iso8859-1 -t utf-8 -o $f.out $f; mv $f.out $f; done\n\n' + print 'depending on the used excel version / export settings' + + self.read_csv('charge_type.csv', self.charge_type); + self.read_csv('gear_type.csv', self.gear_type); + self.read_csv('igniter_type.csv', self.igniter_type); + self.read_csv('igniter_function.csv', self.igniter_function); + self.read_csv('charge_type_igniter_type_igniter_function.csv', self.charge_type_igniter_type_igniter_function); + self.read_csv('load_type.csv', self.load_type); + self.read_csv('charge_type_load_type.csv', self.charge_type_load_type); + self.read_csv('building_charge_effect.csv', self.building_charge_effect); + self.read_csv('can_component_string.csv', self.can_component_string); + self.read_csv('bite_component_text.csv', self.bite_component_text); + self.read_csv('event_filter_hgr_mine_search.csv', self.event_filter_hgr_mine_search); + self.read_csv('equipment_system_event_filter.csv', self.equipment_system_event_filter); + self.read_csv('radio_group.csv', self.radio_group); + self.read_csv('fire_purpose.csv', self.fire_purpose); + self.read_csv('target_type.csv', self.target_type); + self.read_csv('target_subtype.csv', self.target_subtype); + self.read_csv('target_type_target_subtype.csv', self.target_type_target_subtype); + self.read_csv('nuclear_preset.csv', self.nuclear_preset); + self.read_csv('vulnerability_kind.csv', self.vulnerability_kind); + +# self.read_csv('type_class.csv', self.vulnerability_kind); +# self.read_csv('gear_class.csv', self.vulnerability_kind); + + + f = open(self.project + '_pdm_values.sql', 'wt') + head = """-- # $Id$ +-- # $HeadURL$ +-- # $Author$""" + f.write(head) + warning = '\n\n--- This file is automatically generated by pdm_csv_to_sql.py from csv (xls) files - do not modify here directly!' + f.write(warning) + f.write('\nBEGIN;\n-- pdm_gear_type\n') + f.write('\n'.join(str(e) for e in self.ins_gear_type)) + f.write(warning) + f.write('\n\n-- charge_type\n') + f.write('\n'.join(str(e) for e in self.ins_charge_type)) + f.write(warning) + f.write('\n\n-- gear_type_charge_type\n') + f.write('\n'.join(str(e) for e in self.ins_gear_type_charge_type)) + f.write(warning) + f.write('\n\n-- igniter_type\n') + f.write('\n'.join(str(e) for e in self.ins_igniter_type)) + f.write(warning) + f.write('\n\n-- igniter_function\n') + f.write('\n'.join(str(e) for e in self.ins_igniter_function)) + f.write(warning) + f.write('\n\n-- charge_type_igniter_type_igniter_function\n') + f.write('\n'.join(str(e) for e in self.ins_charge_type_igniter_type_igniter_function)) + f.write(warning) + f.write('\n\n-- load_type\n') + f.write('\n'.join(str(e) for e in self.ins_load_type)) + f.write(warning) + f.write('\n\n-- charge_type_load_type\n') + f.write('\n'.join(str(e) for e in self.ins_charge_type_load_type)) + f.write(warning) + f.write('\n\n-- building_charge_effect\n') + f.write('\n'.join(str(e) for e in self.ins_building_charge_effect)) + f.write(warning) + f.write('\n\n-- can_component_string\n') + f.write('\n'.join(str(e) for e in self.ins_can_component_string)) + f.write(warning) + f.write('\n\n-- bite_component_text\n') + f.write('\n'.join(str(e) for e in self.ins_bite_component_text)) + f.write(warning) + f.write('\n\n-- pdm_equipment_system_event_filter\n') + f.write('\n'.join(str(e) for e in self.ins_pdm_equipment_system_event_filter)) + f.write(warning) + f.write('\n\n-- pdm_event_filter_hgr_mine_search\n') + f.write('\n'.join(str(e) for e in self.ins_pdm_event_filter_hgr_mine_search)) + f.write(warning) + f.write('\n\n-- radio_group\n') + f.write('\n'.join(str(e) for e in self.ins_radio_group)) + f.write(warning) + f.write('\n\n-- fire_purpose\n') + f.write('\n'.join(str(e) for e in self.ins_fire_purpose)) + f.write(warning) + f.write('\n\n-- target_type\n') + f.write('\n'.join(str(e) for e in self.ins_target_type)) + f.write(warning) + f.write('\n\n-- target_subtype\n') + f.write('\n'.join(str(e) for e in self.ins_target_subtype)) + f.write(warning) + f.write('\n\n-- targe_type_target_subtype\n') + f.write('\n'.join(str(e) for e in self.ins_target_type_target_subtype)) + f.write(warning) + f.write('\n\n-- nuclear_preset\n') + f.write('\n'.join(str(e) for e in self.ins_nuclear_preset)) + f.write(warning) + f.write('\n\n-- vulnerability_kind\n') + f.write('\n'.join(str(e) for e in self.ins_vulnerability_kind)) + f.write(warning) + f.write('\n\n-- translation\n') + f.write('\n'.join(str(e) for e in self.ins_translation)) + f.write('\nCOMMIT;\n-- END\n') + + f2 = open(self.project + '_pdm_charge_type_update.sql', 'wt') + f2.write(head) + f2.write(warning) + f2.write('\nBEGIN;\n-- charge_type (update)\n') + f2.write('\n'.join(str(e) for e in self.upd_charge_type)) + f2.write(warning) + f2.write('\nCOMMIT;\n-- END\n') + + def read_csv(self, filename, func): + print 'parsing %s' % filename + reader = csv.reader(open(os.path.join(self.subdir, filename), 'rt'), delimiter = ';') + self.parseHeader(reader) + for a in reader: + func(a) + + def parseHeader(self, reader): + self.translation_header = [] + self.default_header = [] + self.csv_header = next(reader, None) + for i in range(0, len(self.csv_header)): + h = self.csv_header[i] + if '[' in h and h.endswith(']'): + lang = h[h.index('[') + 1:-1] + if lang == self.default_language: + self.default_header.append(i) + else: + self.translation_header.append(i) + self.translation_lang.append(lang) + + def toBool(self, val): + if val == '': + return 'false' + if val == 'true' or val == '1': + return 'true' + if val == 'false' or val == '0': + return 'false' + if bool(val): + return 'true' + return 'false' + + def toInt(self, val): + if val == '': + return 'NULL' + return int(val, 0) + + def toFloat(self, val): + val = val.replace(',', '.') + if val == '': + return 0 + return float(val) + + def toString(self, val): + if val == '': + return 'NULL' + return "'" + val + "'" + + def toJson(self, val): + return self.toString(val) # for now + + def create_translation(self, array_idx, line, context, disambiguation): + iso_code = self.translation_lang[array_idx] + key = line[self.default_header[array_idx]] + i18n = line[self.translation_header[array_idx]] + if len(i18n) == 0: + return + self.ins_translation.append("INSERT INTO pdm.pdm_translation (iso_code, disambiguation, context, key, translation) VALUES (%s, %s, %s, %s, %s);" % (self.toString(iso_code), self.toString(disambiguation), self.toString(context), self.toString(key), self.toString(i18n))) + + def gear_type(self, line): + if len(line[0]) == 0: + return + # id;tas_code;name [de_DE];name [en_GB];gear_class_id + id = self.toInt(line[0]) + + self.ins_gear_type.append("INSERT INTO pdm.pdm_gear_type (id, tas_code, name, gear_class_id, properties) VALUES (%s, %s, %s, %s, %s);" % (id, self.toInt(line[1]), self.toString(line[2]), self.toInt(line[4]), self.toString(line[5]))) + + self.create_translation(0, line, 'GearType', 'name') + + def charge_type(self, line): + if len(line[0]) == 0: + return + # 0- 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 + # id,legacy_id,given_name,name [de_DE],shortName [de_DE],name [en_GB],shortName [en_GB],properties,gear_type,max_range,properties,gear_type,max_range,properties,dis_code + + id = self.toInt(line[0]) + legacy_id = self.toInt(line[1]) + predefined_name = self.toString(line[2]) + name = self.toString(line[3]) + short_name = self.toString(line[4]) + props = self.toJson(line[7]) + dis_entity = self.toJson(line[14]) if len(line) > 14 else 'NULL'; + properties_1 = self.toJson(line[10]) + properties_2 = self.toJson(line[13]) + + self.ins_charge_type.append("INSERT INTO pdm.pdm_charge_type (id, predefined_name, name, short_name, properties, dis_entity, charge_legacy_id) VALUES (%s, %s, %s, %s, %s, %s, %s);" % (id, predefined_name, name, short_name, props, dis_entity, legacy_id)) + + self.upd_charge_type.append("UPDATE pdm.pdm_charge_type SET predefined_name = %s, name = %s, short_name = %s, properties = %s, dis_entity = %s, charge_legacy_id = %s WHERE ID = %s;" % (predefined_name, name, short_name, props, dis_entity, legacy_id, id)) + + for i in (8,11): + if i >= len(line): break + gt = line[i] + if gt == '': continue + range = '' + if i + 1 < len(line): + range = line[i+1] + if properties_1 == "NULL": + self.ins_gear_type_charge_type.append("INSERT INTO pdm.pdm_gear_type_charge_type (gear_type_id, charge_type_id, max_range) VALUES (%s, %s, %s);" % (gt, id, self.toInt(range))) + else: + self.ins_gear_type_charge_type.append("INSERT INTO pdm.pdm_gear_type_charge_type (gear_type_id, charge_type_id, max_range, properties) VALUES (%s, %s, %s, %s);" % (gt, id, self.toInt(range), properties_1)) + + self.create_translation(0, line, 'ChargeType', 'name') + self.create_translation(1, line, 'ChargeType', 'shortName') + + def igniter_type(self, line): + if len(line[0]) == 0: + return + # id;name [de_DE];shortName [de_DE],name [en_GB];shortName [en_GB];properties + id = self.toInt(line[0]) + name = self.toString(line[1]) + short_name = self.toString(line[2]) + props = self.toJson(line[5]) + + self.ins_igniter_type.append("INSERT INTO pdm.pdm_igniter_type (id, name, short_name, properties) VALUES (%s, %s, %s, %s);" % (id, name, short_name, props)) + + self.create_translation(0, line, 'IngiterType', 'name') + self.create_translation(1, line, 'IgniterType', 'shortName') + + def igniter_function(self, line): + if len(line[0]) == 0: + return + # id;name [de_DE];shortName [de_DE],name [en_GB];shortName [en_GB];properties + id = self.toInt(line[0]) + name = self.toString(line[1]) + short_name = self.toString(line[2]) + props = self.toJson(line[5]) + + self.ins_igniter_function.append("INSERT INTO pdm.pdm_igniter_function (id, name, short_name, properties) VALUES (%s, %s, %s, %s);" % (id, name, short_name, props)) + + self.create_translation(0, line, 'IngiterFunction', 'name') + self.create_translation(1, line, 'IgniterFunction', 'shortName') + + def charge_type_igniter_type_igniter_function(self, line): + if len(line[0]) == 0: + return + # charge_type_id;igniter_type_id;igniter_function_id;impact_area,impact_radius;hazard_distance;charge_legacy_id;igniter_function_base_id;properties + charge_type_id = self.toInt(line[0]) + igniter_type_id = self.toInt(line[1]) + igniter_function_id = self.toInt(line[2]) + impact_area = self.toJson(line[3]) + impact_radius = self.toInt(line[4]) + hazard_distance = self.toInt(line[5]) + charge_legacy_id = self.toInt(line[6]) + igniter_function_base_id = self.toInt(line[7]) + props = self.toJson(line[8]) + + self.ins_charge_type_igniter_type_igniter_function.append("INSERT INTO pdm.pdm_charge_type_igniter_type_igniter_function (charge_type_id, igniter_type_id, igniter_function_id, impact_area, impact_radius, hazard_distance, charge_legacy_id, igniter_function_base_id, properties) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s);" % (charge_type_id, igniter_type_id, igniter_function_id, impact_area, impact_radius, hazard_distance, charge_legacy_id, igniter_function_base_id, props)) + + def load_type(self, line): + if len(line[0]) == 0: + return + # id;name [de_DE];shortName [de_DE],name [en_GB];shortName [en_GB];properties + id = self.toInt(line[0]) + name = self.toString(line[1]) + short_name = self.toString(line[2]) + props = self.toJson(line[5]) + + self.ins_load_type.append("INSERT INTO pdm.pdm_load_type (id, name, short_name, properties) VALUES (%s, %s, %s, %s);" % (id, name, short_name, props)) + + self.create_translation(0, line, 'LoadType', 'name') + self.create_translation(1, line, 'LoadType', 'shortName') + + def charge_type_load_type(self, line): + if len(line[0]) == 0: + return + # charge_type_id;load_type_id;numbers;properties + charge_type_id = self.toInt(line[0]) + load_type_id = self.toInt(line[1]) + numbers = self.toString(line[2]) + props = self.toJson(line[3]) + + self.ins_charge_type_load_type.append("INSERT INTO pdm.pdm_charge_type_load_type (charge_type_id, load_type_id, numbers, properties) VALUES (%s, %s, %s, %s);" % (charge_type_id, load_type_id, numbers, props)) + + + def building_charge_effect(self, line): + if len(line[0]) == 0: + return + # id, charge_type_id;destructive_factor;penetration_factor;hit_sound;difcue_light;difcue_pyro + + ky = self.toInt(line[0]) + ct = self.toInt(line[1]) + df = self.toInt(line[2]) + pf = self.toInt(line[3]) + hs = self.toInt(line[4]) + dl = self.toBool(line[5]) + dp = self.toBool(line[6]) + + self.ins_building_charge_effect.append("INSERT INTO pdm.pdm_building_charge_effect (id, charge_type_id, destructive_factor, penetration_factor, hit_sound, difcue_light, difcue_pyro) VALUES (%s, %s, %s, %s, %s, %s, %s);" % (ky, ct, df, pf, hs, dl, dp)) + + def can_component_string(self, line): + if len(line[0]) == 0: + return + + # name [de_DE], name [en_GB], bit_mask, can_device_id, sub_device_id + name = self.toString(line[0]) + bm = self.toInt(line[2]) + cd = self.toInt(line[3]) + sd = self.toInt(line[4]) + self.ins_can_component_string.append("INSERT INTO pdm.pdm_can_component_string (name, bit_mask, can_device_id, sub_device_id) VALUES (%s, %s, %s, %s);" % (name, bm, cd, sd)) + self.create_translation(0, line, 'CanComponentString', 'name') + + def bite_component_text(self, line): + if len(line[0]) == 0: + return + + # can_device_id, sub_device_id, error_number, name + name = self.toString(line[0]) + cd = self.toInt(line[2]) + sd = self.toInt(line[3]) + er = self.toInt(line[4]) + self.ins_bite_component_text.append("INSERT INTO pdm.pdm_bite_component_text (name, can_device_id, sub_device_id, error_number) VALUES (%s, %s, %s, %s);" % (name, cd, sd, er)) + self.create_translation(0, line, 'BiteComponentText', 'name') + + def equipment_system_event_filter(self, line): + if len(line[0]) == 0: + return + + # equipment_functional_id, sub_device_id, device_specific_code, hgr_mine_search_filter_type_id + ef = self.toInt(line[0]) + sd = self.toInt(line[1]) + dsc = self.toInt(line[2]) + hgr = self.toInt(line[3]) + self.ins_pdm_equipment_system_event_filter.append("INSERT INTO pdm.pdm_equipment_system_event_filter (equipment_functional_id, sub_device_id, device_specific_code, hgr_mine_search_filter_type_id) VALUES (%s, %s, %s, %s);" % (ef, sd, dsc, hgr)) + + def event_filter_hgr_mine_search(self, line): + if len(line[0]) == 0: + return + + # hgr_mine_search_filter_type_idm, charge_type_id + hgr = self.toInt(line[0]) + ct = self.toInt(line[1]) + self.ins_pdm_event_filter_hgr_mine_search.append("INSERT INTO pdm.pdm_event_filter_hgr_mine_search (hgr_mine_search_filter_type_id, charge_type_id) VALUES (%s, %s);" % (hgr, ct)) + + def radio_group(self, line): + if len(line[0]) == 0: + return + + txt = (self.toInt(line[0]), self.toString(line[1]), self.toBool(line[2]), self.toInt(line[3]), self.toInt(line[4]), self.toInt(line[5]), self.toString(line[6]), self.toInt(line[7]), self.toString(line[8]), self.toInt(line[9])) + if len(line) > 10: + self.create_translation(0, line, 'RadioGroup', 'name') + # id, name[def], base_group, issi, group_issi1, group_issi2, radio_hostname, radio_port, radio_backup_hostname, radio_backup_port, name[en_GB] (optional) + self.ins_radio_group.append("INSERT INTO pdm.pdm_radio_group (id, name, base_group, issi, group_issi1, group_issi2, radio_hostname, radio_port, radio_backup_hostname, radio_backup_port) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s);" % txt); + + def fire_purpose(self, line): + if len(line[0]) == 0: + return + + # id, name [de_DE], name [en_GB], Description, properties + id = self.toInt(line[0]) + name = self.toString(line[1]) + props = self.toJson(line[4]) + txt = (id, name, props) + self.ins_fire_purpose.append("INSERT INTO pdm.pdm_fire_purpose (id, name, properties) VALUES (%s, %s, %s);" % txt) + self.create_translation(0, line, 'FirePurpose', 'name') + + def target_type(self, line): + if len(line[0]) == 0: + return + + # id, name [de_DE], name [en_GB], abbreviation + id = self.toInt(line[0]) + name = self.toString(line[1]) + abbr = self.toString(line[3]) + props = self.toJson(line[4]) + txt = (id, name, abbr, props) + self.ins_target_type.append("INSERT INTO pdm.pdm_target_type (id, name, abbreviation, properties) VALUES (%s, %s, %s, %s);" % txt) + self.create_translation(0, line, 'TargetType', 'name') + + def target_subtype(self, line): + if len(line[0]) == 0: + return + + # id, name [de_DE], name [en_GB], abbreviation + id = self.toInt(line[0]) + name = self.toString(line[1]) + abbr = self.toString(line[3]) + props = self.toJson(line[4]) + txt = (id, name, abbr, props) + self.ins_target_subtype.append("INSERT INTO pdm.pdm_target_subtype (id, name, abbreviation, properties) VALUES (%s, %s, %s, %s);" % txt) + self.create_translation(0, line, 'TargetSubType', 'name') + + + def target_type_target_subtype(self, line): + if len(line[0]) == 0: + return + + # target_type_id;target_subtype_id + targetTypeId = self.toInt(line[0]) + targetSubtypeId = self.toString(line[1]) + props = self.toJson(line[2]) + txt = (targetTypeId, targetSubtypeId, props) + self.ins_target_type_target_subtype.append("INSERT INTO pdm.pdm_target_type_target_subtype (target_type_id, target_subtype_id, properties) VALUES (%s, %s, %s);" % txt) + + def nuclear_preset(self, line): + if len(line[0]) == 0: + return + + # id name [de_DE] name [en_GB] detonation_value impact_radius border_length_inner border_length_outer + id = self.toInt(line[0]) + name = self.toString(line[1]) + det = self.toFloat(line[3]) + imp = self.toInt(line[4]) + bli = self.toInt(line[5]) + blo = self.toInt(line[6]) + txt = (id, name, det, imp, bli, blo) + self.ins_nuclear_preset.append("INSERT INTO pdm.pdm_nuclear_preset (id, name, detonation_value, impact_radius, border_length_inner, border_length_outer) VALUES (%s, %s, %s, %s, %s, %s);" % txt) + self.create_translation(0, line, 'NuclearPreset', 'name') + + def vulnerability_kind(self, line): + if len(line[0]) == 0: + return + + # player_type_class_id;ta_vulnerability_kind;vulnerability_class_id;name [de_DE];name [en_GB];Teilnehmer-Name;Teilnehmer-Typ;Index;Fallback + id = self.toInt(line[0]) + kind = self.toInt(line[1]) + cls = self.toInt(line[2]) + name = self.toString(line[3]) + txt = (id, kind, cls, name) + self.ins_vulnerability_kind.append("INSERT INTO pdm.pdm_vulnerability_kind (player_type_class_id, ta_vulnerability_kind, vulnerability_class_id, name) VALUES (%s, %s, %s, %s);" % txt) + self.create_translation(0, line, 'VulnerabilityKind', 'name') + + def usage(): + print "Usage: %s " % sys.argv[0] + print "usage: $0 -p " + print " -p (--project) : guez / ahtc " + +def main(): + + p = sql_generator() + + try: + opts, args = getopt.getopt(sys.argv[1:], "p:", ["project"]) + except getopt.GetoptError, err: + print >> sys.stderr, err + usage() + sys.exit(2) + for o, a in opts: + if o in ("-p", "--project"): + p.project = a + print >> sys.stderr, "PROJECT: %s" % a + + p.initialize() + + p.execute() + + sys.exit(0) + +if __name__ == "__main__": + main() + diff --git a/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/test_scenario_definitions.py b/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/test_scenario_definitions.py new file mode 100755 index 000000000..4876159c2 --- /dev/null +++ b/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/test_scenario_definitions.py @@ -0,0 +1,10 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# Participant Ids +# 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 +PPM1_participant_id = str(' 5, 6, 7, 8, 9, 12, 13, 14, 15, 16, 18, 19, 20, 21, 24, 25, 57, 58, 30, 31, 32, 52, 53, 54, 55, 90, 91, 92, 93, 95, 96, 97, 98').split(', ') +PPM1_type_id = str(' 55, 55, 55, 74, 74, 55, 55, 55, 55, 55, 78, 78, 57, 57, 27, 29, 54, 54, 77, 77, 78, 78, 78, 57, 57, 173, 173, 173, 173, 173, 173, 173, 173').split(', ') +PPM1_party_id = str(' 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 3, 3, 3, 4, 4, 4, 4, 2, 2, 2, 2, 3, 3, 3, 3').split(', ') +PPM1_equip_no = str('1201, 1202, 1203, 1204, 1205, 1206, 1207, 1208, 1209, 1210, 3801, 3802, 4401, 4402, 3803, 4403, 2501, 2502, 2001, 2002, 2003, 2011, 2012, 2013, 2014, 0, 0, 0, 0, 0, 0, 0, 0').split(', ') + diff --git a/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/test_scenario_participant_positions.py b/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/test_scenario_participant_positions.py new file mode 100755 index 000000000..516f73830 --- /dev/null +++ b/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/test_scenario_participant_positions.py @@ -0,0 +1,47 @@ +#!/usr/bin/python + +from test_scenario_definitions import * +import time + +def generate_participant_positions(): + + start_time = int(time.time()) * 1000 + + stmts = [] + + data_lat = 0.925926; + data_lon = 0.155215; + for i in range(0, 25): + data_lat += 0.000002 + start_time += 100 + + stmt = 'INSERT INTO ex_42.rec_participant_position ( participant_id, participant_type_id, party_id, pos_lon, pos_lat, pos_z, sample_time ) VALUES ( %s, %s, 2, %s, %s, 0, %s )' % (PPM1_participant_id[i], PPM1_type_id[i], data_lon, data_lat, start_time ) + + stmt += ';' + stmts.append(stmt) + + for i in range(0, 25): + data_lon += 0.000005 + start_time += 100 + + stmt = 'INSERT INTO ex_42.rec_participant_position ( participant_id, participant_type_id, party_id, pos_lon, pos_lat, pos_z, sample_time ) VALUES ( %s, %s, 2, %s, %s, 0, %s )' % (PPM1_participant_id[i], PPM1_type_id[i], data_lon, data_lat, start_time ) + + stmt += ';' + stmts.append(stmt) + + + data_lat = 0.929926; + data_lon = 0.156215; + for i in range(26, 33): + data_lat += 0.000002 + start_time += 100 + + stmt = 'INSERT INTO ex_42.rec_participant_position ( participant_id, participant_type_id, party_id, pos_lon, pos_lat, pos_z, sample_time ) VALUES ( %s, %s, 2, %s, %s, 0, %s )' % (PPM1_participant_id[i], PPM1_type_id[i], data_lon, data_lat, start_time ) + + stmt += ';' + stmts.append(stmt) + return stmts + +if __name__ == "__main__": + print '\n'.join(generate_participant_positions()) + diff --git a/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/test_scenario_participant_state.py b/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/test_scenario_participant_state.py new file mode 100755 index 000000000..4f61e34bd --- /dev/null +++ b/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/test_scenario_participant_state.py @@ -0,0 +1,179 @@ +#!/usr/bin/python + +from test_scenario_definitions import * +import time +import json + +def generate_participant_state(): + + start_time = int(time.time()) * 1000 + + stmts = [] + +# sanitation material + #start_time += 100 + + stock = [] + for i in range(1, 5): + tmp1 = dict() + tmp1['materialId'] = i; + tmp1['materialCount'] = i*10; + stock.append(tmp1) + + json_str_stock = json.dumps(stock) + #stmt = 'INSERT INTO ex_42.rec_dynamic_participant_data (sanitation_material_stock, participant_id, sample_time, sanitation_unique_id, qualification ) VALUES (\'%s\', %s, %s, %s, %s )' % (json_str, PPM1_participant_id[i], start_time, 123, 0 ) + + #stmt += ';' + #stmts.append(stmt) + +# firings + for i in range(0, 9): + start_time += 100 + + tmp = dict() + if ((i%2) == 0): + tmp['originatorChargeTypeId'] = 38; + else: + tmp['originatorChargeTypeId'] = 39; + tmp['stateTime'] = start_time; + tmp['vulnerabilityState'] = i; + tmp['originatorId'] = 0; + tmp['originatorType'] = 1; #participant + tmp['vulnerabilityKindId'] = 0; + tmp['vulnerabilityBits'] = 2**i; + + data = [] + data.append(tmp) + json_str = json.dumps(data) + stmt = 'INSERT INTO ex_42.rec_dynamic_participant_data ( state_history, sanitation_material_stock, sanitation_unique_id, qualification, has_nbc_protection_active, has_nbc_protection_configured, participant_id, sample_time ) VALUES (\'%s\', \'%s\', \'%s\', \'%s\', false, false, %s, %s )' % (json_str, json_str_stock, 123, 2, PPM1_participant_id[i], start_time ) + + stmt += ';' + stmts.append(stmt) + +# nbc + for i in range(13, 15): + start_time += 100 + + tmp = dict() + tmp['originatorChargeTypeId'] = 341; #chemical agent + tmp['stateTime'] = start_time; + tmp['vulnerabilityState'] = 5; + tmp['originatorId'] = 3; #nbc + tmp['originatorType'] = 2; #area effect simulation + tmp['vulnerabilityKindId'] = 0; + tmp['vulnerabilityBits'] = 2**5; + + data = dict() + data['ParticipantManagement::StateInformation'] = [] + data['ParticipantManagement::StateInformation'].append(tmp) + json_str = json.dumps(data) + stmt = 'INSERT INTO ex_42.rec_dynamic_participant_data ( state_history, has_nbc_protection_active, has_nbc_protection_configured, participant_id, sample_time ) VALUES (\'%s\', false, false, %s, %s )' % (json_str, PPM1_participant_id[i], start_time ) + + stmt += ';' + stmts.append(stmt) + +# mine area + for i in range(15, 17): + start_time += 100 + + tmp = dict() + tmp['originatorChargeTypeId'] = 351; #mine area + tmp['stateTime'] = start_time; + tmp['vulnerabilityState'] = 8; + tmp['originatorId'] = 2; #mine + tmp['originatorType'] = 2; #area effect simulation + tmp['vulnerabilityKindId'] = 0; + tmp['vulnerabilityBits'] = 2**8; + + data = dict() + data['ParticipantManagement::StateInformation'] = [] + data['ParticipantManagement::StateInformation'].append(tmp) + json_str = json.dumps(data) + stmt = 'INSERT INTO ex_42.rec_dynamic_participant_data ( state_history, has_nbc_protection_active, has_nbc_protection_configured, participant_id, sample_time ) VALUES (\'%s\', false, false, %s, %s )' % (json_str, PPM1_participant_id[i], start_time ) + + stmt += ';' + stmts.append(stmt) + +# functional area + for i in range(10, 13): + start_time += 100 + + tmp = dict() + tmp['originatorChargeTypeId'] = 411; #functional area + tmp['stateTime'] = start_time; + tmp['vulnerabilityState'] = 0; + tmp['originatorId'] = 4; #functional area + tmp['originatorType'] = 2; #area effect simulation + tmp['vulnerabilityKindId'] = 0; + tmp['vulnerabilityBits'] = 0; + + data = dict() + data['ParticipantManagement::StateInformation'] = [] + data['ParticipantManagement::StateInformation'].append(tmp) + json_str = json.dumps(data) + stmt = 'INSERT INTO ex_42.rec_dynamic_participant_data ( state_history, has_nbc_protection_active, has_nbc_protection_configured, participant_id, sample_time ) VALUES (\'%s\', false, false, %s, %s )' % (json_str, PPM1_participant_id[i], start_time ) + + stmt += ';' + stmts.append(stmt) + +# explosive device + for i in range(18, 21): + start_time += 100 + + tmp = dict() + if ((i%2) == 0): + tmp['originatorChargeTypeId'] = 48; + else: + tmp['originatorChargeTypeId'] = 49; + tmp['stateTime'] = start_time; + tmp['vulnerabilityState'] = i-17; #1,2,3 + tmp['originatorId'] = 1; #ied 1 + tmp['originatorType'] = 20; #improvisedExplosiveDevice + tmp['vulnerabilityKindId'] = 0; + tmp['vulnerabilityBits'] = 2**(i-17); + + data = [] + data.append(tmp) + +# tmp1 = dict() +# tmp1['originatorChargeTypeId'] = 70; +# tmp1['stateTime'] = start_time; +# tmp1['vulnerabilityState'] = 8; +# tmp1['originatorId'] = 1; #ied 1 +# tmp1['originatorType'] = 20; #improvisedExplosiveDevice +# tmp1['vulnerabilityKindId'] = 289; +# tmp1['vulnerabilityBits'] = 256; + +# data.append(tmp1) + + json_str = json.dumps(data) + stmt = 'INSERT INTO ex_42.rec_dynamic_participant_data ( state_history, has_nbc_protection_active, has_nbc_protection_configured, participant_id, sample_time ) VALUES (\'%s\', false, false, %s, %s )' % (json_str, PPM1_participant_id[i], start_time ) + + stmt += ';' + stmts.append(stmt) + +# air support + for i in range(21, 24): + start_time += 100 + + tmp = dict() + tmp['originatorChargeTypeId'] = 471; + tmp['stateTime'] = start_time; + tmp['vulnerabilityState'] = 8; + tmp['originatorId'] = 0; + tmp['originatorType'] = 2; #area effect simulation + tmp['vulnerabilityKindId'] = 0; + tmp['vulnerabilityBits'] = 2**8; + + data = [] + data.append(tmp) + json_str = json.dumps(data) + stmt = 'INSERT INTO ex_42.rec_dynamic_participant_data ( state_history, has_nbc_protection_active, has_nbc_protection_configured, participant_id, sample_time ) VALUES (\'%s\', false, false, %s, %s )' % (json_str, PPM1_participant_id[i], start_time ) + + stmt += ';' + stmts.append(stmt) + + return stmts + +if __name__ == "__main__": + print '\n'.join(generate_participant_state()) diff --git a/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/update_barcode_mpa.py b/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/update_barcode_mpa.py new file mode 100755 index 000000000..7ece2e073 --- /dev/null +++ b/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/update_barcode_mpa.py @@ -0,0 +1,48 @@ +#!/usr/bin/python +# This Python file uses the following encoding: utf-8 + +import sys +from collections import OrderedDict + +#asset_id,asset_barcode,structure_element_id,se_barcode,main_structure_element_id,name + + +def readBarcodes(filename): + """Create a dictionary { name, MSE-name : barcode }.""" + ret = OrderedDict() + + with open(filename, "r") as f: + lines = f.read().split("\n") + cols = lines[0].strip().split(',') + + #assert cols[0].lower() == "asset_id" + assert cols[1].lower() == "asset_barcode" + assert cols[3].lower() == "se_barcode" + + rows = [line.strip() for line in lines[1:] if line.strip() != ""] + for row in rows: + items = row.split(",") + ret[items[1]] = items[3] + + return ret + + +def appendBarcodeUpdates(outputFile, barcodes): + """Append an SQL INSERT statement for barcodes.""" + lines = [] + for key in barcodes.keys(): + asset_barcode = key + update = "INSERT INTO ism.ism_mounting_point_asset (asset_id, structure_element_id) VALUES ((SELECT id FROM ism.ism_asset WHERE barcode = '%s'), (SELECT id FROM ism.ism_structure_element WHERE barcode = '%s' ));" % (asset_barcode, barcodes[key]) + lines.append(update) + + with open(outputFile, "w") as f: + for line in lines: + f.write(line + "\n") + + +if __name__ == "__main__": + barcodeFile = sys.argv[1] + barcodes = readBarcodes(barcodeFile) + + sqlOutputFile = sys.argv[2] + appendBarcodeUpdates(sqlOutputFile, barcodes) diff --git a/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/update_barcode_se.py b/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/update_barcode_se.py new file mode 100755 index 000000000..ffdc166c2 --- /dev/null +++ b/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/update_barcode_se.py @@ -0,0 +1,47 @@ +#!/usr/bin/python +# This Python file uses the following encoding: utf-8 + +import sys +from collections import OrderedDict + + +def readBarcodes(filename): + """Create a dictionary { name, MSE-name : barcode }.""" + ret = OrderedDict() + + with open(filename, "r") as f: + lines = f.read().split("\n") + cols = lines[0].strip().split(',') + + assert cols[1].lower() == "name" + #assert cols[2].lower() == "main_structure_element_id" + assert cols[3].lower() == "main_name" + assert cols[4].lower() == "barcode" + + rows = [line.strip() for line in lines[1:] if line.strip() != ""] + for row in rows: + items = row.split(",") + ret[items[1], items[3]] = items[4] + + return ret + + +def appendBarcodeUpdates(outputFile, barcodes): + """Append an SQL UPDATE statement for barcodes.""" + lines = [] + for key in barcodes.keys(): + name, main_name = key + update = "UPDATE ism.ism_structure_element SET barcode = '%s' WHERE main_structure_element_id = (SELECT id FROM ism.ism_main_structure_element WHERE name = '%s') AND name = '%s';" % (barcodes[key], main_name, name) + lines.append(update) + + with open(outputFile, "w") as f: + for line in lines: + f.write(line + "\n") + + +if __name__ == "__main__": + barcodeFile = sys.argv[1] + barcodes = readBarcodes(barcodeFile) + + sqlOutputFile = sys.argv[2] + appendBarcodeUpdates(sqlOutputFile, barcodes) diff --git a/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/update_charge_types.py b/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/update_charge_types.py new file mode 100755 index 000000000..d46232313 --- /dev/null +++ b/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/update_charge_types.py @@ -0,0 +1,67 @@ +#!/usr/bin/python +# This Python file uses the following encoding: utf-8 + +import sys + + +def read(filename): + """Read a file and return a list of the lines.""" + with open(filename, 'r') as f: + lines = f.read().split('\n') + return lines + + +def write(filename, lines): + """Write a file for a given list of lines.""" + with open(filename, 'w') as f: + for line in lines: + f.write(line + '\n') + + +def loadChargeTypes(filename): + """Read old and new charge types from a .csv file to a dictionary { old_id : new_id }.""" + chargeTypes = {} + with open(filename, 'r') as f: + lines = f.read().split('\n') + for line in lines[1:]: + line = line.replace('\r', '') + try: + old, new = line.split(';') + + if old in chargeTypes.keys(): + print("duplicate old charge type &s".arg(old)) + continue + + chargeTypes[old] = new + except: + pass + return chargeTypes + + +def replaceChargeTypes(lines, chargeTypes): + """Replace all 'chargeTypeId' entries with new ones.""" + def replace(iLine, line): + if "chargetypeid" in line.lower(): # ignore lines without charge type ID + items = line.split() # get all items in line separated by whitespace + for i, item in enumerate(map(lambda x: x.lower(), items)): # .lower() to catch all cases + if "chargetypeid" in item: + oldId = items[i+1].replace(',', '').replace('}', '').replace(']', '').replace("'",'') # remove characters to obtain ID + try: + newId = chargeTypes[oldId] # try lookup in chargeTypes + items[i+1] = items[i+1].replace(oldId, newId) # replace old ID with new ID + except: + if int(oldId) < -2: # any ID < -2 becomes 0 + items[i+1] = items[i+1].replace(oldId, '0') + else: # -1 and -2 are valid IDs + pass + line = ' '.join(items) # rejoin items to new line + return line + + return [replace(i, line) for i, line in enumerate(lines)] # simple list comprehension to get file content with updated IDs + + +if __name__ == "__main__": + chargeTypes = loadChargeTypes(sys.argv[1]) + db = read(sys.argv[2]) + db = replaceChargeTypes(db, chargeTypes) + write(sys.argv[3], db) diff --git a/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/update_ism_plans.py b/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/update_ism_plans.py new file mode 100755 index 000000000..3ec01598e --- /dev/null +++ b/qt6-after/qt6-migrated-legatus/Lts/Tests/DatabaseInitialisation/update_ism_plans.py @@ -0,0 +1,48 @@ +#!/usr/bin/python +# This Python file uses the following encoding: utf-8 + +import sys +from collections import OrderedDict + +#id,mounting_point_schedule_id,structure_element_id,main_structure_element_id,name,main_name + +def readBarcodes(filename): + ret = OrderedDict() + + with open(filename, "r") as f: + lines = f.read().split("\n") + cols = lines[0].strip().split(',') + + assert cols[1].lower() == "mounting_point_schedule_id" + assert cols[2].lower() == "structure_element_id" + assert cols[3].lower() == "main_structure_element_id" + assert cols[4].lower() == "name" + assert cols[5].lower() == "main_name" + + rows = [line.strip() for line in lines[1:] if line.strip() != ""] + for row in rows: + items = row.split(",") + ret[items[1], items[4], items[5]] = items[2] + + return ret + + +def appendBarcodeUpdates(outputFile, barcodes): + """Append an SQL INSERT statement for MPP.""" + lines = [] + for key in barcodes.keys(): + mpp_id, name, main_name = key + update = "INSERT INTO ism.ism_mounting_point_plan (mounting_point_schedule_id, structure_element_id) VALUES (%s, (select se.id from ism.ism_structure_element se, ism.ism_main_structure_element mse where se.name = '%s' AND mse.id = se.main_structure_element_id AND mse.name = '%s'));" % (mpp_id, name, main_name) + lines.append(update) + + with open(outputFile, "w") as f: + for line in lines: + f.write(line + "\n") + + +if __name__ == "__main__": + barcodeFile = sys.argv[1] + barcodes = readBarcodes(barcodeFile) + + sqlOutputFile = sys.argv[2] + appendBarcodeUpdates(sqlOutputFile, barcodes) diff --git a/qt6-after/qt6-migrated-legatus/db-manage.sh b/qt6-after/qt6-migrated-legatus/db-manage.sh old mode 100644 new mode 100755 index 81482f241..6f4bbc134 --- a/qt6-after/qt6-migrated-legatus/db-manage.sh +++ b/qt6-after/qt6-migrated-legatus/db-manage.sh @@ -215,38 +215,7 @@ cmd_init_db() { log_info "Initializing database for project: ${project}" - # Determine create_excon_db.py arguments - local db_args="" - case "${project}" in - guez) - db_args="-p guez" - ;; - ahtc) - db_args="-p ahtc" - ;; - qatar) - db_args="-p qatar" - ;; - l400p2) - db_args="-p l400p2" - ;; - demo) - db_args="-p demo" - ;; - commaster) - db_args="-p commaster" - ;; - test-db) - db_args="-p guez -e" - ;; - *) - log_error "Unknown project: ${project}" - log_info "Valid projects: guez, ahtc, qatar, l400p2, demo, commaster, test-db" - return 1 - ;; - esac - - # Find create_excon_db.py script + # Install Python3 in container temporarily and execute create_excon_db.py local script_path="${SCRIPT_DIR}/Lts/Tests/DatabaseInitialisation/create_excon_db.py" if [ ! -f "${script_path}" ]; then @@ -254,28 +223,121 @@ cmd_init_db() { return 1 fi - # Copy script to container and execute + log_info "Installing Python3 in container (temporary)..." + docker exec "${CONTAINER_NAME}" apt-get update -qq >/dev/null 2>&1 || true + docker exec "${CONTAINER_NAME}" apt-get install -y -qq python3 >/dev/null 2>&1 || { + log_warn "Could not install python3, using direct SQL execution instead" + # Fallback: execute SQL files directly + cmd_init_db_sql "${project}" + return $? + } + + # Determine create_excon_db.py arguments + local db_args="" + case "${project}" in + guez) db_args="-p guez" ;; + ahtc) db_args="-p ahtc" ;; + qatar) db_args="-p qatar" ;; + l400p2) db_args="-p l400p2" ;; + demo) db_args="-p demo" ;; + commaster) db_args="-p commaster" ;; + test-db) db_args="-p guez -e" ;; + *) + log_error "Unknown project: ${project}" + return 1 + ;; + esac + log_info "Executing create_excon_db.py ${db_args}..." - docker exec -i "${CONTAINER_NAME}" /bin/bash -c "cat > /tmp/create_excon_db.py && chmod +x /tmp/create_excon_db.py" < "${script_path}" + # Copy script to container + docker cp "${script_path}" "${CONTAINER_NAME}:/tmp/create_excon_db.py" + docker exec "${CONTAINER_NAME}" chmod +x /tmp/create_excon_db.py - # Read lts-cc.conf for database configuration + # Copy lts-cc.conf if exists + local config_arg="" if [ -f "${LTS_CC_CONF}" ]; then - local db_host db_name - db_host=$(grep -E "^DatabaseHostName=" "${LTS_CC_CONF}" | cut -d'=' -f2) - db_name=$(grep -E "^DatabaseName=" "${LTS_CC_CONF}" | cut -d'=' -f2) - - # Execute with config file - docker exec -i "${CONTAINER_NAME}" /bin/bash -c " - cat > /tmp/lts-cc.conf - cat > /tmp/create_excon_db.py && chmod +x /tmp/create_excon_db.py - cd /tmp && python3 /tmp/create_excon_db.py ${db_args} -c /tmp/lts-cc.conf -b /tmp - " < "${LTS_CC_CONF}" - else - # Execute without config file (uses defaults) - docker exec "${CONTAINER_NAME}" python3 /tmp/create_excon_db.py ${db_args} + docker cp "${LTS_CC_CONF}" "${CONTAINER_NAME}:/tmp/lts-cc.conf" + config_arg="-c /tmp/lts-cc.conf" fi + # Copy SQL files to container + local sql_dir="${SCRIPT_DIR}/Lts/Tests/DatabaseInitialisation" + docker exec "${CONTAINER_NAME}" mkdir -p /tmp/sql + for f in "${sql_dir}"/*.sql; do + if [ -f "$f" ]; then + docker cp "$f" "${CONTAINER_NAME}:/tmp/sql/" + fi + done + + # Execute create_excon_db.py in container + docker exec -w /tmp "${CONTAINER_NAME}" python3 /tmp/create_excon_db.py ${db_args} ${config_arg} -b /tmp + + log_info "Database initialization completed for project: ${project}" +} + +# Fallback: Initialize database by executing SQL files directly +cmd_init_db_sql() { + local project="${1:-}" + local sql_dir="${SCRIPT_DIR}/Lts/Tests/DatabaseInitialisation" + + log_info "Executing SQL files directly for project: ${project}" + + # List of base SQL files to execute + local base_files=( + "init_db_users_grants.sql" + "init_db_procedures.sql" + "init_db_schemas.sql" + ) + + # Project-specific files + local project_files=() + case "${project}" in + guez) + project_files=( + "guez_ppm_values_types.sql" + "guez_ppm_values_templates.sql" + "guez_pdm_values.sql" + "guez_pdm_values_translation.sql" + "guez_opm_values_initial.sql" + "guez_opm_values.sql" + "guez_flm_symbols.sql" + "guez_update_flm_used_by.sql" + ) + ;; + ahtc) + project_files=( + "ahtc_ppm_values_types.sql" + "ahtc_ppm_values_templates.sql" + "ahtc_pdm_values.sql" + "ahtc_opm_values.sql" + "ahtc_flm_symbols.sql" + ) + ;; + *) + log_warn "Direct SQL execution not fully implemented for ${project}" + return 1 + ;; + esac + + # Execute base files + for f in "${base_files[@]}"; do + if [ -f "${sql_dir}/${f}" ]; then + log_info "Executing: ${f}" + docker exec -i "${CONTAINER_NAME}" psql -U postgres -d lts_ets_pro -f "/tmp/sql/${f}" 2>&1 | head -5 + fi + done + + # Execute project files + for f in "${project_files[@]}"; do + if [ -f "${sql_dir}/${f}" ]; then + log_info "Executing: ${f}" + docker exec -i "${CONTAINER_NAME}" psql -U postgres -d lts_ets_pro -f "/tmp/sql/${f}" 2>&1 | head -5 + else + log_warn "SQL file not found: ${f}" + fi + done + log_info "Database initialization completed for project: ${project}" } diff --git a/qt6-after/qt6-migrated-legatus/packaging/deb/build-deb-packages.sh b/qt6-after/qt6-migrated-legatus/packaging/deb/build-deb-packages.sh new file mode 100644 index 000000000..74e7d1ac3 --- /dev/null +++ b/qt6-after/qt6-migrated-legatus/packaging/deb/build-deb-packages.sh @@ -0,0 +1,74 @@ +# DEB Packaging Build Script for Legatus Qt6 +# +# This script builds all DEB packages from the packaging directory structure. +# +# Usage: +# ./build-deb-packages.sh [version] +# +# Example: +# ./build-deb-packages.sh 15.6-qt6.10.2 +# + +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +VERSION="${1:-15.6-qt6.10.2}" +OUTPUT_DIR="${SCRIPT_DIR}/output" +PACKAGING_DIR="${SCRIPT_DIR}/packaging/deb" + +# Colors +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +NC='\033[0m' + +log_info() { + echo -e "${GREEN}[INFO]${NC} $1" +} + +log_warn() { + echo -e "${YELLOW}[WARN]${NC} $1" +} + +log_error() { + echo -e "${RED}[ERROR]${NC} $1" +} + +# Create output directory +mkdir -p "${OUTPUT_DIR}" + +# List of packages to build +PACKAGES=("legatus-qt6-sv" "legatus-qt6-ws" "legatus-qt6-aar" "legatus-qt6-ltscc" "legatus-qt6-licence") + +# Build each package +for pkg in "${PACKAGES[@]}"; do + log_info "Building package: ${pkg}_${VERSION}_amd64.deb" + + pkg_dir="${PACKAGING_DIR}/${pkg}" + + if [ ! -d "${pkg_dir}" ]; then + log_warn "Package directory not found: ${pkg_dir}" + continue + fi + + # Update version in control file + control_file="${pkg_dir}/DEBIAN/control" + if [ -f "${control_file}" ]; then + sed -i "s/^Version:.*/Version: ${VERSION}/" "${control_file}" + fi + + # Build the package + cd "${PACKAGING_DIR}" + dpkg-deb --build --root-owner-group "${pkg}" "${OUTPUT_DIR}/${pkg}_${VERSION}_amd64.deb" + + # Validate the package + log_info "Validating package..." + dpkg-deb -I "${OUTPUT_DIR}/${pkg}_${VERSION}_amd64.deb" + dpkg-deb -c "${OUTPUT_DIR}/${pkg}_${VERSION}_amd64.deb" | head -20 + + echo "" +done + +log_info "All packages built successfully!" +log_info "Output directory: ${OUTPUT_DIR}" +ls -la "${OUTPUT_DIR}" \ No newline at end of file