Guillaume RYCKELYNCK c6c2ee9c04 first commit
2024-06-22 22:00:42 +02:00

70 lines
4.1 KiB
Python

import os
import time
import click
from sdi_checker.app_cli import display_check
from sdi_checker.libs.sdi_consistence_check.check import Check
@click.command(name='wms')
@click.argument('url', nargs=1) # help = the server to target (full URL, e.g. https://sdi.georchestra.org/geoserver/wms)
@click.option('--check-layers', '-l', is_flag=True, type=bool, help="check WMS/WFS layer validity")
@click.option('--ssl-verification', '-ssl', type=click.Choice(['', 'true', 'on', 'false', 'off', '1', '0'], case_sensitive=False), default='', help="enable/disable certificate verification")
@click.option('--only-err', '-e', is_flag=True, type=bool, help="only display errors, no summary informations will be displayed")
@click.option('--xunit', '-x', is_flag=True, type=bool, help="generate a XML xunit result report")
@click.option('--xunit-output', '-xo', default="xunit.xml", show_default=True, type=str, help="name of the xunit report file, defaults to ./xunit.xml")
@click.option('--log-file', '-lf', default='', type=str, help="if a file path is specified, log output to this file, not stdout")
@click.option('--log-level', '-ll', default='INFO', type=click.Choice(['INFO', 'DEBUG', 'WARNING', 'CRITICAL', 'ERROR'], case_sensitive=False), help="if a file path is specified, log output to this file, not stdout")
@click.option('--log-display', '-ld', default=None, type=str, help="if a file path is specified, log output to this file, not stdout")
@click.option('--log-clear', '-lc', default=None, type=str, help="if a file path is specified, log output to this file, not stdout")
@click.option('--timeout', '-t', default=30, type=int, help="specify a timeout for request to external service.")
@click.option('--report-format', '-rf', type=click.Choice(['', 'json', 'txt', 'csv', 'db'], case_sensitive=False), default='', help="report output format")
@click.option('--report-file', '-ro', type=str, default='', help="report output file")
@click.option('--report-name', '-rn', type=str, default='', help="report name")
@click.pass_obj
def run(app, url, check_layers, ssl_verification, only_err, xunit, xunit_output, log_file, log_level, log_display, log_clear, timeout, report_format, report_file, report_name):
"""
> sdi-checker check [URL] [--option OPT]
"""
# Utiliser fonction commune à WFS et WMS
on_wms(app, url, check_layers, ssl_verification, only_err, xunit, xunit_output, log_file, log_level, log_display, log_clear, timeout, report_format, report_file, report_name)
def on_wms(app, url, check_layers, ssl_verification, only_err, xunit, xunit_output, log_file, log_level, log_display, log_clear, timeout, report_format, report_file, report_name):
"""
> sdi-checker check [URL] [--option OPT]
"""
logs_config = app.set_logs_config(level=log_level, file=log_file, clear=log_clear, display=log_display)
report_output_file, report_output_format = app.get_report_output_file(name=report_name, file=report_file, extension=report_format)
# if log_level:
# app.logs.set_level(level=log_level)
# if log_file:
# app.logs.set_file(file=log_file)
# if log_clear:
# log_clear = False if log_clear.lower() in ['false', 'off', '0', ''] else True
# app.logs.set_clear(clear=log_clear)
# if log_display is not None:
# log_display = False if log_display.lower() in ['false', 'off', '0', ''] else True
# app.logs.set_display(display=log_display)
ssl_verify = app.get_on_off_value(value=ssl_verification, default=app.ssl_verify)
# ssl_verify = app.ssl_verify
# if not ssl_verification == '':
# ssl_verify = False if ssl_verification.lower() in ['false', 'off', '0', ''] else True
check = Check()
check.wms(server=url, ssl_verification=ssl_verify, check_layers=check_layers, only_err=only_err, xunit=xunit, xunit_output=xunit_output, timeout=timeout, logs=app.logs, report=app.report)
# print(app.report.errors)
report = app.report.get_report(format=report_output_format)
if report_output_file:
with open(report_output_file, 'w') as file:
file.write(report)
else:
print(report)