Skip to content
Snippets Groups Projects
Select Git revision
  • c5ba3b04c7a29e8d397d5ee056274a22394abb7f
  • develop default
  • master protected
  • inventoryProvider-functional
  • inventoryProvider-morework2
  • circuit-service-details-fix
  • lookup-SPECTRUM-SCHF-ports
  • inventoryProvider-1267-cleanup
  • inventoryProvider-moreWork
  • feature/DBOARD3-958
  • release/0.110
  • fix-uuid-validation-error
  • docker-poc
  • 0.160
  • 0.159
  • 0.158
  • 0.157
  • 0.156
  • 0.155
  • 0.154
  • 0.153
  • 0.152
  • 0.151
  • 0.150
  • 0.149
  • 0.148
  • 0.147
  • 0.146
  • 0.145
  • 0.144
  • 0.143
  • 0.142
  • 0.141
33 results

app.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()