Skip to content

Commit

Permalink
Adding shelephant status --not-on (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
tdegeus authored Feb 28, 2024
1 parent 9c7c43e commit a60c18f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
11 changes: 11 additions & 0 deletions shelephant/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1904,6 +1904,11 @@ class MyFmt(
parser.add_argument(
"--in-use", type=str, help="Select storage location in use (use 'none' for unavailable)."
)
parser.add_argument(
"--not-on",
type=str,
help="List files that are not on a storage location.",
)
parser.add_argument(
"--on",
type=str,
Expand Down Expand Up @@ -2004,6 +2009,12 @@ def status(args: list[str]):
e[:, 1] = "here"
data = np.vstack((data, e))

if args.not_on is not None:
name = args.not_on
iname = -(len(storage) - np.argmax(np.equal(storage, name)))
keep = np.equal(data[:, iname], "x")
data = data[keep, :]

if len(args.on) > 0:
keep = np.zeros((len(data)), dtype=bool)
for name in args.on:
Expand Down
32 changes: 32 additions & 0 deletions tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1428,6 +1428,38 @@ def test_status_on(self):
ret = _plain(sio.getvalue())[1:]
self.assertEqual(ret, expect)

def test_status_not_on(self):
with tempdir():
dataset = pathlib.Path("dataset")
source1 = pathlib.Path("source1")
source2 = pathlib.Path("source2")

dataset.mkdir()
source1.mkdir()
source2.mkdir()

with cwd(source1):
create_dummy_files(["a.txt", "b.txt", "c.txt", "d.txt"])

with cwd(source2):
create_dummy_files(["a.txt", "b.txt"])
create_dummy_files(["e.txt", "f.txt"], slice(4, None, None))

with cwd(dataset):
shelephant.dataset.init([])
shelephant.dataset.add(["source1", "../source1", "--rglob", "*.txt", "-q"])
shelephant.dataset.add(["source2", "../source2", "--rglob", "*.txt", "-q"])

with cwd(dataset), contextlib.redirect_stdout(io.StringIO()) as sio:
shelephant.dataset.status(["--table", "PLAIN_COLUMNS", "--not-on", "source1"])

expect = [
"e.txt source2 x ==",
"f.txt source2 x ==",
]
ret = _plain(sio.getvalue())[1:]
self.assertEqual(ret, expect)

def test_removed(self):
with tempdir():
dataset = pathlib.Path("dataset")
Expand Down

0 comments on commit a60c18f

Please sign in to comment.