Verbindungsaufbau nur wenn nötig
This commit is contained in:
@ -7,10 +7,26 @@
|
||||
# https://opensource.org/licenses/MIT.
|
||||
|
||||
import pathlib
|
||||
from PyAPplus64.applus import APplusServerConfigDescription
|
||||
|
||||
basedir = pathlib.Path(__file__)
|
||||
basedir = basedir = pathlib.Path(__file__) # Adapt to your needs
|
||||
configdir = basedir.joinpath("config")
|
||||
|
||||
serverConfYamlDeploy = configdir.joinpath("applus-server-deploy.yaml")
|
||||
serverConfYamlTest = configdir.joinpath("applus-server-test.yaml")
|
||||
serverConfYamlProd = configdir.joinpath("applus-server-prod.yaml")
|
||||
|
||||
|
||||
serverConfDescProdEnv1 = APplusServerConfigDescription("Prod/Env1", serverConfYamlProd, env="Env1")
|
||||
serverConfDescProdEnv2 = APplusServerConfigDescription("Prod/Env2", serverConfYamlProd, env="Env2")
|
||||
serverConfDescTestEnv1 = APplusServerConfigDescription("Test/Env1", serverConfYamlTest, env="Env1")
|
||||
serverConfDescTestEnv2 = APplusServerConfigDescription("Test/Env2", serverConfYamlTest, env="Env2")
|
||||
serverConfDescDeploy = APplusServerConfigDescription("Deploy", serverConfYamlDeploy)
|
||||
|
||||
serverConfDescs = [
|
||||
serverConfDescProdEnv1,
|
||||
serverConfDescProdEnv2,
|
||||
serverConfDescTestEnv1,
|
||||
serverConfDescTestEnv2,
|
||||
serverConfDescDeploy
|
||||
]
|
105
examples/complete_sql.pyw
Normal file
105
examples/complete_sql.pyw
Normal file
@ -0,0 +1,105 @@
|
||||
# Copyright (c) 2023 Thomas Tuerk (kontakt@thomas-tuerk.de)
|
||||
#
|
||||
# This file is part of PyAPplus64 (see https://www.thomas-tuerk.de/de/pyapplus64).
|
||||
#
|
||||
# Use of this source code is governed by an MIT-style
|
||||
# license that can be found in the LICENSE file or at
|
||||
# https://opensource.org/licenses/MIT.
|
||||
|
||||
import PySimpleGUI as sg # type: ignore
|
||||
import PyAPplus64
|
||||
import applus_configs
|
||||
import pathlib
|
||||
from typing import Tuple, Optional, Union
|
||||
|
||||
try:
|
||||
import sqlparse
|
||||
except:
|
||||
pass
|
||||
|
||||
try:
|
||||
import sqlfmt.api
|
||||
except:
|
||||
pass
|
||||
|
||||
def prettyPrintSQL(format, sql):
|
||||
try:
|
||||
if format == "sqlfmt":
|
||||
mode = sqlfmt.api.Mode(dialect_name="ClickHouse")
|
||||
sqlPretty = sqlfmt.api.format_string(sql, mode)
|
||||
return sqlPretty.replace("N '", "N'") # fix String Constants
|
||||
elif format == "sqlparse-2":
|
||||
return sqlparse.format(sql, reindent=True, keyword_case='upper')
|
||||
elif format == "sqlparse":
|
||||
return sqlparse.format(sql, reindent_aligned=True, keyword_case='upper')
|
||||
else:
|
||||
return sql
|
||||
except e:
|
||||
print (str(e))
|
||||
return sql
|
||||
|
||||
def main() -> None:
|
||||
monospaceFont = ("Courier New", 12)
|
||||
sysenvs = applus_configs.serverConfDescs[:];
|
||||
sysenvs.append("-");
|
||||
layout = [
|
||||
[sg.Button("Vervollständigen"), sg.Button("aus Clipboard", key="import"), sg.Button("nach Clipboard", key="export"), sg.Button("zurücksetzen", key="clear"), sg.Button("Beenden"),
|
||||
sg.Text('System/Umgebung:'), sg.Combo(sysenvs, default_value="-", key="sysenv", readonly=True), sg.Text('Formatierung:'), sg.Combo(["-", "sqlfmt", "sqlparse", "sqlparse-2"], default_value="sqlparse", key="formatieren", readonly=True)
|
||||
],
|
||||
[sg.Text('Eingabe-SQL')],
|
||||
[sg.Multiline(key='input', size=(150, 20), font=monospaceFont)],
|
||||
[sg.Text('Ausgabe-SQL')],
|
||||
[sg.Multiline(key='output', size=(150, 20), font=monospaceFont, horizontal_scroll=True)]
|
||||
]
|
||||
|
||||
# server = PyAPplus64.applusFromConfigFile(confFile, user=user, env=env)
|
||||
# systemName = server.scripttool.getSystemName() + "/" + server.scripttool.getMandant()
|
||||
window = sg.Window("Complete SQL", layout)
|
||||
oldSys = None
|
||||
while True:
|
||||
event, values = window.read()
|
||||
if event == sg.WIN_CLOSED or event == 'Beenden':
|
||||
break
|
||||
elif event == 'clear':
|
||||
window['input'].update("")
|
||||
window['output'].update("")
|
||||
elif event == 'import':
|
||||
try:
|
||||
window['input'].update(window.TKroot.clipboard_get())
|
||||
except:
|
||||
window['input'].update("")
|
||||
window['output'].update("")
|
||||
elif event == 'export':
|
||||
try:
|
||||
window.TKroot.clipboard_clear()
|
||||
window.TKroot.clipboard_append(window['output'].get())
|
||||
except:
|
||||
pass
|
||||
elif event == 'Vervollständigen':
|
||||
sqlIn = window['input'].get()
|
||||
try:
|
||||
if sqlIn:
|
||||
sys = window['sysenv'].get()
|
||||
if sys != oldSys:
|
||||
oldSys = sys
|
||||
if sys and sys != "-":
|
||||
server = sys.connect()
|
||||
else:
|
||||
server = None
|
||||
if server:
|
||||
sqlOut = server.completeSQL(sqlIn)
|
||||
else:
|
||||
sqlOut = sqlIn
|
||||
sqlOut = prettyPrintSQL(window['formatieren'].get(), sqlOut)
|
||||
else:
|
||||
sqlOut = ""
|
||||
except Exception as e:
|
||||
sqlOut = "ERROR: " + str(e)
|
||||
sg.popup_error_with_traceback("Fehler bei Vervollständigung", e)
|
||||
window['output'].update(value=sqlOut)
|
||||
|
||||
window.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
75
examples/importViewUDF.py
Normal file
75
examples/importViewUDF.py
Normal file
@ -0,0 +1,75 @@
|
||||
# Copyright (c) 2023 Thomas Tuerk (kontakt@thomas-tuerk.de)
|
||||
#
|
||||
# This file is part of PyAPplus64 (see https://www.thomas-tuerk.de/de/pyapplus64).
|
||||
#
|
||||
# Use of this source code is governed by an MIT-style
|
||||
# license that can be found in the LICENSE file or at
|
||||
# https://opensource.org/licenses/MIT.
|
||||
|
||||
import PySimpleGUI as sg # type: ignore
|
||||
import pathlib
|
||||
import PyAPplus64
|
||||
from PyAPplus64 import applus
|
||||
from PyAPplus64 import sql_utils
|
||||
import applus_configs
|
||||
import traceback
|
||||
import pathlib
|
||||
import sys
|
||||
|
||||
def importViewsUDFs(server, views, udfs, dbanpass):
|
||||
res = ""
|
||||
try:
|
||||
if views or udfs:
|
||||
for env in server.scripttool.getAllEnvironments():
|
||||
res = res + server.importUdfsAndViews(env, views, udfs);
|
||||
res = res + "\n\n";
|
||||
|
||||
for xml in dbanpass:
|
||||
res = res + "Verarbeite " + xml + "\n"
|
||||
xmlRes = server.updateDatabase(xml);
|
||||
if (xmlRes == ""): xmlRes = "OK";
|
||||
res = res + xmlRes
|
||||
res = res + "\n\n"
|
||||
|
||||
sg.popup_scrolled("Importiere", res)
|
||||
except:
|
||||
sg.popup_error("Fehler", traceback.format_exc())
|
||||
|
||||
def importIntoSystem(server, system):
|
||||
try:
|
||||
if (len(sys.argv) < 2):
|
||||
sg.popup_error("Keine Datei zum Import übergeben")
|
||||
return
|
||||
|
||||
views = []
|
||||
udfs = []
|
||||
dbanpass = []
|
||||
errors = ""
|
||||
|
||||
|
||||
for i in range (1, len(sys.argv)):
|
||||
arg = pathlib.Path(sys.argv[i])
|
||||
if arg == server.scripttool.getInstallPathAppServer().joinpath("Database", "View", arg.stem + ".sql"):
|
||||
views.append(arg.stem)
|
||||
elif arg == server.scripttool.getInstallPathAppServer().joinpath("Database", "UDF", arg.stem + ".sql"):
|
||||
udfs.append(arg.stem)
|
||||
elif arg == server.scripttool.getInstallPathAppServer().joinpath("DBChange", arg.stem + ".xml"):
|
||||
dbanpass.append(arg.stem + ".xml")
|
||||
else:
|
||||
errors = errors + " - " + str(arg) + "\n";
|
||||
|
||||
if len(errors) > 0:
|
||||
msg = "Folgende Dateien sind keine View, UDF oder DB-Anpass-Dateien des "+system+"-Systems:\n" + errors;
|
||||
sg.popup_error("Fehler", msg);
|
||||
if views or udfs or dbanpass:
|
||||
importViewsUDFs(server, views, udfs, dbanpass)
|
||||
|
||||
except:
|
||||
sg.popup_error("Fehler", traceback.format_exc())
|
||||
|
||||
if __name__ == "__main__":
|
||||
server = PyAPplus64.applusFromConfigFile(applus_configs.serverConfYamlDeploy)
|
||||
importIntoSystem(server, "Deploy");
|
||||
|
||||
|
||||
|
15
examples/importViewUDFDeploy.pyw
Normal file
15
examples/importViewUDFDeploy.pyw
Normal file
@ -0,0 +1,15 @@
|
||||
# Copyright (c) 2023 Thomas Tuerk (kontakt@thomas-tuerk.de)
|
||||
#
|
||||
# This file is part of PyAPplus64 (see https://www.thomas-tuerk.de/de/pyapplus64).
|
||||
#
|
||||
# Use of this source code is governed by an MIT-style
|
||||
# license that can be found in the LICENSE file or at
|
||||
# https://opensource.org/licenses/MIT.
|
||||
|
||||
import importViewUDF
|
||||
import applus_configs
|
||||
import PyAPplus64
|
||||
|
||||
if __name__ == "__main__":
|
||||
server = PyAPplus64.applusFromConfigFile(applus_configs.serverConfYamlDeploy)
|
||||
importViewUDF.importIntoSystem(server, "Deploy")
|
15
examples/importViewUDFTest.pyw
Normal file
15
examples/importViewUDFTest.pyw
Normal file
@ -0,0 +1,15 @@
|
||||
# Copyright (c) 2023 Thomas Tuerk (kontakt@thomas-tuerk.de)
|
||||
#
|
||||
# This file is part of PyAPplus64 (see https://www.thomas-tuerk.de/de/pyapplus64).
|
||||
#
|
||||
# Use of this source code is governed by an MIT-style
|
||||
# license that can be found in the LICENSE file or at
|
||||
# https://opensource.org/licenses/MIT.
|
||||
|
||||
import importViewUDF
|
||||
import applus_configs
|
||||
import PyAPplus64
|
||||
|
||||
if __name__ == "__main__":
|
||||
server = PyAPplus64.applusFromConfigFile(applus_configs.serverConfYamlTest)
|
||||
importViewUDF.importIntoSystem(server, "Test")
|
@ -48,8 +48,8 @@ def main(confFile: Union[str, pathlib.Path], user: Optional[str] = None, env: Op
|
||||
print(" InstallPathWebServer:", server.scripttool.getInstallPathWebServer())
|
||||
print(" ServerInfo - Version:", server.scripttool.getServerInfo().find("version").text)
|
||||
|
||||
client = server.getWebClient("masterdata/artikel.asmx")
|
||||
print("ARTIKEL-ASMX Date:", client.service.getServerDate())
|
||||
client = server.getWebClient("dbenv/dbenv.asmx")
|
||||
print("WEB Environment:", client.service.getEnvironment())
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(applus_configs.serverConfYamlTest)
|
||||
|
Reference in New Issue
Block a user