-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP feat(datasets): added dataset ls-files, unlink and delete commands #436
Conversation
renku/api/datasets.py
Outdated
files_in_dataset = [( | ||
key, | ||
os.path.realpath( | ||
self.renku_datasets_path / dataset.name / dataset_file.path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.renku_datasets_path / dataset.name / dataset_file.path | |
self.renku_datasets_path / dataset.identifier / dataset_file.path |
renku/api/datasets.py
Outdated
meta_file = dataset_dir_path / self.METADATA | ||
meta_file.unlink() | ||
|
||
def unlink_files(self, dataset, pattern, exclude=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def unlink_files(self, dataset, pattern, exclude=None): | |
def unlink_files(self, dataset, include=None, exclude=None): |
renku/api/datasets.py
Outdated
|
||
def _match(file): | ||
filename = Path(file[1]).name | ||
result = fnmatch(filename, pattern) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
result = fnmatch(filename, pattern) | |
result = fnmatch(filename, include) if include is not None else result |
renku/cli/dataset.py
Outdated
@click.option('--verbose', '-v', is_flag=True) | ||
@pass_local_client(clean=True, commit=True) | ||
def delete(client, name, force, verbose): | ||
"""Deletes a dataset.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""Deletes a dataset.""" | |
"""Delete a dataset metadata.""" |
@@ -46,11 +47,19 @@ class DatasetsApiMixin(object): | |||
DATASETS = 'datasets' | |||
"""Directory for storing dataset metadata in Renku.""" | |||
|
|||
REFS_DATASETS = 'refs' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do you need it? the LinkReference
object should provide you with enough abstraction.
if not force and dataset.files: | ||
raise errors.DatasetNotEmpty() | ||
|
||
dataset_dir_path = self.renku_datasets_path / dataset.identifier.hex |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you might need to iterate over all refs/datasets
since there might be more aliases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we might need a another renku doctor
check that find broken refs
"""Find datasets which contain given dataset file. | ||
|
||
:param client: LocalClient instance. | ||
:param dataset_file: DatasetFile instance. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO it would be nicer to filter by path.
@@ -54,3 +54,20 @@ def check_missing_files(client): | |||
) | |||
|
|||
return False | |||
|
|||
|
|||
def file_in_datasets(client, dataset_file, exclude_dataset=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider building a map: path -> [dataset, ...]
if exclude_dataset and \ | ||
exclude_dataset.identifier == dataset.identifier: | ||
continue | ||
if dataset_file in dataset.files.values(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if dataset_file in dataset.files.values(): | |
if dataset_file.path in dataset.files: |
meta_file.unlink() | ||
dataset_dir_path.rmdir() | ||
|
||
dataset_ref = self.renku_refs_path / Path(dataset.name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dataset_ref = self.renku_refs_path / Path(dataset.name) |
dataset_dir_path.rmdir() | ||
|
||
dataset_ref = self.renku_refs_path / Path(dataset.name) | ||
if dataset_ref.is_symlink(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if dataset_ref.is_symlink(): |
|
||
dataset_ref = self.renku_refs_path / Path(dataset.name) | ||
if dataset_ref.is_symlink(): | ||
dataset_ref.unlink() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dataset_ref.unlink() |
relative_path, | ||
os.path.realpath( | ||
str( | ||
self.renku_datasets_path / dataset.name / dataset_file.path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.renku_datasets_path / dataset.name / dataset_file.path | |
self.renku_datasets_path / dataset.identifier.hex / dataset_file.path |
return found_one | ||
|
||
file_unlinked = [] | ||
for relative, absolute, file_ in filter(_match, files_in_dataset): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using filter
is not very "Pythonic". the better way is to use a list comprehension.
for relative, absolute, file_ in filter(_match, files_in_dataset): | |
file_unlinked = [ | |
file_ | |
for file_ in files_in_dataset | |
if _match(file_) | |
] |
:param include: Remove files matching the include pattern. | ||
:param exclude: Keep files matching the exclude pattern. | ||
""" | ||
files_in_dataset = [( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
files_in_dataset = [
self.renku_datasets_path / dataset.identifier.hex / file_
for file_ in dataset.files
]
if not files_in_dataset: | ||
raise errors.ResourceNotFound(resource_type='DatasetFile') | ||
|
||
def _match(file): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def _match(file): | |
def _match(file_): |
filename = Path(file[1]).name | ||
found_one = False | ||
for pattern in include: | ||
found_one = fnmatch(filename, pattern) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
found_one = fnmatch(filename, pattern) | |
found_one = file_.match(pattern) |
DO NOT MERGE
This PR adds new commands for dataset:
Fixes #418