diff --git a/shelephant/dataset.py b/shelephant/dataset.py index 6c3ee49..381e53d 100644 --- a/shelephant/dataset.py +++ b/shelephant/dataset.py @@ -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, @@ -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: diff --git a/tests/test_dataset.py b/tests/test_dataset.py index f57c8cc..e89b730 100644 --- a/tests/test_dataset.py +++ b/tests/test_dataset.py @@ -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")