Skip to content
Snippets Groups Projects
Select Git revision
  • 6b3abb76381da10d2c48d3c86a9259ee58a0bc39
  • develop default protected
  • master protected
  • feature/POL1-813-error-report-sensu-check
  • 0.22
  • 0.21
  • 0.20
  • 0.19
  • 0.18
  • 0.17
  • 0.16
  • 0.15
  • 0.14
  • 0.13
  • 0.12
  • 0.11
  • 0.10
  • 0.9
  • 0.8
  • 0.7
  • 0.6
  • 0.5
  • 0.4
  • 0.3
24 results

setup.py

Blame
  • cli.py 1.46 KiB
    """
    
    script name [TODO]
    ====================
    
    .. code-block:: bash
    
        Usage: script name [OPTIONS]
    
          notes: - first call init_db(dns=mysql_dsn(params from config)) - then create
          a session (as in unit test) - ... and perform the db queries
    
        Options:
          --config FILENAME  config filename  [required]
          --fqdn TEXT        config filename  [required]
          --help             Show this message and exit.
    
    The configuration filename must be formatted according
    to this schema:
    
        .. asjson::
           resource_management.config.CONFIG_SCHEMA
    
    
    .. todo::
    
        add a console script alias and change the name (cli.py) below
    
    
    """
    import json
    
    import click
    from jsonschema.exceptions import ValidationError
    
    
    def _validate_config(_unused_ctx, _unused_param, file):
        try:
            params = json.loads(file.read())
            return params
        except (json.JSONDecodeError, ValidationError):
            raise click.BadParameter('config file is not valid json')
    
    
    @click.command()
    @click.option(
        '--config',
        required=True,
        type=click.File('r'),
        help='config filename',
        callback=_validate_config)
    @click.option(
        '--fqdn',
        required=True,
        type=click.STRING,
        help='config filename')
    def cli(config, fqdn):
        """
        notes:
        - first call init_db(dns=mysql_dsn(params from config))
        - then create a session (as in unit test)
        - ... and perform the db queries
        """
        print(config)
        print(fqdn)
    
    
    if __name__ == '__main__':
        cli()