1 # ============LICENSE_START=======================================================
3 # ================================================================================
4 # Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
5 # ================================================================================
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 # ============LICENSE_END=========================================================
19 # ECOMP is a trademark and service mark of AT&T Intellectual Property.
21 # -*- coding: utf-8 -*-
23 Provides data format commands
29 from dcae_cli.util import load_json
30 from dcae_cli.util.logger import get_logger
31 from dcae_cli.commands import util
32 from dcae_cli.commands.util import create_table, parse_input
34 from dcae_cli.catalog.exc import MissingEntry
37 logger = get_logger('DataFormatCommand')
45 @data_format.command()
46 @click.option('--update', is_flag=True, help='Updates a locally added data format if it has not been already pushed')
47 @click.argument('specification', type=click.Path(resolve_path=True, exists=True))
49 def add(obj, update, specification):
50 '''Tracks a data format file SPECIFICATION locally but does not push to the catalog'''
51 spec = load_json(specification)
52 user, catalog = obj['config']['user'], obj['catalog']
53 catalog.add_format(spec, user, update)
56 @data_format.command(name='list')
57 @click.option('--latest', is_flag=True, help='Only list the latest version of data formats')
59 def list_format(obj, latest):
60 """Lists all your data formats"""
61 user, catalog = obj['config']['user'], obj['catalog']
62 dfs = catalog.list_formats(latest, user=user)
64 def format_record(df):
65 return (df["name"], df["version"],
66 util.format_description(df["description"]),
67 util.get_status_string(df), df["modified"])
69 dfs = [ format_record(df) for df in dfs ]
72 click.echo("Data formats for {0}".format(user))
73 click.echo(create_table(('Name', 'Version', 'Description', 'Status', 'Modified'), dfs))
76 @data_format.command()
77 @click.argument('data-format', metavar="name:version")
79 def show(obj, data_format):
80 '''Provides more information about FORMAT'''
81 name, ver = parse_input(data_format)
82 spec = obj['catalog'].get_format_spec(name, ver)
84 click.echo(util.format_json(spec))
87 @data_format.command()
88 @click.argument('data-format')
90 def publish(obj, data_format):
91 """Publishes data format to make publicly available"""
92 name, version = parse_input(data_format)
93 user, catalog = obj['config']['user'], obj['catalog']
95 if catalog.publish_format(user, name, version):
96 click.echo("Data format has been published")
98 click.echo("Data format could not be published")