Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions austrakka/components/project/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

from .dataset import dataset
from .field import field
from .provision import provision
from .metadata import metadata
from .document import document

Expand All @@ -37,7 +36,6 @@ def project(ctx):


project.add_command(field)
project.add_command(provision)
project.add_command(metadata)
project.add_command(dataset)
project.add_command(document)
Expand All @@ -46,7 +44,7 @@ def project(ctx):


@project.command(
'add',
'add',
hidden=hide_admin_cmds(),
help='Add a new project'
)
Expand Down Expand Up @@ -78,7 +76,7 @@ def project_add(


@project.command(
'update',
'update',
hidden=hide_admin_cmds(),
help='Update an existing project',
)
Expand Down Expand Up @@ -138,7 +136,7 @@ def dashboard_get(project_abbrev: str, out_format: str):
def projects_list(view_type: str,out_format: str):
list_projects(view_type, out_format)


@project.command('set-type')
@click.argument('project-abbrev', type=str)
@opt_type()
Expand Down
32 changes: 14 additions & 18 deletions austrakka/components/project/metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,38 @@

from austrakka.utils.output import table_format_option
from austrakka.utils.output import FORMATS
from austrakka.utils.options import opt_merge_algorithm
from austrakka.utils.options import opt_view_id

from .funcs import list_dataset_views, \
download_dataset_view
from .funcs import get_view, \
download_view

@click.group()
@click.pass_context
def metadata(ctx):
"""Commands to query for metadata views for a project, including commands for setting how
the views are generated. This sub command is predominantly used for fetching metadata
that was uploaded and shared with the project, as well as project analysis metadata
that was uploaded by a project analyst. Data from both sources are merged to create
one or more unified views which are accessible to project members.
"""Commands to query for metadata views for a project, including commands for setting how
the views are generated. This sub command is predominantly used for fetching metadata
that was uploaded and shared with the project, as well as project analysis metadata
that was uploaded by a project analyst. Data from both sources are merged to create
one or more unified views which are accessible to project members.

All views have the same number of sample rows but differ in the number of fields. The
base view contains all fields which are accessible by the project. All other views are
subsets of the base."""
ctx.context = ctx.parent.context


@metadata.command('list')
@metadata.command('get')
@click.argument('project-abbrev', type=str)
@table_format_option()
def get_dataset_view_list(project_abbrev: str, out_format: str):
"""Get a list of metadata views for a given project."""
list_dataset_views(project_abbrev, out_format)
def get_dataset_view(project_abbrev: str, out_format: str):
"""Get view information for a given project."""
get_view(project_abbrev, out_format)

@metadata.command('get')
@opt_view_id()
@metadata.command('download')
@click.argument('project-abbrev', type=str)
@table_format_option(FORMATS.CSV)
def get_dataset_view(
def download_dataset_view(
project_abbrev: str,
view_id: Optional[str],
out_format: str,
):
"""Get a specific metadata view. By default, the full metadata view is returned."""
download_dataset_view(view_id, project_abbrev, out_format)
download_view( project_abbrev, out_format)
31 changes: 9 additions & 22 deletions austrakka/components/project/metadata/funcs.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# pylint: disable=R0801
import json
from typing import Optional

import httpx
from httpx import HTTPStatusError
from loguru import logger
from austrakka.utils.api import api_get, api_get_stream
from austrakka.utils.api import api_get_stream
from austrakka.utils.exceptions import FailedResponseException, UnknownResponseException
from austrakka.utils.helpers.output import call_get_and_print
from austrakka.utils.http import get_header_value, HEADERS
from austrakka.utils.misc import logger_wraps
from austrakka.utils.output import print_dict
Expand All @@ -15,40 +15,27 @@


@logger_wraps()
def list_dataset_views(
def get_view(
abbrev: str,
out_format: str):
path = "/".join([PROJECT_PATH, abbrev, 'project-views'])
response = api_get(path)
data = response['data'] if ('data' in response) else response
if not data:
logger.info("No Views available")
return

print_dict(
data,
out_format,
)

call_get_and_print(path, out_format)

@logger_wraps()
def download_dataset_view(
dataset_view_id: Optional[str],
def download_view(
abbrev: str,
out_format: str
):
query_path = f'?datasetViewId={dataset_view_id}' if dataset_view_id is not None else ''
api_path = "/".join([PROJECT_PATH, abbrev, f'download-project-view{query_path}'])
dataset_msg = f'dataset {dataset_view_id} of ' if dataset_view_id is not None else ''
api_path = "/".join([PROJECT_PATH, abbrev, "download-project-view"])
try:
def _write_chunks(resp: httpx.Response):
filename = get_header_value(resp, HEADERS.CONTENT_DISPOSITION, "filename")
logger.info(f"Downloading file {filename} for {dataset_msg}{abbrev}")
logger.info(f"Downloading file {filename} for {abbrev}")
json_str = ""
for chunk in resp.iter_bytes():
json_str += chunk.decode('utf-8')
print_dict(json.loads(json_str), out_format)
logger.success(f"Successfully downloaded file {filename} for {dataset_msg}{abbrev}")
logger.success(f"Successfully downloaded file {filename} for {abbrev}")

api_get_stream(api_path, _write_chunks)

Expand All @@ -58,5 +45,5 @@ def _write_chunks(resp: httpx.Response):
log_response_compact(ex)
except HTTPStatusError as ex:
logger.error(
f'Failed to download from {dataset_msg}{abbrev}. Error: {ex}'
f'Failed to download from {abbrev}. Error: {ex}'
)
58 changes: 0 additions & 58 deletions austrakka/components/project/provision/__init__.py

This file was deleted.

64 changes: 0 additions & 64 deletions austrakka/components/project/provision/funcs.py

This file was deleted.

22 changes: 0 additions & 22 deletions austrakka/utils/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,18 +259,6 @@ def options_seq_id_or_file(func):
)
return _opt_seq_id(_opt_file(func))

def opt_prov_id(**attrs: t.Any):
defaults = {
'required': True,
'help': 'provision id',
}
return create_option(
"-pi",
"--prov-id",
type=click.STRING,
**{**defaults, **attrs}
)


def opt_field_name(**attrs: t.Any):
defaults = {
Expand Down Expand Up @@ -857,16 +845,6 @@ def opt_tree_version_id(**attrs: t.Any):
)


def opt_view_id(**attrs: t.Any):
defaults = {
'required': False,
'help': 'Project metadata view ID',
}
return create_option(
'--view-id',
**{**defaults, **attrs}
)


def opt_server_username(**attrs: t.Any):
defaults = {
Expand Down
Loading