This repository was archived by the owner on Mar 8, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathDiskSpaceChecker.py
More file actions
42 lines (36 loc) · 1.58 KB
/
DiskSpaceChecker.py
File metadata and controls
42 lines (36 loc) · 1.58 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
import os
import shutil
from AppConfig import AppConfig
class DiskSpaceChecker:
def __init__(self):
"""
Initializes the DiskSpaceChecker class.
Fetches the base path directory from the AppConfig singleton.
"""
self.config = AppConfig()
self.base_path = self.config.base_path
def has_enough_space(self, required_space_gb):
"""
Checks if the base path directory or its drive has enough free space.
:param required_space_gb: The required space in GB as a string (e.g., "3.5").
:return: True if there is enough space, False otherwise.
"""
try:
# Convert required space from string to float
required_space_gb = float(required_space_gb)
# Determine the path to check
path_to_check = self.base_path
if not os.path.exists(self.base_path):
print(f"Base path does not exist. Falling back to the drive: {os.path.splitdrive(self.base_path)[0]}")
path_to_check = os.path.splitdrive(self.base_path)[0] # Use the drive, e.g., "C:\\"
# Get the free space in bytes
total, used, free = shutil.disk_usage(path_to_check)
# Convert free space from bytes to GB
free_space_gb = free / (1024 ** 3)
return free_space_gb >= required_space_gb
except ValueError:
print("Invalid required_space_gb value. Must be a numeric string.")
return False
except Exception as e:
print(f"Error checking disk space: {e}")
return False