Skip to content

Commit 58904b9

Browse files
committed
Initial Commit
0 parents  commit 58904b9

File tree

7 files changed

+158
-0
lines changed

7 files changed

+158
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.venv
2+
__pycache__
3+
.DS_Store

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Quentin
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Node Modules Visualizer
2+
3+
![Alt text](docs/visualizer.jpg?raw=true "Node modules Visualizer")
4+
5+
## What we need to do to make it work
6+
7+
## Requirements :
8+
Have python [3.X] installed.
9+
10+
11+
## Install pip requirements
12+
> pip install -r requirements.txt
13+
14+
## Run the visualizer
15+
> python3 visualizer.py [PATH]
16+
17+
## Compatibility
18+
19+
| Operating System | Version needed |
20+
| :---: | :---: |
21+
| Windows 10/11 | 1.0 |
22+
| MacOS / Linux | 1.0 |
23+
24+
## Copyrights
25+
26+
```text
27+
Copyrights EQ-0 - 2023, All Rights Reserved
28+
29+
__ ___________________ _______ __
30+
/ / \_ _____/\_____ \ \ _ \ \ \
31+
/ / | __)_ / / \ \ ______ / /_\ \ \ \
32+
\ \ | \/ \_/. \ /_____/ \ \_/ \ / /
33+
\_\ /_______ /\_____\ \_/ \_____ / /_/
34+
\/ \__> \/
35+
```
36+

docs/visualizer.jpg

103 KB
Loading

requirements.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
markdown-it-py==3.0.0
2+
mdurl==0.1.2
3+
Pygments==2.15.1
4+
rich==13.4.2

scan.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import os
2+
import time
3+
4+
from rich.progress import (
5+
BarColumn,
6+
MofNCompleteColumn,
7+
Progress,
8+
TextColumn,
9+
TimeElapsedColumn,
10+
TimeRemainingColumn,
11+
)
12+
13+
class Scan:
14+
def __init__(self, path="."):
15+
self.path = path
16+
self.size = 0
17+
self.files = 0
18+
self.folders = 0
19+
self.results = []
20+
21+
def convert_size(self, size_in_bytes):
22+
units = ["B", "KB", "MB", "GB", "TB"]
23+
unit_index = 0
24+
25+
while size_in_bytes >= 1024 and unit_index < len(units) - 1:
26+
size_in_bytes /= 1024
27+
unit_index += 1
28+
29+
return f"{size_in_bytes:.2f} {units[unit_index]}"
30+
31+
def scan(self, target="", console=None):
32+
console.print(f"[bold green]Indexing files/folders {self.path} for {target}...[/bold green]")
33+
directories = list(os.walk(self.path))
34+
with Progress() as progress:
35+
task = progress.add_task("[cyan]Scanning directories...", total=len(directories), console=console)
36+
37+
for root, dirs, files in directories:
38+
for dir in dirs:
39+
if dir == target:
40+
dir_path = os.path.join(root, dir)
41+
dir_size = os.path.getsize(dir_path)
42+
converted_size = self.convert_size(dir_size)
43+
44+
self.results.append((root, dir_path, converted_size))
45+
self.size += dir_size
46+
self.folders += 1
47+
continue
48+
time.sleep(0.00001)
49+
progress.advance(task) # Update the progress bar
50+
51+
return self
52+
53+
def get_size(self):
54+
return self.size
55+
56+
def get_files(self):
57+
return self.files
58+
59+
def get_folders(self):
60+
return self.folders
61+
62+
def get_results(self):
63+
return self.results
64+
65+
def get_path(self):
66+
return self.path

visualizer.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import sys
2+
from rich.console import Console
3+
from rich.table import Table
4+
from rich.progress import track
5+
from time import sleep
6+
7+
from scan import Scan
8+
9+
PATH = sys.argv[1] if len(sys.argv) > 1 else "." # Get the path from the command line arguments
10+
CONSOLE = Console() # Create a console
11+
12+
scanner = Scan(PATH) # Scan the current directory
13+
14+
scanner.scan(target="node_modules", console=CONSOLE) # Scan the directory
15+
16+
table = Table(title="Node Visualizer") # Create a table with a title
17+
18+
table.add_column("Project Name", justify="center", style="cyan")
19+
table.add_column("Path", justify="center", style="magenta")
20+
table.add_column("Size", justify="center", style="green")
21+
22+
for result in scanner.results:
23+
table.add_row(result[0], result[1], result[2]) # Add a row to the table
24+
25+
CONSOLE.print(table, justify="center") # Print the tables
26+
27+
CONSOLE.print(f"Possible reclaimed size on disk 💾 : [bold green]{scanner.convert_size(scanner.size)}", justify="center") # Print a message
28+
CONSOLE.print(f"Total node_modules folders 📁 : [bold green]{scanner.folders}", justify="center") # Print a message

0 commit comments

Comments
 (0)