Ejemplo n.º 1
0
def list_dataset_files_view(user, cache):
    """List files in a dataset."""
    ctx = DatasetFilesListRequest().load(request.args)
    project = cache.get_project(cache.ensure_user(user), ctx['project_id'])

    with chdir(project.abs_path):
        ctx['files'] = list_files(datasets=[ctx['short_name']])

    return result_response(DatasetFilesListResponseRPC(), ctx)
Ejemplo n.º 2
0
def test_list_files_default(project, tmpdir):
    """Test a default file listing."""
    create_dataset("ds1", title="", description="", creators=[], commit_message="my awesome dataset")
    data_file = tmpdir / Path("somefile")
    data_file.write_text("1,2,3", encoding="utf-8")

    add_file([str(data_file)], "ds1")
    files = list_files(datasets=["ds1"])

    assert isinstance(files, list)
    assert "somefile" in [file_.name for file_ in files]
Ejemplo n.º 3
0
def list_dataset_files_view(user, cache):
    """List files in a dataset."""
    ctx = DatasetFilesListRequest().load(request.args)
    project = cache.get_project(cache.ensure_user(user), ctx['project_id'])

    if not project.abs_path.exists():
        return error_response(INVALID_PARAMS_ERROR_CODE,
                              'invalid project_id argument')

    with chdir(project.abs_path):
        ctx['files'] = list_files(datasets=[ctx['dataset_name']])

    return result_response(DatasetFilesListResponseRPC(), ctx)
Ejemplo n.º 4
0
def test_list_files_default(project, tmpdir):
    """Test a default file listing."""
    create_dataset('ds1',
                   title='',
                   description='',
                   creators=[],
                   commit_message='my awesome dataset')
    data_file = tmpdir / Path('somefile')
    data_file.write_text('1,2,3', encoding='utf-8')

    add_file([str(data_file)], 'ds1')
    files = list_files(datasets=['ds1'])

    assert isinstance(files, list)
    assert 'somefile' in [ds.name for ds in files]
Ejemplo n.º 5
0
def list_dataset_files_view(user, cache):
    """List files in a dataset."""
    ctx = DatasetFilesListRequest().load(request.args)
    project = cache.get_project(user, ctx['project_id'])
    project_path = make_project_path(user, project)

    if not project_path:
        return jsonify(
            error={
                'code': INVALID_PARAMS_ERROR_CODE,
                'reason': 'invalid project_id argument',
            })

    with chdir(project_path):
        dataset_files = json.loads(
            # TODO: fix core interface to address this issue (add ticket ref)
            list_files(ctx['dataset_name'], None, None, None, 'json-ld'))
        ctx['files'] = [
            DatasetFileDetails().load(ds, unknown=EXCLUDE)
            for ds in dataset_files
        ]

    response = DatasetFilesListResponse().load(ctx, unknown=EXCLUDE)
    return jsonify(DatasetFilesListResponseRPC().load({'result': response}))
Ejemplo n.º 6
0
def ls_files(short_names, creators, include, exclude, format, columns):
    """List files in dataset."""
    echo_via_pager(
        list_files(short_names, creators, include, exclude, format, columns)
    )
Ejemplo n.º 7
0
def ls_files(names, creators, include, exclude, format, columns):
    """List files in dataset."""
    click.echo(list_files(names, creators, include, exclude, format, columns))
Ejemplo n.º 8
0
def ls_files(names, creators, include, exclude, format):
    """List files in dataset."""
    echo_via_pager(list_files(names, creators, include, exclude, format))
Ejemplo n.º 9
0
 def renku_op(self):
     """Renku operation for the controller."""
     return list_files(datasets=[self.ctx["name"]])