Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- # Filename: is_mounted.py
- # Version: 1.0.0
- # Author: Jeoi Reqi
- """
- This script enables users to retrieve essential data about each mounted filesystem.
- Information Included:
- - Device: The device associated with the mounted filesystem (e.g., C:\, D:\ on Windows, or /dev/sda1, /dev/sdb1 on Unix-like systems).
- - Filesystem Type: The type of filesystem used on the device (e.g., NTFS, ext4, FAT32).
- - Total Size: The total size of the filesystem, indicating the overall storage capacity available.
- - Used Space: The amount of space currently utilized within the filesystem.
- - Available Space: The remaining available space within the filesystem that can be utilized.
- - Usage Percentage: The percentage of space currently utilized in relation to the total capacity.
- Functions:
- 1. main(): Main function to fetch and display mounted filesystems information.
- 2. bytes_to_human_readable(bytes): Converts bytes to a human-readable format.
- Requirements:
- - Python 3.x
- - psutil Module
- Usage:
- - Run the script to display information about mounted filesystems.
- Expected Output:
- --------------------------------------------------------
- Fetching Mounted Filesystems...
- Mounted Filesystems Found:
- :: [Mount Point: C:\] ::
- - Device: C:\
- - Filesystem Type: NTFS
- - Total Size: 474.73 GB
- - Used Space: 124.94 GB
- - Available Space: 349.79 GB
- - Usage Percentage: 26.3%
- :: [Mount Point: D:\] ::
- - Device: D:\
- - Filesystem Type: NTFS
- - Total Size: 931.50 GB
- - Used Space: 165.80 GB
- - Available Space: 765.69 GB
- - Usage Percentage: 17.8%
- --------------------------------------------------------
- Additional Notes:
- - This script requires the psutil module to be installed.
- - You can install it using pip command:
- 'pip install psutil'
- - Ensure that the script has the necessary permissions to access mounted filesystem information.
- - By executing the script, users gain insights into the storage utilization of each mounted filesystem,
- empowering them to make informed decisions regarding resource allocation, storage management & system performance optimization.
- """
- import psutil
- def main():
- """
- Main function to fetch and display mounted filesystems information.
- """
- print("Fetching Mounted Filesystems...\n")
- try:
- mounts = psutil.disk_partitions()
- if not mounts:
- print("No filesystems are mounted.")
- else:
- print("Mounted Filesystems Found:\n")
- for mount in mounts:
- print(f"\t:: [Mount Point: {mount.mountpoint}] ::\n")
- usage = psutil.disk_usage(mount.mountpoint)
- print(f"\t - Device: {mount.device}")
- print(f"\t - Filesystem Type: {mount.fstype}")
- print(f"\t - Total Size: {bytes_to_human_readable(usage.total)}")
- print(f"\t - Used Space: {bytes_to_human_readable(usage.used)}")
- print(f"\t - Available Space: {bytes_to_human_readable(usage.free)}")
- print(f"\t - Usage Percentage: {usage.percent}%")
- print()
- except Exception as e:
- print(f"\n\tError: {e}")
- def bytes_to_human_readable(bytes):
- """
- Convert bytes to a human-readable format (e.g., KB, MB, GB).
- """
- for unit in ["", "KB", "MB", "GB", "TB"]:
- if bytes < 1024:
- return f"{bytes:.2f} {unit}"
- bytes /= 1024
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement