Skip to content

Commit

Permalink
Add --quite flag to 'dtool copy' command
Browse files Browse the repository at this point in the history
  • Loading branch information
tjelvar-olsson committed Oct 3, 2017
1 parent dec55dc commit 2415bd4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Added
^^^^^

- ``dtool readme show`` command that returns the readme content
- ``--quiet`` flag to ``dtool copy`` command


Changed
Expand Down
25 changes: 17 additions & 8 deletions dtool_create/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,11 @@ def freeze(proto_dataset_uri):


@click.command()
@click.option("--quiet", "-q", is_flag=True)
@dataset_uri_argument
@click.argument("prefix", default="")
@click.argument("storage", default="file", callback=storagebroker_validation)
def copy(dataset_uri, prefix, storage):
def copy(quiet, dataset_uri, prefix, storage):
"""Copy a dataset to a different location."""
# Check if the destination URI is already a dataset
# and exit gracefully if true.
Expand All @@ -302,14 +303,22 @@ def copy(dataset_uri, prefix, storage):
"Path already exists: {}".format(parsed_uri.path))

# Finally do the copy
num_items = len(list(src_dataset.identifiers))
with click.progressbar(length=num_items*2,
label="Copying dataset") as progressbar:
if quiet:
dest_uri = dtoolcore.copy(
dataset_uri,
prefix,
storage,
CONFIG_PATH,
progressbar)

click.secho("Dataset copied to {}".format(dest_uri))
CONFIG_PATH)
click.secho(dest_uri)
else:
num_items = len(list(src_dataset.identifiers))
with click.progressbar(length=num_items*2,
label="Copying dataset") as progressbar:
dest_uri = dtoolcore.copy(
dataset_uri,
prefix,
storage,
CONFIG_PATH,
progressbar)

click.secho("Dataset copied to:\n{}".format(dest_uri))
15 changes: 15 additions & 0 deletions tests/test_dtool_dataset_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from click.testing import CliRunner

from dtoolcore import DataSet, ProtoDataSet
from dtoolcore.compare import diff_content

from . import chdir_fixture, tmp_dir_fixture # NOQA

Expand Down Expand Up @@ -53,3 +54,17 @@ def test_dataset_copy_functional(chdir_fixture): # NOQA
result = runner.invoke(copy, [dataset_uri, copy_directory])
assert result.exit_code != 0
assert result.output.find("Error: Dataset already exists") != -1

# Create another directory to copy the dataset to.
copy_directory_2 = os.path.abspath("copy_dir_2")
os.mkdir(copy_directory_2)

# Test the quite flag.
result = runner.invoke(copy, ["--quiet", dataset_uri, copy_directory_2])
assert result.exit_code == 0
expected_uri = "file://" + os.path.join(copy_directory_2, dataset_name)
assert result.output.strip() == expected_uri

# Compare the content of the two datasets.
copied_dataset = DataSet.from_uri(expected_uri)
assert len(diff_content(dataset, copied_dataset)) == 0

0 comments on commit 2415bd4

Please sign in to comment.