Skip to content

Commit e7d0b79

Browse files
add shebang to Python scripts, update requirements and make new setup wizard script
1 parent 8059a2d commit e7d0b79

7 files changed

Lines changed: 322 additions & 61 deletions

File tree

.gitignore

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
1-
# All sorts of virtual environments
2-
*env*
1+
# Python Bytecode
2+
__pycache__/
3+
*.py[cod]
34

4-
# Output from indexation
5-
index*.json
6-
*.json
7-
8-
# Output from analysis
9-
*.pdf
10-
*.jpg
11-
*.png
5+
# Environments
6+
venv/
7+
.venv/
8+
env/
9+
.env/
10+
ENV/
11+
.ENV/
1212

13-
# User Configuration File
13+
# User-specific Config
1414
config.ini
1515

16-
# Log files
17-
*error*
18-
*.log
16+
# Application Outputs
17+
*.json
18+
*.pdf
19+
*.log
20+
21+
# OS-specific
22+
.DS_Store
23+
Thumbs.db

README.md

Lines changed: 64 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Peters-Disk-Utils (v1.0.0-alpha)
1+
# Peters-Disk-Utils (v1.0.0-stable)
22

33
A lightweight, cross-platform CLI suite for indexing, visualizing, and navigating disk storage. Built for developers and power users who need to analyze large directory structures and explore them offline.
44

@@ -10,54 +10,43 @@ A lightweight, cross-platform CLI suite for indexing, visualizing, and navigatin
1010
- **OS-Aware Exclusions**: Pre-configured to skip virtual filesystems (Linux) and protected system folders (Windows).
1111
- **Centralized Config**: Control targets, output names, and verbosity via _config.ini_.
1212
- **Silent Logging**: Comprehensive error tracking using the `logging` module to keep your terminal clean.
13+
- **Cross-Platform**: Works seamlessly on Windows and Linux with the same codebase.
14+
- **Global Usage**: Run the analyzer and navigator from any directory, with outputs saved to the current working directory.
1315

1416
## 🚀 Quick Start
1517

16-
### 1. Prerequisites
18+
### 1. **Clone the Repository**
1719

18-
Ensure you have Python 3.10 or higher installed. Install the required dependencies:
20+
```Bash
21+
git clone https://github.com/SaturniNovaDev/peters-disk-utils
22+
```
23+
24+
### 2. **Run the Installer**
1925

20-
```bash
21-
pip install matplotlib colorama
26+
On Linux:
27+
28+
```Bash
29+
cd peters-disk-utils
30+
chmod +x setup.sh
31+
./setup.sh
32+
# Follow the instructions in the wizard
2233
```
2334

24-
### 2. Configuration
25-
26-
The suite requires a _config.ini_ file in the root directory.
27-
28-
Use this template and rename it to _config.ini_ in order to configure the program with the best settings.
29-
30-
```ini
31-
; -- Default configuration template --
32-
; Rename to 'config.ini' to start using this configuration
33-
34-
[GENERAL]
35-
; Set to True for full logs, False for single-line status
36-
Verbose = False
37-
; How many errors to show in the terminal summary
38-
ErrorLimit = 20
39-
; Whether to print the error summary at the end of the scan
40-
ShowSummary = True
41-
42-
[PATHS]
43-
; Default names for your outputs
44-
JsonOutput = disk-index.json
45-
ChartOutput = analysis.pdf
46-
; Log file for permission errors
47-
LogFile = nls-errors.log
48-
49-
; Default directories to scan if no --target param is provided
50-
[DEFAULT_TARGETS]
51-
Windows = C:/Users
52-
Linux = /home
53-
54-
[EXCLUDE]
55-
; Linux-specific virtual/system files
56-
LinuxDirs = /proc, /sys, /dev, /run, /snap, /var/lib/lxd
57-
; Windows-specific system files that often cause permission errors
58-
WindowsDirs = C:/System Volume Information, C:/$Recycle.Bin, C:/Windows/CSC
35+
On Windows:
36+
37+
```PowerShell
38+
cd peters-disk-utils
39+
.\setup.bat
40+
# Follow the instructions in the wizard
5941
```
6042

43+
The installer will guide you through setting up the necessary Python environment, installing dependencies, and configuring your default targets, as well as optionally adding the tools to your system for global access.
44+
This works by creating scripts in your system PATH that point to the main Python files, allowing you to run `disk-nls` and `disk-nav` from any terminal.
45+
46+
Keep in mind that **erasing the files in the repository will break this functionality.** I'm working on a future update which will include an uninstaller script to clean up these PATH entries if needed.
47+
48+
If you do, however, want to remove the tools manually, simply delete the `disk-nls` and `disk-nav` scripts from your system PATH (e.g., `/usr/local/bin/` on Linux or the PATH environment variable on Windows).
49+
6150
## 📖 Usage Guide
6251

6352
### Step 1: Indexing _disk-nls.py_
@@ -66,11 +55,17 @@ Run the analyzer to create a JSON snapshot of your drive and a visual PDF chart.
6655

