86 lines
3.2 KiB
Python
Executable file
86 lines
3.2 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
|
|
from asyncio import run
|
|
from os import listdir, link, makedirs
|
|
from os.path import isdir, join
|
|
from shutil import rmtree
|
|
from copy import copy
|
|
|
|
from risotto.utils import CONFIGS, RISOTTO_CONFIG, SERVERS
|
|
from risotto.image import load
|
|
from risotto.machine import templates
|
|
|
|
|
|
INSTALL_DIR = RISOTTO_CONFIG['directories']['dest']
|
|
CONFIG_DEST_DIR = 'configurations'
|
|
CONFIG_DIFF_DIR = 'diff'
|
|
CONFIG_ORI_DIR = 'ori'
|
|
SRV_DEST_DIR = 'srv'
|
|
|
|
|
|
def tiramisu_display_name(kls,
|
|
dyn_name: 'Base'=None,
|
|
suffix: str=None,
|
|
) -> str:
|
|
# FIXME
|
|
if dyn_name is not None:
|
|
name = kls.impl_getpath() + str(suffix)
|
|
else:
|
|
name = kls.impl_getpath()
|
|
return name
|
|
|
|
|
|
async def main():
|
|
if isdir(INSTALL_DIR):
|
|
rmtree(INSTALL_DIR)
|
|
makedirs(INSTALL_DIR)
|
|
module_infos = await load(display_name=tiramisu_display_name, clean_directories=True, copy_manual_dir=True)
|
|
for server_name in SERVERS:
|
|
module_name = CONFIGS[server_name]['module_name']
|
|
add_srv = CONFIGS[server_name]['add_srv']
|
|
cfg = CONFIGS[server_name]['templates_informations']
|
|
cfg['tmp_dir'] = 'tmp'
|
|
cfg['destinations_dir'] = join(INSTALL_DIR, module_name, CONFIG_DEST_DIR, server_name)
|
|
if isdir('tmp'):
|
|
rmtree('tmp')
|
|
makedirs(cfg['tmp_dir'])
|
|
makedirs(cfg['destinations_dir'])
|
|
if add_srv:
|
|
srv = join(INSTALL_DIR, SRV_DEST_DIR, server_name)
|
|
else:
|
|
srv = None
|
|
await templates(server_name, **CONFIGS[server_name], srv=srv)
|
|
for server_name in SERVERS:
|
|
config = CONFIGS[server_name]['config']
|
|
await config.property.read_write()
|
|
try:
|
|
# pass
|
|
await config.option('general.hide_secret').value.set(True)
|
|
except AttributeError:
|
|
# if rougail.general.hide_secret not exists
|
|
pass
|
|
await config.property.read_only()
|
|
for server_name in SERVERS:
|
|
config = CONFIGS[server_name]['config']
|
|
await config.value.dict()
|
|
for server_name in SERVERS:
|
|
module_name = CONFIGS[server_name]['module_name']
|
|
destinations_dir = join(INSTALL_DIR, module_name, CONFIG_DIFF_DIR, server_name)
|
|
makedirs(destinations_dir)
|
|
CONFIGS[server_name]['templates_informations']['destinations_dir'] = destinations_dir
|
|
await templates(server_name, **CONFIGS[server_name])
|
|
for module_name, cfg in module_infos.items():
|
|
with open(join(INSTALL_DIR, module_name, 'install_machines'), 'w') as fh:
|
|
for idx, server_name in enumerate(cfg['infos'].servers):
|
|
if not idx:
|
|
destinations_dir = join(INSTALL_DIR, module_name, CONFIG_ORI_DIR)
|
|
makedirs(destinations_dir)
|
|
CONFIGS[server_name]['templates_informations']['destinations_dir'] = destinations_dir
|
|
await templates(server_name,
|
|
**CONFIGS[server_name],
|
|
just_copy=True,
|
|
)
|
|
fh.write(f'./install_machine {module_name} {server_name}\n')
|
|
|
|
|
|
run(main())
|