# import os import click from sdi_checker.libs.audits import Audits from sdi_checker.app_cli import display_audits # from sdi_checker.app_cli import helpers # from sdi_checker.app_cli import display @click.command(name='edit') @click.argument('id', nargs=1) @click.option('--url', '-u', default=None, type=str, help='URL of audit') @click.option('--name', '-n', default=None, type=str, help='name of audit') @click.option('--type', '-t', 'mode', type=click.Choice(['wms', 'wfs', 'csw'], case_sensitive=False), default='wms', show_default=True, show_choices=True, help="audit type (wms, WFS or csw)") @click.option('--description', '-r', default='', type=str, help='description of audit') @click.option('--file', '-f', default='', type=str, help='audits JSON file to add audit') @click.option('--check-layers', '-c', 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), show_default=True, show_choices=True, help="if a file path is specified, log output to this file, not stdout") @click.option('--log-display', '-ld', type=click.Choice(['', 'true', 'on', 'false', 'off', '1', '0'], case_sensitive=False), default='', help="display log on stdout") @click.option('--timeout', '-to', default=30, type=int, help="specify a timeout for request to external audit.") @click.option('--report-format', '-rf', type=click.Choice(['json', 'txt', 'csv', 'db'], case_sensitive=False), default='json', show_default=True, show_choices=True, 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, id, url, name, mode, description, file, check_layers, ssl_verification, only_err, xunit, xunit_output, log_file, log_level, log_display, timeout, report_format, report_file, report_name): """ > master edit [TEXT] [--template TPL] [--file FILE] [--edit] [--repository REPOSITORY] [--login LOGIN] [--password PASSWORD] """ on_edit(app, id, url, name, mode, description, file, check_layers, ssl_verification, only_err, xunit, xunit_output, log_file, log_level, log_display, timeout, report_format, report_file, report_name) def on_edit(app, id, url, name, mode, description='', file=None, check_layers=False, ssl_verification=True, only_err=False, xunit=False, xunit_output=None, log_file='', log_level='INFO', log_display=False, timeout=None, report_format=None, report_file=None, report_name=None): id = [str(i.strip()) for i in ','.join(id).split(',')] audits_file = file or app.audits_file if len(id) == 0 or id[0] is None: app.echo('ERROR: ID parameter is mandatory') exit() else: id = int(id[0]) audits = Audits(file=audits_file) audit_edit = audits.get(id=id).result if len(audit_edit) == 0: app.echo('ID not exists. Audit(s) can\'t be removed.') exit() audit = { 'url': url, 'name': name, 'type': mode, 'description': description, 'params': { 'check_layers': check_layers, 'ssl_verify': ssl_verification, 'only_err': only_err, 'xunit': xunit, 'xunit_output': xunit_output, 'log_file': log_file or app.logs_file, 'log_level': log_level, 'log_display': log_display, 'report_format': report_format, 'report_file': report_file, 'report_name': report_name } } audits = Audits(file=audits_file) audits.edit(id=id, audit=audit) audits_list = audits.get().result result = display_audits.print_audits_list(app, audits_list, title="Liste des audits") result_text = '\n'.join(result) app.echo(result_text)