Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ Create a YAML config file (see [`config.yaml`](config.yaml) for a template):
paths:
- /path/to/data

# Unix group whose members' subdirectories should be reported (optional)
group: your_group_name
# Unix groups whose members' subdirectories should be reported (optional)
groups:
- your_group_name

# Shell-style glob patterns for files/directories to exclude (optional)
ignore:
Expand All @@ -37,7 +38,7 @@ ignore:
| Key | Description |
|---|---|
| `paths` | List of top-level paths to scan (required) |
| `group` | Unix group name; enables group mode (optional, overridden by `--group`) |
| `groups` | List of Unix group names; enables group mode (optional, overridden by `--groups`) |
| `ignore` | Glob patterns matched against base names to exclude from all scans |

## Usage
Expand All @@ -49,7 +50,7 @@ python3 ontrack.py --config config.yaml [OPTIONS]
| Option | Description |
|---|---|
| `--config FILE` | Path to the YAML config file (default: `config.yaml`) |
| `--group GROUP` | Unix group name; overrides the `group` key in the config file |
| `--groups GROUP [GROUP ...]` | One or more Unix group names; overrides the `groups` key in the config file |
| `--light` | Skip file-count and size scanning; only report directory and owner |
| `--progress` | Show progress bars while scanning |
| `--output FILE` | Write the report as YAML to `FILE` instead of printing to stdout |
Expand All @@ -62,10 +63,10 @@ python3 ontrack.py --config config.yaml [OPTIONS]
python3 ontrack.py --config config.yaml
```

**Group mode** — for each configured directory, finds and reports subdirectories owned by members of the specified Unix group. Descends until a directory containing at least one file is found:
**Group mode** — for each configured directory, finds and reports subdirectories owned by members of the specified Unix groups. Descends until a directory containing at least one file is found:

```bash
python3 ontrack.py --config config.yaml --group researchers
python3 ontrack.py --config config.yaml --groups researchers
```

## Example Output
Expand Down
2 changes: 1 addition & 1 deletion ontrack.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def report_directory(
print(f"Directory : {entry['directory']}")
print(f"Username : {entry['username']}")
if "groups" in entry:
print(f"Groups : {', '.join(entry['groups'])}")
print(f"Group : {', '.join(entry['groups'])}")
if "file_count" in entry:
print(f"Files : {entry['file_count']}")
print(f"Total size: {entry['total_size_human']}")
Expand Down
14 changes: 6 additions & 8 deletions tests/test_ontrack.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def test_get_directory_stats_group_excludes_files():


def test_report_directory_with_group(capsys):
"""report_directory prints the Groups line when groups are supplied."""
"""report_directory prints the Group line when groups are supplied."""
current_gid = os.getgid()
group_name = grp.getgrgid(current_gid).gr_name

Expand All @@ -288,19 +288,17 @@ def test_report_directory_with_group(capsys):

report_directory(tmpdir, groups=[group_name])
captured = capsys.readouterr()
assert "Groups" in captured.out
assert "Group" in captured.out
assert group_name in captured.out


def test_report_directory_without_group_no_group_line(capsys):
"""report_directory does not print a Groups line when no groups are given."""
"""report_directory does not print a Group line when no groups are given."""
with tempfile.TemporaryDirectory() as tmpdir:
with open(os.path.join(tmpdir, "sample.txt"), "w") as f:
f.write("data")

report_directory(tmpdir)
captured = capsys.readouterr()
assert "Groups" not in captured.out
assert "Group :" not in captured.out


# ---------------------------------------------------------------------------
Expand All @@ -326,7 +324,7 @@ def test_main_with_group(tmp_path, capsys):
main(str(config_file), groups=[group_name])
captured = capsys.readouterr()
assert str(user_subdir) in captured.out
assert "Groups" in captured.out
assert "Group" in captured.out
assert group_name in captured.out


Expand Down Expand Up @@ -356,7 +354,7 @@ def test_main_with_multiple_groups(tmp_path, capsys):
main(str(config_file), groups=[group_name, second_group])
captured = capsys.readouterr()
assert str(user_subdir) in captured.out
assert "Groups" in captured.out
assert "Group" in captured.out
assert group_name in captured.out


Expand Down
Loading