Files
qt5-legatus-legacy/Lts/Tools/Niklas-Excon-Helper/main.py
T
2026-08-13 18:33:10 +02:00

115 lines
4.5 KiB
Python
Executable File

import argparse
import sys
import paramiko
from prompt_toolkit import prompt
import network
import settings
from initiate import initiate
import subprocess
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="Niklas Excon Helfer")
parser.add_argument('-db', '--updatedb', action='store_true', help="Datenbank updaten")
parser.add_argument('-c', '--autocheck', action='store_true',
help="Checkt alle Maschinen und Prozesse in einem Produktivsystem und lokalem System")
# parser.add_argument('-i', '--install' , action='store_true', help="Installiert die komplette Software, pogchamp")
parser.add_argument("-b", "--branch", action='store_true', help='Returns the current used branch')
parser.add_argument('-s', '--switch', action='store_true', help='Switches the branch to another')
parser.add_argument('-a', '--add', action='store_true', help='Adds a new branch on server and client')
parser.add_argument('-v', '--verbose', action='store_true', help="More print outs")
parser.add_argument('-in', '--init', action='store_true', help="Init this tool to set TDS and DBS...")
parser.add_argument('-n', '--niklas', action='store_true', help="Kleine Info")
parser.add_argument("-r", "--revisions", action='store_true', help="Show all revisions/versions installed on several machines")
verbose = False
args = parser.parse_args()
if args.niklas:
print("Hallo liebe Freunde, dieses Tool wurde mit Liebe und Herzblut von mir gebaut, ich hoffe es sind nicht zu viele Fehler drin, in Liebe Niklas <3")
sys.exit()
if args.init:
initiate()
sys.exit()
if settings.get_setting("tds") is None:
print("Die Settings wurden nicht korrekt gesetzt, bitte führe --init aus")
sys.exit()
if args.branch:
if settings.get_setting("rpm") is True:
print("Only possible in dev mode. (This machine is in production mode, --init to change)")
sys.exit()
branch = settings.get_setting("current_branch")
if branch is not None:
print(f"Current installed branch: {branch}")
sys.exit()
if args.revisions:
if settings.get_setting("rpm") is False:
print("Only possible in production mode. (This machine is in dev mode, --init to change)")
sys.exit()
if args.verbose:
verbose = True
if args.autocheck:
from autocheck import autocheck
autocheck(verbose)
sys.exit()
if args.updatedb:
from updatedb import updatedb
updatedb(verbose)
sys.exit()
if args.switch:
if settings.get_setting("rpm") is True:
print("Only possible in dev mode. (This machine is in production mode, --init to change)")
sys.exit()
from branch_helper import switch_branch
switch_branch(verbose)
sys.exit()
if args.add:
if settings.get_setting("rpm") is True:
print("Only possible in dev mode. (This machine is in production mode, --init to change)")
sys.exit()
from branch_helper import add_branch
add_branch(verbose)
sys.exit()
tds = settings.get_setting("tds")
if tds == "localhost":
sys.exit()
print("What do you want to do?")
print("[1] Open LogView")
print("[2] Open SqlBrowser")
print("[3] Open DDSView")
print("[4] Restart Server")
print("[5] Restart Tetra")
print("[6] Update Software")
option = prompt()
tds_user = settings.get_setting("tds_user")
tds_pass = settings.get_setting("tds_pass")
if option == "1":
subprocess.run(f"sshpass -p '{tds_pass}' ssh -X {tds_user}@{tds} /shd/CTC/SV/bin/LogView", shell=True)
if option == "2":
subprocess.run(f"sshpass -p '{tds_pass}' ssh -X {tds_user}@{tds} /shd/CTC/SV/bin/sqlbrowser", shell=True)
if option == "3":
subprocess.run(f"sshpass -p '{tds_pass}' ssh -X {tds_user}@{tds} /shd/CTC/SV/bin/ddsview", shell=True)
if option == "4":
subprocess.run(f"sshpass -p '!Mout11de' ssh -X root@{tds} systemctl restart lts_sv", shell=True)
if option == "5":
network.execSshCommand("ccstsw01", "root", "accessnet", "systemctl restart guez2")
if option == "6":
print("ServiceManagement will be stopped!")
network.execSshCommand(tds, "root", "!Mout11de", "systemctl stop lts_sv && zypper ref && zypper up")
network.execSshCommand(tds, "root", "!Mout11de", "systemctl start lts_sv")