-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInventoryTree.py
24 lines (18 loc) · 902 Bytes
/
InventoryTree.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from textual.message import Message
from textual.widgets import DirectoryTree
from pathlib import Path
from typing import Iterable
class InventoryTree(DirectoryTree):
class Selected(Message):
"""Inventory selected message."""
def __init__(self, path: Path) -> None:
self.path = path
super().__init__()
def filter_paths(self, paths: Iterable[Path]) -> Iterable[Path]:
return [path for path in paths
if not path.name.startswith('.')
and (path.is_dir() or path.suffix == '' or 'hosts' in path.name)]
def on_directory_tree_file_selected(self, event: DirectoryTree.FileSelected) -> None:
"""Called when the user click a hosts file in the inventory directory tree."""
# Convert the FileSelected message into an InventoryTree.Selected message
self.post_message(self.Selected(event.path))