Skip to content

Commit

Permalink
Minor refactor after testing mountpoint logic on macOS and Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
dormant-user committed Nov 29, 2024
1 parent e3c2712 commit d682ba6
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 25 deletions.
20 changes: 16 additions & 4 deletions docs/genindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,24 @@ <h2 id="_">_</h2>
<li><a href="index.html#pyninja.features.gpu._darwin">(in module pyninja.features.gpu)</a>
</li>
</ul></li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="index.html#pyninja.modules.enums.StrEnum._generate_next_value_">_generate_next_value_() (pyninja.modules.enums.StrEnum method)</a>
</li>
<li><a href="index.html#pyninja.features.cpu._linux">_linux() (in module pyninja.features.cpu)</a>

<ul>
<li><a href="index.html#pyninja.features.gpu._linux">(in module pyninja.features.gpu)</a>
</li>
</ul></li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="index.html#pyninja.modules.enums.StrEnum._member_map_">_member_map_ (pyninja.modules.enums.StrEnum attribute)</a>
</li>
<li><a href="index.html#pyninja.modules.enums.StrEnum._member_names_">_member_names_ (pyninja.modules.enums.StrEnum attribute)</a>
</li>
<li><a href="index.html#pyninja.modules.enums.StrEnum._member_type_">_member_type_ (pyninja.modules.enums.StrEnum attribute)</a>
</li>
<li><a href="index.html#pyninja.modules.enums.StrEnum._value2member_map_">_value2member_map_ (pyninja.modules.enums.StrEnum attribute)</a>
</li>
<li><a href="index.html#pyninja.features.cpu._windows">_windows() (in module pyninja.features.cpu)</a>

<ul>
Expand Down Expand Up @@ -949,10 +959,10 @@ <h2 id="S">S</h2>
</li>
<li><a href="index.html#pyninja.modules.models.Session">Session (class in pyninja.modules.models)</a>
</li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="index.html#pyninja.modules.enums.Templates.session">session (pyninja.modules.enums.Templates attribute)</a>
</li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="index.html#pyninja.monitor.authenticator.session_error">session_error() (in module pyninja.monitor.authenticator)</a>
</li>
<li><a href="index.html#pyninja.modules.enums.Cookies.session_token">session_token (pyninja.modules.enums.Cookies attribute)</a>
Expand All @@ -968,6 +978,8 @@ <h2 id="S">S</h2>
<li><a href="index.html#pyninja.modules.models.ServiceStatus.status_code">status_code (pyninja.modules.models.ServiceStatus attribute)</a>
</li>
<li><a href="index.html#pyninja.features.service.stopped">stopped() (in module pyninja.features.service)</a>
</li>
<li><a href="index.html#pyninja.modules.enums.StrEnum">StrEnum (class in pyninja.modules.enums)</a>
</li>
<li><a href="index.html#pyninja.monitor.resources.system_resources">system_resources() (in module pyninja.monitor.resources)</a>
</li>
Expand Down
55 changes: 46 additions & 9 deletions docs/index.html

Large diffs are not rendered by default.

Binary file modified docs/objects.inv
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/searchindex.js

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions pyninja/features/disks/macOS.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ def parse_size(input_string: str) -> int:
return int(match.group(1)) if match else 0


def update_mountpoints(disks, device_ids: defaultdict) -> defaultdict:
def update_mountpoints(
disks: List[Dict[str, str]], device_ids: defaultdict
) -> defaultdict:
"""Updates mount points for physical devices based on diskutil data.
Args:
Expand All @@ -39,14 +41,14 @@ def update_mountpoints(disks, device_ids: defaultdict) -> defaultdict:
part_of_whole = disk.get("Part of Whole")
apfs_store = disk.get("APFS Physical Store", "")
mount_point = disk.get("Mount Point")
read_only = "Yes" in disk.get("Volume Read-Only")
if mount_point and not mount_point.startswith("/System/Volumes/"):
if part_of_whole in device_ids:
device_ids[part_of_whole].append(mount_point)
else:
for device_id in device_ids:
if apfs_store.startswith(device_id):
if apfs_store.startswith(device_id) and read_only:
device_ids[device_id].append(mount_point)
# todo: verify this logic in macOS
for device_id, mountpoints in device_ids.items():
if not mountpoints:
device_ids[device_id] = ["Not Mounted"]
Expand Down
3 changes: 1 addition & 2 deletions pyninja/features/disks/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,5 @@ def drive_info() -> List[Dict[str, str]]:
if device_id in usage:
item["Mountpoints"] = ", ".join(usage[device_id])
else:
# todo: verify this logic in Windows
item["Mountpoints"] = ["Not Mounted"]
item["Mountpoints"] = "Not Mounted"
return data
1 change: 0 additions & 1 deletion pyninja/monitor/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ async def system_resources() -> Dict[str, dict | List[Dict[str, str | int]]]:
Dict[str, dict]:
Returns a nested dictionary.
"""
# todo: Create a 4th section for disk usage - that includes PIE charts for all the attached disks
system_metrics_task = asyncio.create_task(get_system_metrics())
docker_stats_task = asyncio.create_task(get_docker_stats())
service_stats_task = asyncio.create_task(
Expand Down
1 change: 0 additions & 1 deletion pyninja/monitor/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ async def websocket_endpoint(websocket: WebSocket, session_token: str = Cookie(N
# Base task with a placeholder asyncio sleep to start the task loop
task = asyncio.create_task(asyncio.sleep(0.1))
# Store disk usage information (during startup) to avoid repeated calls
# todo: Make this an async call or simply render via websocket but cache the response
disk_info = list(monitor.resources.get_disk_info())
while True:
# Validate session asynchronously (non-blocking)
Expand Down
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ requires-python = ">=3.10"
[tool.setuptools]
packages = [
"pyninja",
"pyninja.executors",
"pyninja.features",
"pyninja.modules",
"pyninja.monitor",
"pyninja.routes",
"pyninja.monitor",
"pyninja.modules",
"pyninja.features",
"pyninja.executors",
"pyninja.features.disks",
"pyninja.monitor.templates"
]
Expand Down

0 comments on commit d682ba6

Please sign in to comment.