Skip to content

Commit 19ab8d9

Browse files
authored
Update __init__.py
1 parent 455304a commit 19ab8d9

1 file changed

Lines changed: 69 additions & 1 deletion

File tree

‎pydiskinfo/pydiskinfo/__init__.py‎

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,71 @@
1+
# pydiskinfo - Lightweight cross-platform disk info library
2+
# Copyright (C) 2026 Your Name (alebo Meno/Autor pôvodného projektu)
3+
#
4+
# This program is free software: you can redistribute it and/or modify
5+
# it under the terms of the GNU Affero General Public License as published by
6+
# the Free Software Foundation, either version 3 of the License, or
7+
# (at your option) any later version.
8+
#
9+
# This program is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even theoretical WARRANTY OF
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU Affero General Public License for more details.
13+
14+
import platform
15+
import os
16+
from .models import DiskInfo
17+
18+
__version__ = "1.0.0"
19+
20+
def get_disks() -> list[DiskInfo]:
21+
"""Vráti zoznam všetkých pripojených diskov/partícií pre aktuálny OS."""
22+
system = platform.system()
23+
if system == "Windows":
24+
from .windows import get_disks_windows
25+
return get_disks_windows()
26+
elif system == "Linux":
27+
from .linux import get_disks_linux
28+
return get_disks_linux()
29+
elif system == "Darwin":
30+
from .macos import get_disks_macos
31+
return get_disks_macos()
32+
else:
33+
return []
34+
35+
def get_disk_by_path(path: str) -> DiskInfo | None:
36+
"""Nájde disk, na ktorom sa nachádza zadaná cesta."""
37+
abs_path = os.path.abspath(path)
38+
disks = get_disks()
39+
40+
# Zoradíme od najdlhšej cesty po najkratšiu pre presný match
41+
disks.sort(key=lambda d: len(d.mount), reverse=True)
42+
43+
for disk in disks:
44+
if abs_path.lower().startswith(disk.mount.lower()):
45+
return disk
46+
return None
47+
48+
def get_directory_size(dir_path: str) -> dict:
49+
"""Vráti veľkosť priečinka v bajtoch a zoznam položiek."""
50+
total_size = 0
51+
all_items = []
52+
if not os.path.exists(dir_path):
53+
return {"size_bytes": 0, "items": []}
54+
55+
for root, dirs, files in os.walk(dir_path, topdown=False):
56+
for f in files:
57+
fp = os.path.join(root, f)
58+
all_items.append(fp)
59+
try:
60+
total_size += os.path.getsize(fp)
61+
except OSError:
62+
pass
63+
for d in dirs:
64+
all_items.append(os.path.join(root, d))
65+
66+
all_items.append(dir_path)
67+
return {"size_bytes": total_size, "items": all_items}
68+
169
import platform
270
import os
371
from .models import DiskInfo
@@ -51,4 +119,4 @@ def get_directory_size(dir_path: str) -> dict:
51119
all_items.append(os.path.join(root, d))
52120

53121
all_items.append(dir_path)
54-
return {"size_bytes": total_size, "items": all_items}
122+
return {"size_bytes": total_size, "items": all_items}

0 commit comments

Comments
 (0)