availcheck.cli

  1# -*- coding: utf-8 -*-
  2# Copyright (C) 2024 TU Dresden
  3# ralf.klammer@tu-dresden.de
  4
  5import click
  6import logging
  7
  8from json import dumps
  9
 10from .checker import (
 11    CheckerOneStop4All,
 12    CheckerEduTrain,
 13    CheckerSupportApps,
 14    CheckerKnowledgeHub,
 15    CheckerWebApps,
 16)
 17from .util import cli_startup
 18
 19log = logging.getLogger(__name__)
 20
 21
 22@click.group()
 23@click.option("--debug/--no-debug", "-d", is_flag=True, default=False)
 24@click.pass_context
 25def main(ctx, debug):
 26    cli_startup(log_level=debug and logging.DEBUG or logging.INFO)
 27    ctx.ensure_object(dict)
 28    ctx.obj["DEBUG"] = debug
 29
 30
 31@main.command()
 32@click.pass_context
 33@click.option("--path", default="/tmp", help="Path to save the results.")
 34def save_all(ctx, path, **kw):
 35
 36    results = {
 37        "OneStop4All - Prod": CheckerOneStop4All(instance="prod").save_checks(
 38            path
 39        ),
 40        "OneStop4All - Test": CheckerOneStop4All(instance="test").save_checks(
 41            path
 42        ),
 43        "EduTrain - Prod": CheckerEduTrain(instance="prod").save_checks(path),
 44        "EduTrain - Test": CheckerEduTrain(instance="test").save_checks(path),
 45        "JupyterHub - Prod": CheckerSupportApps(instance="prod").save_checks(
 46            path
 47        ),
 48    }
 49
 50    filename = f"{path.rstrip('/')}/collection.json"
 51    with open(filename, "w") as f:
 52        f.write(dumps(results))
 53
 54
 55@main.command()
 56@click.pass_context
 57def onestop4all(ctx, **kw):
 58
 59    CheckerOneStop4All(instance="prod").run_checks()
 60
 61    CheckerOneStop4All(instance="test").run_checks()
 62
 63
 64@main.command()
 65@click.pass_context
 66def develop(ctx, **kw):
 67
 68    CheckerOneStop4All(instance="prod").involvement()
 69
 70
 71@main.command()
 72@click.pass_context
 73def edutrain(ctx, **kw):
 74
 75    CheckerEduTrain(instance="prod").run_checks()
 76
 77    CheckerEduTrain(instance="test").run_checks()
 78
 79
 80@main.command()
 81@click.pass_context
 82def supportapps(ctx, **kw):
 83
 84    CheckerSupportApps(instance="prod").run_checks()
 85
 86
 87@main.command()
 88@click.pass_context
 89def knowledgehub(ctx, **kw):
 90
 91    CheckerKnowledgeHub(instance="prod").run_checks()
 92
 93    CheckerKnowledgeHub(instance="test").run_checks()
 94
 95
 96@main.command()
 97@click.pass_context
 98def webapps(ctx, **kw):
 99
100    CheckerWebApps(instance="prod").run_checks()
101
102
103if __name__ == "__main__":
104    main(obj={})
log = <Logger availcheck.cli (WARNING)>