dirshot 0.1.3__py3-none-any.whl → 0.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dirshot/__init__.py +14 -13
- dirshot/dirshot.py +955 -989
- dirshot/reconstruct.py +110 -0
- dirshot-0.3.0.dist-info/METADATA +197 -0
- dirshot-0.3.0.dist-info/RECORD +7 -0
- {dirshot-0.1.3.dist-info → dirshot-0.3.0.dist-info}/WHEEL +1 -1
- dirshot/examples.py +0 -65
- dirshot-0.1.3.dist-info/METADATA +0 -110
- dirshot-0.1.3.dist-info/RECORD +0 -7
- {dirshot-0.1.3.dist-info → dirshot-0.3.0.dist-info}/top_level.txt +0 -0
dirshot/reconstruct.py
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import re
|
|
3
|
+
|
|
4
|
+
# --- Configuration ---
|
|
5
|
+
# You can edit these variables to match your needs.
|
|
6
|
+
|
|
7
|
+
# 1. The name of the file containing the project structure and content.
|
|
8
|
+
INPUT_FILENAME = 'repo.txt'
|
|
9
|
+
|
|
10
|
+
# 2. The name of the directory where the project will be created.
|
|
11
|
+
OUTPUT_DIRECTORY = 'studio'
|
|
12
|
+
# --- End of Configuration ---
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def reconstruct_and_populate_project(file_path, root_dir):
|
|
16
|
+
"""
|
|
17
|
+
Parses a formatted text file to reconstruct a project's directory
|
|
18
|
+
structure and correctly populates all files with their content.
|
|
19
|
+
|
|
20
|
+
Args:
|
|
21
|
+
file_path (str): The path to the input text file (e.g., 'repo.txt').
|
|
22
|
+
root_dir (str): The name of the root directory for the reconstructed project.
|
|
23
|
+
"""
|
|
24
|
+
print(f"Starting project reconstruction from '{file_path}'...")
|
|
25
|
+
print(f"Output will be saved in the '{root_dir}' directory.")
|
|
26
|
+
|
|
27
|
+
try:
|
|
28
|
+
with open(file_path, 'r', encoding='utf-8') as f:
|
|
29
|
+
content = f.read()
|
|
30
|
+
except FileNotFoundError:
|
|
31
|
+
print(f"\nERROR: The input file '{file_path}' was not found.")
|
|
32
|
+
print("Please make sure the script is in the same directory as the input file.")
|
|
33
|
+
return
|
|
34
|
+
except Exception as e:
|
|
35
|
+
print(f"\nAn error occurred while reading the file: {e}")
|
|
36
|
+
return
|
|
37
|
+
|
|
38
|
+
# A line of 80 hyphens is the separator. We split the entire document by it.
|
|
39
|
+
separator = '--------------------------------------------------------------------------------'
|
|
40
|
+
# The split operation will result in a list where file paths and contents alternate.
|
|
41
|
+
sections = content.split(separator)
|
|
42
|
+
|
|
43
|
+
# The very first section is the visual tree, which we don't need.
|
|
44
|
+
# We start processing from the first "FILE:" header.
|
|
45
|
+
# We skip any empty sections that might result from splitting.
|
|
46
|
+
file_chunks = [s.strip() for s in sections if s.strip()]
|
|
47
|
+
|
|
48
|
+
# Create a dictionary to hold {'filepath': 'content'}
|
|
49
|
+
file_data = {}
|
|
50
|
+
|
|
51
|
+
# The new logic iterates through the chunks. When it finds a file header,
|
|
52
|
+
# it assumes the *next* chunk is the content for that file.
|
|
53
|
+
i = 0
|
|
54
|
+
while i < len(file_chunks):
|
|
55
|
+
chunk = file_chunks[i]
|
|
56
|
+
if chunk.startswith('FILE:'):
|
|
57
|
+
# This chunk is a file header. Extract the path.
|
|
58
|
+
# It might have other text like the tree, so we find the 'FILE:' line specifically.
|
|
59
|
+
path_line = [line for line in chunk.splitlines() if line.startswith('FILE:')][0]
|
|
60
|
+
relative_path = path_line[5:].strip()
|
|
61
|
+
|
|
62
|
+
# The very next chunk in the list is the content for this file.
|
|
63
|
+
if i + 1 < len(file_chunks):
|
|
64
|
+
content = file_chunks[i + 1]
|
|
65
|
+
file_data[relative_path] = content
|
|
66
|
+
# We've processed the header and the content, so we can skip the next item.
|
|
67
|
+
i += 2
|
|
68
|
+
else:
|
|
69
|
+
# Found a file header without any content after it (end of file).
|
|
70
|
+
file_data[relative_path] = '' # Create an empty file
|
|
71
|
+
i += 1
|
|
72
|
+
else:
|
|
73
|
+
# This chunk is not a file header, so we skip it (e.g., the initial tree view).
|
|
74
|
+
i += 1
|
|
75
|
+
|
|
76
|
+
if not file_data:
|
|
77
|
+
print("\nERROR: Could not find any valid 'FILE:' sections. Nothing to create.")
|
|
78
|
+
return
|
|
79
|
+
|
|
80
|
+
# Create the main output directory if it doesn't already exist.
|
|
81
|
+
if not os.path.exists(root_dir):
|
|
82
|
+
print(f"\nCreating root directory: '{root_dir}'")
|
|
83
|
+
os.makedirs(root_dir)
|
|
84
|
+
else:
|
|
85
|
+
print(f"\nOutput directory '{root_dir}' already exists. Files may be overwritten.")
|
|
86
|
+
|
|
87
|
+
# Now, create the directories and write the populated files.
|
|
88
|
+
for relative_path, file_content in file_data.items():
|
|
89
|
+
full_path = os.path.join(root_dir, relative_path)
|
|
90
|
+
parent_dir = os.path.dirname(full_path)
|
|
91
|
+
|
|
92
|
+
# Ensure the directory for the file exists (e.g., 'src/components/ui/').
|
|
93
|
+
if parent_dir:
|
|
94
|
+
os.makedirs(parent_dir, exist_ok=True)
|
|
95
|
+
|
|
96
|
+
# Write the captured content into the file.
|
|
97
|
+
try:
|
|
98
|
+
with open(full_path, 'w', encoding='utf-8') as f:
|
|
99
|
+
f.write(file_content)
|
|
100
|
+
print(f" - Created and populated: {full_path}")
|
|
101
|
+
except Exception as e:
|
|
102
|
+
print(f" - FAILED to create file {full_path}: {e}")
|
|
103
|
+
|
|
104
|
+
print(f"\nProject reconstruction complete!")
|
|
105
|
+
print(f"Check the '{root_dir}' directory to see your populated project.")
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
# --- Script Execution ---
|
|
109
|
+
if __name__ == '__main__':
|
|
110
|
+
reconstruct_and_populate_project(file_path=INPUT_FILENAME, root_dir=OUTPUT_DIRECTORY)
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dirshot
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: A flexible, high-performance utility for creating project snapshots and searching files with a rich terminal UI.
|
|
5
|
+
Author-email: init-helpful <init.helpful@gmail.com>
|
|
6
|
+
Project-URL: Homepage, https://github.com/init-helpful/dirshot
|
|
7
|
+
Project-URL: Bug Tracker, https://github.com/init-helpful/dirshot/issues
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Topic :: Terminals
|
|
12
|
+
Classifier: Topic :: Utilities
|
|
13
|
+
Requires-Python: >=3.7
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
Provides-Extra: rich
|
|
16
|
+
Requires-Dist: rich>=13.0.0; extra == "rich"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
# dirshot 📸
|
|
20
|
+
|
|
21
|
+
[](https://badge.fury.io/py/dirshot)
|
|
22
|
+
[](https://opensource.org/licenses/MIT)
|
|
23
|
+

|
|
24
|
+
|
|
25
|
+
A flexible, high-performance utility for creating project snapshots and searching files, complete with rich visual feedback in your terminal.
|
|
26
|
+
|
|
27
|
+
`dirshot` scans your project directories to either create a single, comprehensive text file "snapshot" of your codebase or to search for specific keywords within your files. It's perfect for feeding project context to Large Language Models (LLMs), archiving codebases, conducting security audits, or simply navigating complex projects.
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## ✨ Key Features
|
|
32
|
+
|
|
33
|
+
- **Rich Terminal Visuals**: Powered by `rich`, `dirshot` provides a beautiful and informative live view of its progress, including spinners, progress bars, summary tables, and thread activity. It falls back to a simple text-based progress indicator if `rich` is not installed.
|
|
34
|
+
- **Powerful Presets**: Comes with an extensive list of `LanguagePreset` and `IgnorePreset` enums to instantly configure scans for dozens of languages, frameworks, and tools (Python, JavaScript, Go, Rust, Terraform, Docker, etc.).
|
|
35
|
+
- **Dual Modes**:
|
|
36
|
+
- **Snapshot Mode**: Collate all project files matching your criteria into a single, easy-to-share output file.
|
|
37
|
+
- **Search Mode**: Hunt for specific keywords in filenames or, optionally, within file contents.
|
|
38
|
+
- **Highly Customizable**: Fine-tune scans by combining presets with manual lists of file extensions, ignore paths, and specific file names to include or exclude.
|
|
39
|
+
- **Concurrent & Fast**: Uses a `ThreadPoolExecutor` for high-performance file discovery and processing, making scans quick and efficient.
|
|
40
|
+
- **Detailed Output**: Generates an optional file tree, shows detailed scan summaries, and can even approximate token/character counts, which is useful for LLM context limits.
|
|
41
|
+
|
|
42
|
+
## 📦 Installation
|
|
43
|
+
|
|
44
|
+
You can install `dirshot` directly from PyPI.
|
|
45
|
+
|
|
46
|
+
**Basic Installation (no visual dependencies):**
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
pip install dirshot
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
**Installation with Enhanced Terminal Visuals:**
|
|
53
|
+
|
|
54
|
+
To get the full rich terminal experience, install the `rich` extra, which adds support for `rich`.
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
pip install dirshot[rich]
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## 🚀 How to Use
|
|
61
|
+
|
|
62
|
+
`dirshot` is used by importing the `generate_snapshot` function into a Python script.
|
|
63
|
+
|
|
64
|
+
Here is a basic example of creating a snapshot of a Python project:
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
# snapshot_script.py
|
|
68
|
+
from src.dirshot import generate_snapshot, LanguagePreset, IgnorePreset
|
|
69
|
+
# or
|
|
70
|
+
# from src.dirshot import *
|
|
71
|
+
|
|
72
|
+
generate_snapshot(
|
|
73
|
+
root_directory=".", # optional
|
|
74
|
+
output_file_name="my_python_project.txt",
|
|
75
|
+
language_presets=[LanguagePreset.PYTHON, LanguagePreset.MARKUP],
|
|
76
|
+
ignore_presets=[
|
|
77
|
+
IgnorePreset.VERSION_CONTROL, # Ignore .git
|
|
78
|
+
IgnorePreset.PYTHON, # Ignore __pycache__, venv, etc.
|
|
79
|
+
IgnorePreset.IDE_METADATA # Ignore .vscode, .idea
|
|
80
|
+
],
|
|
81
|
+
generate_tree=True,
|
|
82
|
+
show_token_count=True
|
|
83
|
+
)
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
To run this, save the code as a Python file (e.g., `snapshot_script.py`) and execute it from your terminal:
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
python snapshot_script.py
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## 📋 Examples
|
|
93
|
+
|
|
94
|
+
The `examples.py` file in the repository contains many more use cases. Here are a few common ones:
|
|
95
|
+
|
|
96
|
+
#### 1. Full-Stack Web App (React + Node.js)
|
|
97
|
+
|
|
98
|
+
This example combines multiple presets to capture a full-stack JavaScript project while ignoring common clutter like `node_modules`.
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
generate_snapshot(
|
|
102
|
+
root_directory=".",
|
|
103
|
+
output_file_name="fullstack_js_snapshot.txt",
|
|
104
|
+
language_presets=[
|
|
105
|
+
LanguagePreset.REACT, # Handles all frontend JS/TS/JSX files
|
|
106
|
+
LanguagePreset.WEB_FRONTEND # Includes HTML and CSS files
|
|
107
|
+
],
|
|
108
|
+
ignore_presets=[
|
|
109
|
+
IgnorePreset.NODE_JS, # Crucial for ignoring node_modules
|
|
110
|
+
IgnorePreset.IDE_METADATA,
|
|
111
|
+
IgnorePreset.BUILD_ARTIFACTS,
|
|
112
|
+
IgnorePreset.VERSION_CONTROL
|
|
113
|
+
],
|
|
114
|
+
generate_tree=True,
|
|
115
|
+
show_tree_stats=True
|
|
116
|
+
)
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
#### 2. Data Science Project (Python, Notebooks & SQL)
|
|
120
|
+
|
|
121
|
+
Collate all relevant files from a data analysis or machine learning project.
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
generate_snapshot(
|
|
125
|
+
root_directory="./data_science_project",
|
|
126
|
+
output_file_name="data_science_snapshot.txt",
|
|
127
|
+
language_presets=[
|
|
128
|
+
LanguagePreset.PYTHON,
|
|
129
|
+
LanguagePreset.DATA_SCIENCE_NOTEBOOKS, # .ipynb
|
|
130
|
+
LanguagePreset.SQL,
|
|
131
|
+
LanguagePreset.MARKUP # Include READMEs
|
|
132
|
+
],
|
|
133
|
+
ignore_presets=[
|
|
134
|
+
IgnorePreset.PYTHON, # Ignores venv, __pycache__, etc.
|
|
135
|
+
IgnorePreset.JUPYTER_NOTEBOOKS, # Ignores .ipynb_checkpoints
|
|
136
|
+
IgnorePreset.IDE_METADATA,
|
|
137
|
+
IgnorePreset.VERSION_CONTROL
|
|
138
|
+
]
|
|
139
|
+
)
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
#### 3. Search for Secrets or API Keys
|
|
143
|
+
|
|
144
|
+
Use "Search Mode" to perform a security audit. This example intentionally omits the `SECRET_FILES` ignore preset to ensure `.env` files are searched.
|
|
145
|
+
|
|
146
|
+
```python
|
|
147
|
+
generate_snapshot(
|
|
148
|
+
root_directory=".",
|
|
149
|
+
output_file_name="secrets_audit_results.txt",
|
|
150
|
+
search_keywords=["password", "secret_key", "api_key", "token"],
|
|
151
|
+
language_presets=[LanguagePreset.CONFIGURATION],
|
|
152
|
+
search_file_contents=True,
|
|
153
|
+
ignore_presets=[
|
|
154
|
+
IgnorePreset.VERSION_CONTROL,
|
|
155
|
+
IgnorePreset.NODE_JS,
|
|
156
|
+
IgnorePreset.BUILD_ARTIFACTS
|
|
157
|
+
# Deliberately not ignoring SECRET_FILES
|
|
158
|
+
]
|
|
159
|
+
)
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## ⚙️ API Reference
|
|
163
|
+
|
|
164
|
+
The `generate_snapshot()` function accepts the following parameters:
|
|
165
|
+
|
|
166
|
+
| Parameter | Type | Default | Description |
|
|
167
|
+
| ------------------------------------- | ---------------------------- | ---------------------------- | ------------------------------------------------------------------------------------------------------- |
|
|
168
|
+
| `root_directory` | `str` | `"."` | The starting directory for the scan. |
|
|
169
|
+
| `output_file_name` | `str` | `"project_snapshot.txt"` | The name of the file to save the results to. |
|
|
170
|
+
| `search_keywords` | `Optional[List[str]]` | `None` | If provided, switches to **Search Mode**. Otherwise, runs in **Snapshot Mode**. |
|
|
171
|
+
| `files` | `Optional[List[str]]` | `None` | A list of specific filenames to include. If provided, checks this list first before extensions. |
|
|
172
|
+
| `language_presets` | `Optional[List[LanguagePreset]]` | `None` | A list of `LanguagePreset` enums for common file types (e.g., `LanguagePreset.PYTHON`). |
|
|
173
|
+
| `ignore_presets` | `Optional[List[IgnorePreset]]` | `None` | A list of `IgnorePreset` enums for common ignore patterns (e.g., `IgnorePreset.NODE_JS`). |
|
|
174
|
+
| `file_extensions` | `Optional[List[str]]` | `None` | A manual list of file extensions to include (e.g., `[".py", ".md"]`). |
|
|
175
|
+
| `ignore_if_in_path` | `Optional[List[str]]` | `None` | A list of directory or file substring names to exclude (e.g., `["temp"]` excludes `src/temp/file.py`). |
|
|
176
|
+
| `ignore_extensions` | `Optional[List[str]]` | `None` | A manual list of file extensions to explicitly ignore (e.g., `[".log", ".tmp"]`). |
|
|
177
|
+
| `search_file_contents` | `bool` | `True` | In Search Mode, search for keywords within file contents. |
|
|
178
|
+
| `generate_tree` | `bool` | `True` | Include a file tree of the matched files at the top of the output. |
|
|
179
|
+
| `show_tree_stats` | `bool` | `False` | Display file and directory counts in the generated tree. |
|
|
180
|
+
| `show_token_count` | `bool` | `False` | Display an approximated token/character count in the summary and output file. |
|
|
181
|
+
| `exclude_whitespace_in_token_count` | `bool` | `False` | If `True`, removes whitespace before counting tokens for a more compact count. |
|
|
182
|
+
| `max_workers` | `Optional[int]` | `CPU count + 4` | The maximum number of worker threads for concurrent processing. |
|
|
183
|
+
| `read_binary_files` | `bool` | `False` | If `True`, the content search will attempt to read and search through binary files. |
|
|
184
|
+
| `only_show_tree` | `bool` | `False` | If `True`, the output file will contain only the file tree (and stats), omitting file content. |
|
|
185
|
+
| `case_sensitive_filter` | `bool` | `False` | If `True`, file filtering (extensions, ignore paths) is case-sensitive. |
|
|
186
|
+
| `case_sensitive_search` | `bool` | `False` | If `True`, keyword searching is case-sensitive. |
|
|
187
|
+
|
|
188
|
+
## 🤝 Contributing
|
|
189
|
+
|
|
190
|
+
Contributions are welcome! Please feel free to submit a pull request or open an issue.
|
|
191
|
+
|
|
192
|
+
1. Fork the repository.
|
|
193
|
+
2. Create a new branch (`git checkout -b feature/your-feature-name`).
|
|
194
|
+
3. Make your changes.
|
|
195
|
+
4. Commit your changes (`git commit -m 'Add some feature'`).
|
|
196
|
+
5. Push to the branch (`git push origin feature/your-feature-name`).
|
|
197
|
+
6. Open a pull request.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
dirshot/__init__.py,sha256=OpzEFnxp6FpjdapuhBF5UTEc-rpR-Z9r0B2wa9gTSwo,476
|
|
2
|
+
dirshot/dirshot.py,sha256=VpRVuLabAN1S8lFXuKFB4vYvsQjz9vPSpVu6ieTvpvY,38595
|
|
3
|
+
dirshot/reconstruct.py,sha256=rM9rcNoE7tQkqUhP1Fisg2Hlxb3CE0iDvvCdCOOdS8k,4628
|
|
4
|
+
dirshot-0.3.0.dist-info/METADATA,sha256=0uzuFJGJSEQgzGTgPauUpWTNcw9YOX5BboeoR53tuP4,11236
|
|
5
|
+
dirshot-0.3.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
6
|
+
dirshot-0.3.0.dist-info/top_level.txt,sha256=ROGW8gTcmwJ2jJ1Fp7TV1REZLRUGbL3L-Lfoy8tPxOA,8
|
|
7
|
+
dirshot-0.3.0.dist-info/RECORD,,
|
dirshot/examples.py
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
from src.dirshot.dirshot import *
|
|
2
|
-
|
|
3
|
-
if __name__ == "__main__":
|
|
4
|
-
# To run a specific example, make sure it is NOT commented out,
|
|
5
|
-
# and the other examples ARE commented out.
|
|
6
|
-
|
|
7
|
-
# --- Example 1: Search with NO Presets (Custom Filters) ---
|
|
8
|
-
# Goal: Find the words "API" or "Controller" inside any .java or .js file,
|
|
9
|
-
# while manually ignoring common dependency/build folders.
|
|
10
|
-
# print("\n--- Example 1: Running a custom search with NO presets ---")
|
|
11
|
-
# find_in_project(
|
|
12
|
-
# root_dir_param="example_project",
|
|
13
|
-
# output_file_name="search_custom_results.txt",
|
|
14
|
-
# search_keywords=["API", "Controller"],
|
|
15
|
-
|
|
16
|
-
# # --- NO language_presets ---
|
|
17
|
-
# # Manually define which file types to scan
|
|
18
|
-
# file_extensions_to_check=[".java", ".js"],
|
|
19
|
-
|
|
20
|
-
# # --- NO ignore_presets ---
|
|
21
|
-
# # Manually define which directories to skip
|
|
22
|
-
# ignore_dirs_in_path=["node_modules", "build", "venv"],
|
|
23
|
-
|
|
24
|
-
# search_file_contents=True,
|
|
25
|
-
# show_tree_stats=True,
|
|
26
|
-
# show_token_count=True,
|
|
27
|
-
# )
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
# # --- Example 2: Search with Python Presets ---
|
|
31
|
-
# # Goal: Find the word "Flask" inside any Python-related file.
|
|
32
|
-
# # The presets will automatically handle file types and ignore folders like 'venv'.
|
|
33
|
-
# print("\n--- Example 2: Running a search with Python presets ---")
|
|
34
|
-
# find_in_project(
|
|
35
|
-
# root_dir_param=".",
|
|
36
|
-
# output_file_name="search_python_preset_results.txt",
|
|
37
|
-
# search_keywords=[""],
|
|
38
|
-
|
|
39
|
-
# # Use presets for convenience
|
|
40
|
-
# language_presets=[LanguagePreset.PYTHON],
|
|
41
|
-
# ignore_presets=[IgnorePreset.PYTHON_ENV],
|
|
42
|
-
|
|
43
|
-
# search_file_contents=True,
|
|
44
|
-
# show_tree_stats=True,
|
|
45
|
-
# show_token_count=True,
|
|
46
|
-
# )
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
filter_project(
|
|
50
|
-
root_dir_param=".",
|
|
51
|
-
output_file_name="snapshot.txt",
|
|
52
|
-
file_types=[".py"],
|
|
53
|
-
# Use presets to define the scope of the snapshot
|
|
54
|
-
# language_presets=[LanguagePreset.PYTHON],
|
|
55
|
-
|
|
56
|
-
ignore_dirs_in_path=[".git"],
|
|
57
|
-
ignore_presets=[
|
|
58
|
-
IgnorePreset.PYTHON_ENV,
|
|
59
|
-
IgnorePreset.NODE_MODULES,
|
|
60
|
-
IgnorePreset.BUILD_ARTIFACTS,
|
|
61
|
-
],
|
|
62
|
-
|
|
63
|
-
show_tree_stats=False,
|
|
64
|
-
show_token_count=True,
|
|
65
|
-
)
|
dirshot-0.1.3.dist-info/METADATA
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: dirshot
|
|
3
|
-
Version: 0.1.3
|
|
4
|
-
Summary: A flexible utility for creating project snapshots and searching for files.
|
|
5
|
-
Author-email: init-helpful <init.helpful@gmail.com>
|
|
6
|
-
Project-URL: Homepage, https://github.com/init-helpful/dirshot
|
|
7
|
-
Project-URL: Bug Tracker, https://github.com/init-helpful/dirshot/issues
|
|
8
|
-
Classifier: Programming Language :: Python :: 3
|
|
9
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
-
Classifier: Operating System :: OS Independent
|
|
11
|
-
Requires-Python: >=3.7
|
|
12
|
-
Description-Content-Type: text/markdown
|
|
13
|
-
Requires-Dist: tqdm
|
|
14
|
-
|
|
15
|
-
# Dirshot: A Flexible Project Snapshot and Search Tool
|
|
16
|
-
|
|
17
|
-
Dirshot is a Python utility that creates snapshots of a project's directory structure and file contents. It can operate in two modes: filtering files based on their type and path, or searching for files based on keywords in their name or content.
|
|
18
|
-
|
|
19
|
-
The script generates a single output file containing a directory tree and the concatenated text of the selected files. This is useful for quickly gathering project context for code analysis, sharing with collaborators, or providing to a Large Language Model (LLM).
|
|
20
|
-
|
|
21
|
-
## Key Features
|
|
22
|
-
|
|
23
|
-
* **Two Operating Modes**:
|
|
24
|
-
* **Filter Mode**: Create a snapshot of your project by filtering files based on extensions, filenames, and directory paths.
|
|
25
|
-
* **Search Mode**: Search for files containing specific keywords in their name, path, or content.
|
|
26
|
-
* **Customizable Filtering**:
|
|
27
|
-
* Use language presets for popular languages (Python, JavaScript, Java, etc.).
|
|
28
|
-
* Use ignore presets to exclude common files and directories (e.g., `.git`, `node_modules`, `__pycache__`).
|
|
29
|
-
* Define custom file types, and whitelist/blacklist substrings in filenames and paths.
|
|
30
|
-
* **Flexible Tree Generation**:
|
|
31
|
-
* Display a directory tree in various styles (Unicode, ASCII, Compact).
|
|
32
|
-
* Show statistics for included/matched files and directories in the tree.
|
|
33
|
-
* **Content Collation**:
|
|
34
|
-
* Concatenates the content of all selected files into a single output file.
|
|
35
|
-
* Optionally display an approximated token/character count.
|
|
36
|
-
* **Snapshot Deconstruction**:
|
|
37
|
-
* A utility function to parse a generated snapshot file and extract the directory tree and file paths.
|
|
38
|
-
|
|
39
|
-
## Installation
|
|
40
|
-
|
|
41
|
-
You can install Dirshot from PyPI:
|
|
42
|
-
|
|
43
|
-
```bash
|
|
44
|
-
pip install dirshot
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
## Usage
|
|
50
|
-
|
|
51
|
-
Here are some examples of how to use Dirshot in your own Python scripts.
|
|
52
|
-
|
|
53
|
-
#### Example 1: Creating a Snapshot with Presets (Filter Mode)
|
|
54
|
-
|
|
55
|
-
This example creates a snapshot of a Python project, ignoring common virtual environment and build directories.
|
|
56
|
-
|
|
57
|
-
```python
|
|
58
|
-
from dirshot import filter_project, LanguagePreset, IgnorePreset
|
|
59
|
-
|
|
60
|
-
filter_project(
|
|
61
|
-
root_dir_param=".",
|
|
62
|
-
output_file_name="project_snapshot.txt",
|
|
63
|
-
language_presets=[LanguagePreset.PYTHON],
|
|
64
|
-
ignore_presets=[
|
|
65
|
-
IgnorePreset.PYTHON_ENV,
|
|
66
|
-
IgnorePreset.NODE_MODULES,
|
|
67
|
-
IgnorePreset.BUILD_ARTIFACTS,
|
|
68
|
-
],
|
|
69
|
-
show_token_count=True,
|
|
70
|
-
)
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
#### Example 2: Searching for Keywords in a Project (Search Mode)
|
|
74
|
-
|
|
75
|
-
This example searches for the keywords "API" or "Controller" within `.java` and `.js` files.
|
|
76
|
-
|
|
77
|
-
```python
|
|
78
|
-
from dirshot import find_in_project
|
|
79
|
-
|
|
80
|
-
find_in_project(
|
|
81
|
-
root_dir_param="example_project",
|
|
82
|
-
output_file_name="search_results.txt",
|
|
83
|
-
search_keywords=["API", "Controller"],
|
|
84
|
-
file_extensions_to_check=[".java", ".js"],
|
|
85
|
-
ignore_dirs_in_path=["node_modules", "build"],
|
|
86
|
-
search_file_contents=True,
|
|
87
|
-
show_tree_stats=True,
|
|
88
|
-
)
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
### Deconstructing a Snapshot
|
|
92
|
-
|
|
93
|
-
You can also parse a previously generated snapshot file to extract the directory structure and the list of included files.
|
|
94
|
-
|
|
95
|
-
```python
|
|
96
|
-
from dirshot import deconstruct_snapshot
|
|
97
|
-
|
|
98
|
-
snapshot_data = deconstruct_snapshot("project_snapshot.txt")
|
|
99
|
-
print("Directory Tree:")
|
|
100
|
-
for line in snapshot_data["tree_lines"]:
|
|
101
|
-
print(line)
|
|
102
|
-
|
|
103
|
-
print("\nIncluded Files:")
|
|
104
|
-
for file_path in snapshot_data["file_paths"]:
|
|
105
|
-
print(file_path)
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
## Contributing
|
|
109
|
-
|
|
110
|
-
Contributions are welcome! Please feel free to submit a pull request or open an issue on the project's GitHub repository.
|
dirshot-0.1.3.dist-info/RECORD
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
dirshot/__init__.py,sha256=ss4HC5VTyD9j6GFGCLMU6VxPlXy0qaGFzXlZB3_d2WM,403
|
|
2
|
-
dirshot/dirshot.py,sha256=2zx4ghzYi5Rsh-C0maHATapF2ArremgRLFWJlWlRu34,40365
|
|
3
|
-
dirshot/examples.py,sha256=q--iNqxmA4xX8nyXYdOP-HPsqzpLHBFo1PTseQ9ki7M,2344
|
|
4
|
-
dirshot-0.1.3.dist-info/METADATA,sha256=9mdpQmEFer0rY-kineW0bSU2OZHHYo7FNw1eDCZ_M4I,4172
|
|
5
|
-
dirshot-0.1.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
6
|
-
dirshot-0.1.3.dist-info/top_level.txt,sha256=ROGW8gTcmwJ2jJ1Fp7TV1REZLRUGbL3L-Lfoy8tPxOA,8
|
|
7
|
-
dirshot-0.1.3.dist-info/RECORD,,
|
|
File without changes
|