6756
```Bash
6857
# Uses the default target from config.ini
69-
python disk-nls.py
58+
python3 disk-nls.py
7059

7160
# Manually specify a target and enable verbose logging
72-
python disk-nls.py --target /var/www --verbose
61+
python3 disk-nls.py --target /var/www --verbose
62+
63+
```
7364

65+
Or, if you have set up the global command:
66+
67+
```Bash
68+
disk-nls # Optionally specify a target with --target and enable verbose logging with --verbose
7469
```
7570

7671
### Step 2: Navigating _disk-nav.py_
@@ -79,7 +74,13 @@ Explore the generated index interactively using our built-in CLI tool:
7974

8075
```Bash
8176
# Loads the default JsonOutput from config.ini
82-
python disk-nav.py
77+
python3 ./disk-nav.py
78+
```
79+
80+
Or, if you have set up the global command:
81+
82+
```Bash
83+
disk-nav # Optionally specify a source JSON snapshot with --source
8384
```
8485

8586
#### Navigator Commands
@@ -91,7 +92,24 @@ python disk-nav.py
9192
- help: Show available commands.
9293
- exit: Close the navigator.
9394

94-
## ⚠️ Known Issues (Alpha)
95+
## Notes
96+
97+
1. System directories and virtual filesystems are automatically excluded based on the OS, but you can customize this in the _config.ini_ file under the `[EXCLUSIONS]` section. If you get permission errors during indexing, run the program as administrator/root or adjust the exclusions to skip problematic directories. **NOTE THAT THIS IS VERY INCONVENIENT**, as the next time you want to analyze the disk, or even access the log, chart or index files, you will have to run the program with elevated permissions again. Run as an administrator/root only if you _NEED_ to analyze protected system folders or virtual filesystems, and be cautious when doing so, as it can lead to unintended consequences if you modify or delete important files.
98+
99+
```Bash
100+
sudo disk-nls # Reads config.ini and runs with elevated permissions on Linux
101+
# Or:
102+
sudo python3 disk-nls.py --target / # Run with elevated permissions on Linux
103+
# Or:
104+
python3 disk-nls.py --target /home # Skip non-user directories on Linux
105+
```
106+
107+
## ⚠️ Known Issues (Stable)
95108

96-
1. Some system-level folders remain inaccessible without Admin/Sudo privileges. Check _nls-errors.log_ for details when indexing system directories.
97-
2. Very large disk indexes (multi-terabyte) may consume significant RAM during JSON generation. While we work on a solution for this, you might want to avoid indexing non-user directories.
109+
1. The Ring Chart may not display correctly if there are too many small files or directories, as they can clutter the visualization.
110+
2. The navigator does not currently support searching or filtering within the index, which can make it difficult to find specific items in large datasets. Future updates will include search functionality.
111+
3. The tool does not currently handle symbolic links or shortcuts, which may lead to inaccurate size calculations or navigation issues.
112+
4. The installer does not currently check for existing PATH entries before adding new ones, which could lead to conflicts if the tools are already installed or if there are naming collisions. I recommend reviewing your PATH after installation and removing any duplicates if necessary.
113+
5. The tool does not currently support incremental updates to the index, meaning that you will need to re-run the analyzer to reflect any changes in the filesystem.
114+
6. The navigation REPL is still very raw and prone to styling errors.
115+
7. The tool is known to log some directories with incorrect sizes due to permission issues or special filesystem features. In some occasions, these might be reflected in the index with a size larger than the disk's own capacity. This is a known issue that I am working on fixing in a future update.

disk-nav.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env python3
12
import os
23
import json
34
import argparse

disk-nls.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env python3
12
import os
23
import json
34
import argparse
@@ -140,6 +141,9 @@ def generate_visuals(index_data, output_file):
140141
target = os.path.abspath(args.target)
141142
if not os.path.exists(target):
142143
print(f"{Fore.RED}Error: Target path '{target}' does not exist.")
144+
print(
145+
f"{Fore.YELLOW}Please check your --target argument or the [DEFAULT_TARGETS] in config.ini."
146+
)
143147
exit(1)
144148

145149
print(f"{Fore.YELLOW}Target identified: {Fore.WHITE}{target}")
@@ -172,6 +176,13 @@ def generate_visuals(index_data, output_file):
172176
f"{Fore.WHITE}Duration: {Fore.CYAN}{final_output['scan_duration_seconds']}s"
173177
)
174178
print(f"{Fore.WHITE}Log File: {Fore.CYAN}{config.get('PATHS', 'LogFile')}")
179+
if final_output["scan_duration_seconds"] > 60:
180+
print(
181+
f"{Fore.YELLOW}Note: Long scan times may indicate a very large target or performance issues. Consider excluding more directories or running with verbose mode for detailed logging."
182+
)
183+
print(
184+
f"{Fore.BLUE}Tip: If you get permission errors during scans, consider skipping system directories or running the tool with elevated permissions (e.g., as administrator or with sudo)."
185+
)
175186

