-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support removing data in "gas rm" command
- Loading branch information
1 parent
26898fd
commit 2227b6e
Showing
4 changed files
with
96 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/env python3 | ||
# | ||
# Copyright 2021 Graviti. Licensed under MIT License. | ||
# | ||
|
||
"""Implementation of gas rm.""" | ||
|
||
import sys | ||
from typing import Dict | ||
|
||
import click | ||
|
||
from .tbrn import TBRN, TBRNType | ||
from .utility import filter_data, get_dataset_client, get_gas | ||
|
||
|
||
def _implement_rm(obj: Dict[str, str], tbrn: str, is_recursive: bool) -> None: | ||
gas = get_gas(**obj) | ||
info = TBRN(tbrn=tbrn) | ||
dataset_client = get_dataset_client(gas, info, is_fusion=False) | ||
|
||
if info.type not in (TBRNType.SEGMENT, TBRNType.NORMAL_FILE): | ||
click.echo(f'"{tbrn}" is an invalid path to remove', err=True) | ||
sys.exit(1) | ||
|
||
if not info.is_draft: | ||
click.echo( | ||
f'To remove the data, "{info}" must be in draft status, like "{info}#1', err=True | ||
) | ||
sys.exit(1) | ||
|
||
if info.type == TBRNType.SEGMENT: | ||
if not is_recursive: | ||
click.echo("Please use -r option to remove the whole segment", err=True) | ||
sys.exit(1) | ||
dataset_client.delete_segment(info.segment_name) | ||
elif info.remote_path.endswith("/") and not is_recursive: | ||
click.echo("Please use -r option to remove recursively", err=True) | ||
sys.exit(1) | ||
else: | ||
segment = dataset_client.get_segment(info.segment_name) | ||
data = filter_data(segment.list_data_paths(), info.remote_path, is_recursive) | ||
if not data: | ||
echo_info = "file or directory" if is_recursive else "file" | ||
click.echo(f'No such {echo_info} "{tbrn}" ', err=True) | ||
sys.exit(1) | ||
segment.delete_data(data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters