def startapp(name, dir): try: r = _startapp(name, dir) except Exception as e: logger.error('startapp failed: {}'.format(e)) click.echo('startapp failed.') sys.exit(ERROR_EXITCODE) click.echo(json_output_formatter(r))
def create_repository(name, description): try: r = _create_repository(name, description) except Exception as e: logger.error('create-repository failed: {}'.format(e)) click.echo('create-repository failed.') sys.exit(ERROR_EXITCODE) click.echo(json_output_formatter(r))
def describe_repository_tags(repository_id, limit, offset): try: r = _describe_repository_tags(repository_id, limit, offset) except Exception as e: logger.error('describe-repository-tags failed: {}'.format(e)) click.echo('describe-repository-tags failed.') sys.exit(ERROR_EXITCODE) click.echo(json_output_formatter(r))
def delete_repository(repository_id): try: r = _delete_repository(repository_id) except Exception as e: logger.error('delete-repository failed: {}'.format(e)) click.echo('delete-repository failed.') sys.exit(ERROR_EXITCODE) click.echo(json_output_formatter(r))
def describe_datasets(dataset_id): try: url = "{}/datasets".format(ORGANIZATION_ENDPOINT) if dataset_id == 'all' \ else "{}/datasets/{}".format(ORGANIZATION_ENDPOINT, dataset_id) r = api_get(url) except Exception as e: logger.error('describe-dataset failed: {}'.format(e)) click.echo('describe-dataset failed.') sys.exit(ERROR_EXITCODE) click.echo(json_output_formatter(r))
def delete_dataset(dataset_id): try: url = '{}/datasets/{}'.format(ORGANIZATION_ENDPOINT, dataset_id) r = api_delete(url) except Exception as e: logger.error('delete-dataset failed: {}'.format(e)) click.echo('delete-dataset failed.') sys.exit(ERROR_EXITCODE) click.echo(json_output_formatter(r))
def create_dataset(name, dataset_type, props): try: props = props.read() props = json.loads(props) parameters = {'name': name, 'type': dataset_type, 'props': props} json_data = json.dumps(parameters) url = "{}/datasets".format(ORGANIZATION_ENDPOINT) r = api_post(url, json_data) except Exception as e: logger.error('create-dataset failed: {}'.format(e)) click.echo('create-dataset failed.') sys.exit(ERROR_EXITCODE) click.echo(json_output_formatter(r))
def create_dataset_item(dataset_id, _payload): ext = os.path.splitext(_payload.name)[-1] try: if ext in ['.json']: payload = json.loads(_payload.read()) elif ext in ['.yml', '.yaml']: payload = yaml.load(_payload.read()) else: click.echo( 'Invalid payload file format. .json .yml .yaml is acceptable') sys.exit(ERROR_EXITCODE) url = "{}/datasets/{}/items".format(ORGANIZATION_ENDPOINT, dataset_id) r = api_post(url, json.dumps(payload)) except Exception as e: logger.error('create-dataset-item failed: {}'.format(e)) click.echo('create-dataset-item failed.') sys.exit(ERROR_EXITCODE) click.echo(json_output_formatter(r))
def dataset_import_from_datalake(channel_id, dataset_id, property_metadata_keys, category_id, _type, _max): """Imports dataset items from datalake. You can import dataset items from a datalake channel with properties. You have to prepare a datalake channel that has files you want to use as dataset. `x-abeja-meta-label` and `x-abeja-meta-label_id` is used as properties by default. For example, `cat00001.jpg` with `x-abeja-meta-label:cat` and `x-abeja-meta-label_id:1` is registered to a dataset with label `cat` and label_id 1. You can specify the multiple metadata names for properties with `--property-metadata-key` option. """ try: r = import_dataset_from_datalake(channel_id, dataset_id, property_metadata_keys, category_id, _type, _max) except Exception as e: logger.exception(e) sys.exit(ERROR_EXITCODE) click.echo(json_output_formatter(r))
def describe_dataset_items(dataset_id, dataset_item_id, q): if dataset_item_id and q: click.echo( 'describe-dataset-items failed: q cannot be specified when dataset-item-id is specified' ) sys.exit(ERROR_EXITCODE) try: if dataset_item_id is None: url = "{}/datasets/{}/items".format(ORGANIZATION_ENDPOINT, dataset_id) res = _get_all_dataset_items(url, q) else: url = "{}/datasets/{}/items/{}".format(ORGANIZATION_ENDPOINT, dataset_id, dataset_item_id) res = api_get(url) except Exception as e: logger.error('describe-dataset-items failed: {}'.format(e)) click.echo('describe-dataset-items failed.') sys.exit(ERROR_EXITCODE) click.echo(json_output_formatter(res))