added the tool that was created on 30/05/2022

work related to https://bugzilla.ipr.univ-rennes1.fr/show_bug.cgi?id=3368
This commit is contained in:
Guillaume Raffy 2023-10-06 10:58:39 +02:00
parent 0840c37eec
commit 5241bbe3f8
1 changed files with 106 additions and 0 deletions

106
create_list_for_annex.py Normal file
View File

@ -0,0 +1,106 @@
from cocluto.inventory import Inventory
from cocluto.SimpaDbUtil import SqlDatabaseReader, SqlFile
from urllib.parse import urlparse
def get_md_table_separator_line(columns_width):
sep_line = '|'
for col_width in columns_width:
sep_line += '-' * col_width
sep_line += '|'
return sep_line
def render_table_md(columns_data, labels):
assert len(labels) == len(columns_data)
num_cols = len(columns_data)
num_rows = len(columns_data[0])
cols_width = [0 for col in range(num_cols)]
for icol in range(num_cols):
cols_width[icol] = max(cols_width[icol], len(labels[icol]))
for irow in range(num_rows):
cols_width[icol] = max(cols_width[icol], len(columns_data[icol][irow]))
sep_line = get_md_table_separator_line([col_width + 2 for col_width in cols_width])
line_format = "|" + ''.join([" %%%ds |" % col_width for col_width in cols_width])
print(sep_line)
print(line_format % tuple(labels))
print(sep_line)
for irow in range(num_rows):
row = []
for icol in range(num_cols):
row.append(columns_data[icol][irow])
print(line_format % tuple(row))
print(sep_line)
def render_table_wiki(columns_data, labels):
assert len(labels) == len(columns_data)
num_cols = len(columns_data)
num_rows = len(columns_data[0])
cols_width = [0 for col in range(num_cols)]
for icol in range(num_cols):
cols_width[icol] = max(cols_width[icol], len(labels[icol]))
for irow in range(num_rows):
cols_width[icol] = max(cols_width[icol], len(columns_data[icol][irow]))
cols_width = [col_width + 1 for col_width in cols_width]
header_line_format = "^" + ''.join([" %%%ds ^" % col_width for col_width in cols_width])
line_format = "|" + ''.join([" %%%ds |" % col_width for col_width in cols_width])
print(header_line_format % tuple(labels))
for irow in range(num_rows):
row = []
for icol in range(num_cols):
row.append(columns_data[icol][irow])
print(line_format % tuple(row))
def print_machine_table(machines_fqdn):
itinv_db_url = "file:///home/graffy/work/simpaweb/itinv.git/itinv.sql"
url_parts = urlparse(itinv_db_url)
sql_source = SqlFile(url_parts.path)
sql_reader = SqlDatabaseReader(sql_source)
inventory = Inventory(sql_reader)
machines_name = []
machines_spec_id = []
machines_serial_number = []
for machine_fqdn in machines_fqdn:
machine_name = machine_fqdn.split('.')[0]
machine_spec_id = inventory.machine_name_to_machine_spec_id(machine_name)
serial_number = inventory.get_machine_serial_number(machine_name)
machines_name.append(machine_name)
machines_spec_id.append(machine_spec_id)
machines_serial_number.append(serial_number)
name_label = 'Nom'
model_label = 'Modèle'
serial_label = 'Numéro de Série'
render_table_md([machines_name, machines_spec_id, machines_serial_number], [name_label, model_label, serial_label])
render_table_wiki([machines_name, machines_spec_id, machines_serial_number], [name_label, model_label, serial_label])
if __name__ == '__main__':
machines_fqdn = [
'physix49.ipr.univ-rennes1.fr',
'physix50.ipr.univ-rennes1.fr',
'physix51.ipr.univ-rennes1.fr',
'physix52.ipr.univ-rennes1.fr',
'physix53.ipr.univ-rennes1.fr',
'physix54.ipr.univ-rennes1.fr',
'physix55.ipr.univ-rennes1.fr',
'physix56.ipr.univ-rennes1.fr',
'physix57.ipr.univ-rennes1.fr',
'physix58.ipr.univ-rennes1.fr',
'simpatix59.ipr.univ-rennes1.fr',
'physix72.ipr.univ-rennes1.fr',
'physix73.ipr.univ-rennes1.fr',
'physix74.ipr.univ-rennes1.fr',
'physix75.ipr.univ-rennes1.fr',
'physix90.ipr.univ-rennes1.fr',
'physix91.ipr.univ-rennes1.fr',
'alambix103.ipr.univ-rennes1.fr',
'alambix104.ipr.univ-rennes1.fr'
]
print_machine_table(machines_fqdn)