mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-05-03 08:55:15 +00:00
[AB-xxx] restructuring installer module to be outside of maven
split liquibase and template deployment adding various features to the deployment images
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import glob
|
||||
import os
|
||||
import sqlalchemy as db
|
||||
from sqlalchemy.sql import text
|
||||
|
||||
|
||||
def deploy_template_folder(db_config, folder):
|
||||
engine = db.create_engine('postgresql://%s:%s@%s:%s/%s' % (db_config.user, db_config.password, db_config.host, db_config.port, db_config.database))
|
||||
|
||||
if not os.path.isdir(folder):
|
||||
print(f'Given path {folder} was not a folder. Exiting.')
|
||||
exit(1)
|
||||
|
||||
files = glob.glob(folder + '/**/*.ftl', recursive=True)
|
||||
templates = []
|
||||
for file in files:
|
||||
with open(file) as template_file:
|
||||
file_content = template_file.read()
|
||||
template_key = os.path.splitext(os.path.basename(file))[0]
|
||||
template = {'key': template_key, 'content': file_content}
|
||||
print(f'Deployment template {template}')
|
||||
templates.append(template)
|
||||
|
||||
print(f'Deploying {len(templates)} templates from folder {folder}')
|
||||
|
||||
with engine.connect() as con:
|
||||
with con.begin():
|
||||
statement = text(f"""INSERT INTO {db_config.scheme}template(key, content, last_modified) VALUES(:key, :content, NOW()) ON CONFLICT (key) DO UPDATE SET content = :content""")
|
||||
|
||||
for line in templates:
|
||||
con.execute(statement, **line)
|
||||
Reference in New Issue
Block a user