-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enjoy this somewhat unnecessary, yet "fun-for-the-whole-family" DiskSpaceAnalyzer tool. 😄
- Loading branch information
Showing
6 changed files
with
218 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
MIT License | ||
|
||
Copyright (c) 2023 idlebg | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,83 @@ | ||
# HowMuch | ||
Say hello to HowMuch: Checking checkpoint wasted space since... well, now! 😄 | ||
|
||
# HowMuch | ||
![60% Works](https://img.shields.io/badge/60%25%20of%20the%20Time-It%20Works%20Every%20Time-green) | ||
|
||
|
||
![License](https://img.shields.io/github/license/1e-2/HowMuch) | ||
![Python Version](https://img.shields.io/badge/python-3.7+-blue.svg) | ||
![Repo Size](https://img.shields.io/github/repo-size/1e-2/HowMuch) | ||
![Last Commit](https://img.shields.io/github/last-commit/1e-2/HowMuch) | ||
![Open Issues](https://img.shields.io/github/issues-raw/1e-2/HowMuch) | ||
![Closed Issues](https://img.shields.io/github/issues-closed-raw/1e-2/HowMuch) | ||
![Pull Requests](https://img.shields.io/github/issues-pr/1e-2/HowMuch) | ||
![Stars](https://img.shields.io/github/stars/1e-2/HowMuch) | ||
|
||
|
||
**Have you ever asked yourself, "How much space have I wasted on *.ckpt and *.safetensors checkpoints?"** 🤔 | ||
Say hello to HowMuch: Checking checkpoint wasted space since... well, now! 😄 Enjoy this somewhat unnecessary, yet "fun-for-the-whole-family" DiskSpaceAnalyzer tool. 😄 | ||
## Overview | ||
|
||
`HowMuch` is a Python tool designed to scan your drives (or a specified directory) and report on the total space used by files with specific extensions, mainly `.ckpt` and `.safetensors`. | ||
|
||
It outputs: | ||
- The total storage capacity of each scanned drive or directory. | ||
- The space occupied by `.ckpt` and `.safetensors` files. | ||
- The free space available. | ||
- A neat bar chart visualizing the above data. | ||
|
||
## Installation | ||
|
||
### From PyPI | ||
|
||
You can easily install `HowMuch` via pip: | ||
|
||
```bash | ||
pip install howmuch | ||
``` | ||
|
||
### From Source | ||
|
||
1. Clone the repository: | ||
|
||
```bash | ||
git clone https://github.com/1e-2/HowMuch.git | ||
``` | ||
|
||
2. Navigate to the cloned directory and install: | ||
|
||
```bash | ||
cd HowMuch | ||
pip install . | ||
``` | ||
|
||
## Usage | ||
|
||
|
||
Run the tool without any arguments to scan all drives: | ||
|
||
```bash | ||
howmuch | ||
``` | ||
|
||
Or, specify a particular directory or drive to scan: | ||
|
||
```bash | ||
howmuch --scan C: | ||
``` | ||
|
||
The results will be displayed in the console, saved to a text file (`HowMuch_output.txt`), and visualized in a bar chart (`HowMuch_chart.png`). | ||
|
||
## Contributing | ||
|
||
Feel free to fork the repository, make changes, and open a pull request. All contributions are welcome! | ||
|
||
## License | ||
|
||
This project is licensed under the MIT License. See [LICENSE](https://github.com/1e-2/HowMuch/blob/main/LICENSE) for details. | ||
|
||
## Author | ||
|
||
- **idlebg** - [GitHub](https://github.com/idlebg) | ||
|
||
For any additional questions or comments, please [open an issue](https://github.com/1e-2/HowMuch/issues/new). | ||
aaaa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import psutil | ||
import os | ||
import argparse | ||
from tqdm import tqdm | ||
import matplotlib.pyplot as plt | ||
|
||
def get_size(bytes, suffix="B"): | ||
"""Convert bytes to human-readable formats (e.g., KB, MB, GB, etc.).""" | ||
factor = 1024 | ||
for unit in ["", "K", "M", "G", "T", "P"]: | ||
if bytes < factor: | ||
return f"{bytes:.2f} {unit}{suffix}" | ||
bytes /= factor | ||
|
||
def get_file_size_for_extensions(drive, extensions): | ||
"""Get the total size of files with specific extensions in a drive.""" | ||
total_size = 0 | ||
for dirpath, dirnames, filenames in tqdm(os.walk(drive), desc=f"Scanning {drive}", unit="dir"): | ||
for file in filenames: | ||
if any(file.endswith(ext) for ext in extensions): | ||
total_size += os.path.getsize(os.path.join(dirpath, file)) | ||
return total_size | ||
|
||
parser = argparse.ArgumentParser(description="Analyze disk space used by specific file extensions.") | ||
parser.add_argument("--scan", metavar="PATH", type=str, help="Specify a folder or drive to scan. If not provided, all drives will be scanned.") | ||
args = parser.parse_args() | ||
|
||
if args.scan: | ||
partitions = [type('', (), {"mountpoint": args.scan})()] | ||
else: | ||
partitions = psutil.disk_partitions() | ||
|
||
total_space = 0 | ||
total_free_space = 0 | ||
total_ckptsafetensors_size = 0 | ||
|
||
log_output = [] | ||
|
||
for partition in partitions: | ||
usage = psutil.disk_usage(partition.mountpoint) | ||
ckptsafetensors_size = get_file_size_for_extensions(partition.mountpoint, [".ckpt", ".safetensors"]) | ||
drive_name = partition.device if hasattr(partition, 'device') else args.scan | ||
log_output.append(f"\nDrive {drive_name}:") | ||
log_output.append(f" Total Space: {get_size(usage.total)}") | ||
log_output.append(f" Space taken by .ckpt and .safetensors files: {get_size(ckptsafetensors_size)}") | ||
log_output.append(f" Free Space: {get_size(usage.free)}") | ||
total_space += usage.total | ||
total_free_space += usage.free | ||
total_ckptsafetensors_size += ckptsafetensors_size | ||
|
||
log_output.append("\nTOTAL space taken by all drives: {}".format(get_size(total_space))) | ||
log_output.append("TOTAL free space across all drives: {}".format(get_size(total_free_space))) | ||
log_output.append("TOTAL space taken by .ckpt and .safetensors files: {}".format(get_size(total_ckptsafetensors_size))) | ||
log_output.append("\nNote: The sizes may not match exactly with Windows File Explorer due to system reserved space.") | ||
|
||
# Print and save to txt | ||
with open('HowMuch_output.txt', 'w') as f: | ||
for line in log_output: | ||
print(line) | ||
f.write(line + '\n') | ||
|
||
# Generate Chart | ||
drives = [partition.device if hasattr(partition, 'device') else args.scan for partition in partitions] | ||
total_spaces = [psutil.disk_usage(partition.mountpoint).total for partition in partitions] | ||
ckpt_safetensor_sizes = [get_file_size_for_extensions(partition.mountpoint, [".ckpt", ".safetensors"]) for partition in partitions] | ||
free_spaces = [psutil.disk_usage(partition.mountpoint).free for partition in partitions] | ||
|
||
bar_width = 0.25 | ||
r1 = range(len(drives)) | ||
r2 = [x + bar_width for x in r1] | ||
r3 = [x + bar_width for x in r2] | ||
|
||
# Adjusted colors here: | ||
plt.bar(r1, total_spaces, color='pink', width=bar_width, edgecolor='grey', label='Total Space') | ||
plt.bar(r2, ckpt_safetensor_sizes, color='purple', width=bar_width, edgecolor='grey', label='.ckpt & .safetensors Size') | ||
plt.bar(r3, free_spaces, color='g', width=bar_width, edgecolor='grey', label='Free Space') | ||
|
||
plt.xlabel('Drives', fontweight='bold') | ||
plt.xticks([r + bar_width for r in range(len(drives))], drives) | ||
plt.legend() | ||
plt.savefig('HowMuch_chart.png') | ||
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Init file for howmuch package |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
psutil | ||
tqdm | ||
matplotlib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
from setuptools import setup, find_packages | ||
|
||
with open("README.md", "r") as fh: | ||
long_description = fh.read() | ||
|
||
setup( | ||
name="howmuch", | ||
version="0.1", | ||
packages=find_packages(), | ||
install_requires=[ | ||
'psutil', | ||
'tqdm', | ||
'matplotlib' | ||
], | ||
author="idlebg", | ||
author_email="[email protected]", | ||
description="A simple disk space analyzer for *.ckpt & *.safetensors file extensions", | ||
long_description=long_description, | ||
long_description_content_type="text/markdown", | ||
url="https://github.com/1e-2/HowMuch", | ||
classifiers=[ | ||
"Programming Language :: Python :: 3", | ||
"License :: OSI Approved :: MIT License", | ||
"Operating System :: OS Independent", | ||
], | ||
) |