176187
generate_visuals(full_structure, args.output)
177188
print(f"{Fore.GREEN}Index and chart saved successfully.")

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
matplotlib
2-
tqdm
32
colorama

setup.bat

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
@echo off
2+
setlocal enabledelayedexpansion
3+
4+
echo --- Peter's Disk Utils - Windows Setup ---
5+
6+
:: 1. Choose Setup Mode
7+
set /p choice="Use recommended defaults? (y/n): "
8+
9+
if /i "%choice%"=="y" (
10+
echo Creating config.ini with Windows defaults...
11+
copy config.template config.ini
12+
goto VENV
13+
)
14+
15+
echo --- Custom Configuration ---
16+
17+
set /p VERBOSE="Verbose Mode (True/False) [False]: "
18+
if "!VERBOSE!"=="" set VERBOSE=False
19+
20+
set /p ELIMIT="Error Limit [20]: "
21+
if "!ELIMIT!"=="" set ELIMIT=20
22+
23+
set /p SUMMARY="Show Summary at end of scan? (True/False) [True]: "
24+
if "!SUMMARY!"=="" set SUMMARY=True
25+
26+
set /p TARGET="Default Windows Scan Target [C:/Users]: "
27+
if "!TARGET!"=="" set TARGET=C:/Users
28+
29+
set /p JSON_OUT="Output JSON Name [disk-index.json]: "
30+
if "!JSON_OUT!"=="" set JSON_OUT=disk-index.json
31+
32+
set /p CHART_OUT="Output Chart Name [analysis.pdf]: "
33+
if "!CHART_OUT!"=="" set CHART_OUT=analysis.pdf
34+
35+
set /p LOG_FILE="Output Error Log [nls-errors.log]: "
36+
if "!LOG_FILE!"=="" set LOG_FILE=nls-errors.log
37+
38+
set /p WIN_DIRS="Ignore which directories? [C:/System Volume Information, C:/$Recycle.Bin]: "
39+
if "!WIN_DIRS!"=="" set WIN_DIRS=C:/System Volume Information, C:/$Recycle.Bin
40+
41+
:: Build the config file
42+
echo [GENERAL] > config.ini
43+
echo Verbose = !VERBOSE! >> config.ini
44+
echo ErrorLimit = !ELIMIT! >> config.ini
45+
echo ShowSummary = !SUMMARY! >> config.ini
46+
echo. >> config.ini
47+
echo [PATHS] >> config.ini
48+
echo JsonOutput = !JSON_OUT! >> config.ini
49+
echo ChartOutput = !CHART_OUT! >> config.ini
50+
echo LogFile = !LOG_FILE! >> config.ini
51+
echo. >> config.ini
52+
echo [DEFAULT_TARGETS] >> config.ini
53+
echo Windows = !TARGET! >> config.ini
54+
echo Linux = /home >> config.ini
55+
echo. >> config.ini
56+
echo [EXCLUDE] >> config.ini
57+
echo LinuxDirs = /proc, /sys, /dev, /run, /snap >> config.ini
58+
echo WindowsDirs = !WIN_DIRS! >> config.ini
59+
60+
:VENV
61+
echo.
62+
echo Setting up Virtual Environment...
63+
python -m venv .venv
64+
call .venv\Scripts\activate
65+
python -m pip install --upgrade pip
66+
pip install -r requirements.txt
67+
68+
:: 2. Create Global Commands
69+
echo.
70+
set /p global_choice="Register 'disk-nls' and 'disk-nav' as global commands? (y/n): "
71+
if /i "%global_choice%"=="y" (
72+
set "INSTALL_DIR=%CD%"
73+
set "VENV_PY=%CD%\.venv\Scripts\python.exe"
74+
75+
:: Create disk-nls.bat shim
76+
echo @echo off > disk-nls.bat
77+
echo "!VENV_PY!" "!INSTALL_DIR!\disk-nls.py" %%* >> disk-nls.bat
78+
79+
:: Create disk-nav.bat shim
80+
echo @echo off > disk-nav.bat
81+
echo "!VENV_PY!" "!INSTALL_DIR!\disk-nav.py" %%* >> disk-nav.bat
82+
83+
echo.
84+
echo To use these commands from any folder, you must add this directory to your PATH:
85+
echo !INSTALL_DIR!
86+
echo.
87+
echo Would you like me to try adding it to your User PATH automatically?
88+
set /p path_choice="(y/n): "
89+
if /i "!path_choice!"=="y" (
90+
:: Add to path using setx (takes effect in NEW terminal windows)
91+
for /f "tokens=2*" %%A in ('reg query "HKCU\Environment" /v Path') do set "oldpath=%%B"
92+
echo !oldpath! | findstr /i "!INSTALL_DIR!" >nul
93+
if errorlevel 1 (
94+
setx PATH "!oldpath!;!INSTALL_DIR!"
95+
echo Success! Please restart your terminal for global commands to work.
96+
) else (
97+
echo Directory already in PATH.
98+
)
99+
)
100+
)
101+
102+
echo.
103+
echo Setup Complete!
104+
pause

0 commit comments

Comments
 (0)