/Snoopy

Snooping on your directories

Primary LanguagePythonBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

Snoopy - Your loyal directory snooper 🐢

Install Snoopy

snoopy requires Python 3.10 or newer. For basic use, snoopy does not require any other packages. Only to save directory trees as HTML files and for a nicer print output the rich package is required.

$ pip install git+https://github.com/styfenschaer/Snoopy.git

Test installation

$ snoopy
Welcome to Snoopy - Your loyal directory snooper!

                   / \__
                  (    @\___
                  /         O
                 /   (_____/
                /_____/   U

Snoopy is here to help you sniff out the details in your directories, fetching the information you need with the precision and loyalty of man's best friend. Just give the command, and consider it found!

For help, type: snoopy --help
To start snooping, specify your directory: snoopy /path/to/directory

Version 0.0.2 (2024-02-22)
Copyright (c) 2024 Styfen SchΓ€r
Download-URL https://github.com/styfenschaer/Snoopy

Command line usage

$ snoopy --help

What it can look like

πŸ“ snoopy
 β”‚ πŸ“ examples
 β”‚  β”‚ πŸ“„ example0.py
 β”‚  β”‚ πŸ“„ example1.py
 β”‚  β”‚ πŸ“„ example2.py
 β”‚ πŸ“ snoopy
 β”‚  β”‚ πŸ“„ __init__.py
 β”‚  β”‚ πŸ“„ __main__.py
 β”‚  β”‚ πŸ“„ _version.py
 β”‚  β”‚ πŸ“„ core.py
 β”‚  β”‚ πŸ“„ filtering.py
 β”‚  β”‚ πŸ“„ formatting.py
 β”‚  β”‚ πŸ“„ progress.py
 β”‚  β”‚ πŸ“„ pruning.py
 β”‚  β”‚ πŸ“„ sorting.py
 β”‚  β”‚ πŸ“„ units.py
 β”‚ πŸ“„ .gitignore
 β”‚ πŸ“„ LICENSE
 β”‚ πŸ“„ README.md
 β”‚ πŸ“„ setup.py

Snoop with a script

The minimalist

import snoopy

# build a tree of the working directory
tree = snoopy.snoop()

# define the formatting of the tree
fmt = snoopy.Formatter(tree)

# print the tree
print(fmt)

The enthusiast

from pathlib import Path

import snoopy
from snoopy import filtering, formatting, progress, sorting

# directory to be snooped
snoopy_path = Path(snoopy.__file__).parent.parent

# get a dog called Barky
barky = snoopy.Dog(
    "Barky",
    ignore_folder=filtering.chain(
        filtering.Name(".git"),
        filtering.GitIgnore(snoopy_path / ".gitignore"),
    ),
)

# let it snoop the directory
with progress.elapsed():
    tree = barky.snoop(snoopy_path)

# sort alphabetically 
tree = sorting.alphabetic(tree)

# folders come before files
tree = sorting.by_kind(tree)

# define the formatting of the tree
fmt = snoopy.Formatter(
    tree,
    format_folder=formatting.ItemName(),
    format_file=formatting.ItemName(),
    max_files_display=2,
)

# display the tree nicely
snoopy.display(fmt)

# save the tree to view it in the browser
snoopy.snapshot(fmt, filename=tree.name + ".html")

# let barky know that he did great!
snoopy.praise(barky)
πŸ“ snoopy
 β”‚ πŸ“ examples
 β”‚  β”‚ πŸ“„ example0.py
 β”‚  β”‚ πŸ“„ example1.py
 β”‚  β”‚ βœ‚οΈ  [Folders: 0 | Files: 1 | Errors: 0]
 β”‚ πŸ“ snoopy
 β”‚  β”‚ πŸ“„ __init__.py
 β”‚  β”‚ πŸ“„ __main__.py
 β”‚  β”‚ βœ‚οΈ  [Folders: 0 | Files: 8 | Errors: 0]
 β”‚ πŸ“„ .gitignore
 β”‚ πŸ“„ LICENSE
 β”‚ βœ‚οΈ  [Folders: 0 | Files: 2 | Errors: 0]

How I met your mother my Snoopy

Amidst the chaos of my overflowing Google Drive, I met Snoopy, a clever dog with an uncanny knack for data. With a few sniffs and paws at the keyboard, he quickly unearthed the forgotten dataset cluttering my storage. Thanks to Snoopy, my digital rescuer, I avoided the need to upgrade my storage plan.

$ snoopy --good-boy!
>> Woof woof! 🐢

Snoopy's line to also save you from extra charges:

from pathlib import Path

import snoopy
from snoopy import filtering, formatting, pruning, sorting

this_path = Path(__file__).parent

if __name__ == "__main__":
    barky = snoopy.Dog(ignore_folder=filtering.hidden, verbosity=1)

    tree = barky.snoop(this_path)

    tree = sorting.by_size(tree)
    tree = pruning.by_size(tree, "<1.0 GB")

    fmt = snoopy.Formatter(
        tree,
        format_folder=formatting.ItemSize(unit="GB"),
        format_file=formatting.ItemSize(unit="GB"),
    )

    snoopy.display(fmt)
    snoopy.snapshot(fmt, filename=tree.name + ".html", silent=False)

(text generated by AI)

Notes on Snoopy

  1. Snoopy is an eager dog, which can sometimes be slow. But Snoopy has to be like this because he reports folder sizes, among other things.
  2. Documentation is currently missing. May your IDE be with you.
  3. This repository is 65 % useful and 35 % gimmicky.