Пример #1
0
def list(ctx):
    """List all nFlex modules."""
    try:
        modules = ctx.nflex.list()
        print_modules(modules)

    except requests.exceptions.RequestException as e:
        raise click.ClickException("Failed to fetch nFlex modules: %s" %
                                   prep_err_msg(e))
Пример #2
0
def upload(ctx, zip, sync, language, event_source, description, name):
    """Upload a new module to nFlex."""
    try:
        module = ctx.nflex.upload(name, description, event_source, language,
                                  sync, zip)
        click.echo("Module created with ID %s" % module['id'], err=True)

    except requests.exceptions.RequestException as e:
        raise click.ClickException("Failed to upload nFlex module: %s" %
                                   prep_err_msg(e))
Пример #3
0
def update(ctx, module_id, zip, language, description):
    """Update an existing module.

    Update the "source_code" or the "description" of an nFlex module.
    """
    try:
        ctx.nflex.update(module_id, zip, language, description=description)
        click.echo("Module %s successfully updated" % module_id, err=True)

    except requests.exceptions.RequestException as e:
        raise click.ClickException("Failed to update nFlex module: %s" %
                                   prep_err_msg(e))
Пример #4
0
def download(ctx, module_id):
    """Download an nFlex module.

    If the module type is inline, the source_code will be saved as "main.py"
    in the current working directory, otherwise the contents of the zip file
    will be extracted there.
    """
    try:
        ctx.nflex.download(module_id)
        click.echo('Module %s downloaded in the current directory' % module_id,
                   err=True)

    except requests.exceptions.RequestException as e:
        raise click.ClickException("Failed to download nFlex module: %s" %
                                   prep_err_msg(e))
Пример #5
0
def get(ctx, module_id):
    """Get an nFlex module.

    If the module type is inline and the source_code is more than 50
    characters long, the source_code field won't be displayed.
    """
    try:
        result = ctx.nflex.get(module_id)
        if len(result["source_code"]) > 50:
            result["source_code"] = "*** REDACTED ***"

        print_module(result)

    except requests.exceptions.RequestException as e:
        raise click.ClickException("Failed to delete nFlex module: %s" %
                                   prep_err_msg(e))