-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils_system.py
More file actions
49 lines (39 loc) · 1.33 KB
/
utils_system.py
File metadata and controls
49 lines (39 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import os
from pathlib import Path
import subprocess
from loguru import logger
import getpass
import getpass
import platform
import win32api
import win32file
def log_runtime_user():
try:
user = getpass.getuser()
except Exception:
user = os.environ.get("USERNAME", "UNKNOWN")
logger.debug(f"Текущий пользователь: {user}")
logger.debug(f"OS user (env USERNAME): {os.environ.get('USERNAME')}")
logger.debug(f"Домашний каталог: {Path.home()}")
logger.debug(f"Платформа: {platform.platform()}")
def log_drives():
logger.debug("=== Логические диски ===")
drives = win32api.GetLogicalDriveStrings().split('\x00')[:-1]
for drive in drives:
drive_type = win32file.GetDriveType(drive)
types = {
win32file.DRIVE_FIXED: "FIXED",
win32file.DRIVE_REMOTE: "REMOTE",
win32file.DRIVE_REMOVABLE: "REMOVABLE",
win32file.DRIVE_CDROM: "CDROM",
win32file.DRIVE_RAMDISK: "RAMDISK",
}
logger.debug(f"{drive} -> {types.get(drive_type, 'UNKNOWN')}")
def log_net_use():
logger.debug("=== Сетевые диски ===")
result = subprocess.run(
["net", "use"],
capture_output=True,
text=True
)
logger.debug(result.stdout)