コード例 #1
0
ファイル: cli.py プロジェクト: nonnib/drift-config
def register(deployable_name, tier):
    """Add or update the registration of a deployable plugin.\n
    DEPLOYABLE_NAME is the name of the plugin to register. Specify 'all' to register all plugins."""
    tiers = tier  # The 'tier' option is a list, so find a better name for it.
    with TSLocal() as ts:
        deployable_names = ts.get_table('deployable-names')
        deployables = ts.get_table('deployables')

        for d in _enumerate_plugins('drift.plugin', 'provision'):
            dist = d['dist']
            if deployable_name == dist.key or deployable_name == 'all':
                summary = d['meta'].get('Summary',
                                        "(No description available)")
                row = {
                    'deployable_name': dist.key,
                    'display_name': summary.strip()
                }
                deployable_names.update(row)
                click.secho("{} added/updated.".format(dist.key))
                for tier_entry in ts.get_table('tiers').find():
                    if tier_entry['tier_name'] in tiers or 'all' in tiers:
                        row = {
                            'tier_name': tier_entry['tier_name'],
                            'deployable_name': dist.key,
                            'is_active': True,
                            'tags': d['tags'],
                        }
                        # By default, live tiers use version affinity
                        if tier_entry['is_live']:
                            row['version'] = str(dist.parsed_version)
                        deployables.update(row)
                        click.secho("Adding registration:\n" +
                                    json.dumps(row, indent=4))

        _epilogue(ts)
コード例 #2
0
ファイル: cli.py プロジェクト: nonnib/drift-config
def add(organization_name, short_name, display_name, edit):
    """Add a new organization.\n
    ORGANIZATION_NAME is a 2-20 character long string containing only lower case letters and digits.\n
    SHORT_NAME is a 2-20 character long string containing only lower case letters and digits."""
    with TSLocal() as ts:
        organizations = ts.get_table('organizations')
        entry = {
            'organization_name': organization_name,
            'short_name': short_name,
        }
        if display_name:
            entry['display_name'] = display_name

        if edit:
            edit = click.edit(json.dumps(entry, indent=4), editor='nano')
            if edit:
                entry = json.loads(edit)
        if organizations.find(entry):
            click.secho("Organization {} already exists!".format(
                entry['organization_name']),
                        fg='red',
                        bold=True)
            sys.exit(1)
        organizations.add(entry)

        _epilogue(ts)
コード例 #3
0
ファイル: cli.py プロジェクト: nonnib/drift-config
def edit(tier_name):
    """Edit a tier."""
    with TSLocal() as ts:
        tiers = ts.get_table('tiers')
        entry = tiers.get({'tier_name': tier_name})
        if not entry:
            click.secho("tier {} not found!".format(tier_name))
            sys.exit(1)

        edit = click.edit(json.dumps(entry, indent=4), editor='nano')
        if edit:
            entry = json.loads(edit)
            tiers.update(entry)
コード例 #4
0
ファイル: cli.py プロジェクト: nonnib/drift-config
def edit(product_name):
    """Edit a product."""
    with TSLocal() as ts:
        products = ts.get_table('products')
        entry = products.get({'product_name': product_name})
        if not entry:
            click.secho("product {} not found!".format(product_name))
            sys.exit(1)

        edit = click.edit(json.dumps(entry, indent=4), editor='nano')
        if edit:
            entry = json.loads(edit)
            products.update(entry)
コード例 #5
0
ファイル: cli.py プロジェクト: nonnib/drift-config
def edit(organization_name):
    """Edit a organization."""
    with TSLocal() as ts:
        organizations = ts.get_table('organizations')
        entry = organizations.get({'organization_name': organization_name})
        if not entry:
            click.secho("organization {} not found!".format(organization_name))
            sys.exit(1)

        edit = click.edit(json.dumps(entry, indent=4), editor='nano')
        if edit:
            entry = json.loads(edit)
            organizations.update(entry)
コード例 #6
0
ファイル: cli.py プロジェクト: nonnib/drift-config
def add(product_name, edit):
    """Add a new product.\n
    PRODUCT_NAME is a 3-35 character long string containing only lower case letters digits and dashes.
    The product name must be prefixed with the organization short name and a dash.
    """
    if '-' not in product_name:
        click.secho(
            "Error: The product name must be prefixed with the organization "
            "short name and a dash.",
            fg='red',
            bold=True)
        sys.exit(1)

    short_name = product_name.split('-', 1)[0]
    conf = get_default_drift_config()
    org = conf.get_table('organizations').find({'short_name': short_name})
    if not org:
        click.secho(
            "No organization with short name {} found.".format(short_name),
            fg='red',
            bold=True)
        sys.exit(1)

    organization_name = org[0]['organization_name']

    with TSLocal() as ts:
        products = ts.get_table('products')
        entry = {
            'organization_name': organization_name,
            'product_name': product_name
        }

        if edit:
            edit = click.edit(json.dumps(entry, indent=4), editor='nano')
            if edit:
                entry = json.loads(edit)
        if products.find(entry):
            click.secho("Product {} already exists!".format(
                entry['product_name']),
                        fg='red',
                        bold=True)
            sys.exit(1)
        products.add(entry)

        _epilogue(ts)
コード例 #7
0
ファイル: cli.py プロジェクト: nonnib/drift-config
def add(tier_name, is_live, edit):
    """Add a new tier.\n
    TIER_NAME is a 3-20 character long upper case string containing only the letters A-Z."""
    with TSLocal() as ts:
        tiers = ts.get_table('tiers')
        entry = {'tier_name': tier_name, 'is_live': is_live}
        if edit:
            edit = click.edit(json.dumps(entry, indent=4), editor='nano')
            if edit:
                entry = json.loads(edit)
        if tiers.find(entry):
            click.secho("Tier {} already exists!".format(entry['tier_name']),
                        fg='red',
                        bold=True)
            sys.exit(1)
        tiers.add(entry)

        _epilogue(ts)