mtes-scripts/scripts/zephir/groups.py
2021-07-16 15:05:43 +02:00

59 lines
2.0 KiB
Python

#!/usr/bin/python
from zephir.backend.lib_backend import CxPool
def make_group():
cx_pool = CxPool()
cu = cx_pool.create()
cu.execute("""select libelle,id from modules""")
infos = {}
variante_infos = {}
filename = 'exportation'
server_infos = []
for module_name in cu.fetchall():
module, version = module_name[0].rsplit('-', 1)
infos.setdefault(version, {})[module] = module_name[1]
versions = infos.keys()
versions.sort()
print('Choix de la version :')
for idx, version in enumerate(versions):
print('{}: {}'.format(idx, version))
idx = input('> ')
version = versions[int(idx)]
filename += '-' + version
print
print('Choix du module :')
modules = infos[version].keys()
modules.sort()
for idx, module in enumerate(modules):
print('{}: {}'.format(idx, module))
idx = input('> ')
module = modules[int(idx)]
filename += '-' + module
print
cu.execute("select libelle,id from variantes where module = " + str(infos[version][module]))
for variante_obj in cu.fetchall():
variante_infos[variante_obj[0]] = variante_obj[1]
print('Choix de la variante :')
variantes = variante_infos.keys()
variantes.sort()
for idx, variante in enumerate(variantes):
print('{}: {}'.format(idx, variante))
idx_all = idx + 1
print('{}: toutes les variantes'.format(idx_all))
idx = input('> ')
if idx == idx_all:
variantes = variante_infos.values()
else:
filename += '-' + variantes[idx]
variantes = [variante_infos[variantes[idx]]]
print
for variante in variantes:
cu.execute('select id,ip_publique,rne,libelle from serveurs where variante=' + str(variante))
print("Liste des serveurs : ")
for server in cu.fetchall():
print('{} - {} - {} - {}'.format(server[0], server[1], server[2], server[3]))
server_infos.append((server[0], server[1], server[2], server[3]))
return server_infos