Esempio n. 1
0
"""Manage database fixtures."""
import click

from encapsia_cli import lib

main = lib.make_main(__doc__)


@main.command("list")
@click.pass_obj
def list_fixtures(obj):
    """List available fixtures."""
    api = lib.get_api(**obj)
    lib.log_output(
        lib.dbctl_action(api, "list_fixtures", dict(), f"Fetching list of fixtures")
    )


@main.command("create")
@click.argument("name")
@click.pass_obj
def create_fixture(obj, name):
    """Create new fixture with given name."""
    api = lib.get_api(**obj)
    lib.log_output(
        lib.dbctl_action(
            api, "create_fixture", dict(name=name), f"Creating fixture {name}"
        )
    )

Esempio n. 2
0
import datetime
import re
import shutil
import sys
import tempfile
import urllib.request
from contextlib import contextmanager
from pathlib import Path

import click
import toml
from tabulate import tabulate

from encapsia_cli import lib

main = lib.make_main(__doc__, for_plugins=True)


def _fetch_plugin_and_store_in_cache(url, plugins_cache_dir, force=False):
    full_name = url.rsplit("/", 1)[-1]
    m = re.match(r"plugin-([^-]*)-([^-]*).tar.gz", full_name)
    if m:
        output_filename = plugins_cache_dir / full_name
        if not force and output_filename.exists():
            lib.log(f"Found: {output_filename} (Skipping)")
        else:
            filename, headers = urllib.request.urlretrieve(
                url,
                tempfile.mkstemp()[1])
            shutil.move(filename, output_filename)
            lib.log(f"Created: {output_filename}")