Project Structure Generator
Overview
Project Structure Generator is a versatile tool available both as a command-line interface and as a library. It enables users to generate directory structures in JSON, YAML, or plain text formats and offers the ability to pretty-print the structure with color.
Features
- Generate directory structures in JSON, YAML, Dictionary or plain text.
- Exclude patterns specified in
.gitignore. - Pretty-print the directory structure with colorful output.
- Command-line interface for ease of use.
- Ability to include content of specified files.
- Customizable patterns for more precise control over the directory structure output.
Installation
To install the package, use the following command:
pip install pstruc
CLI Usage
The pstruc tool supports various arguments for generating and customizing the directory structure.
Arguments
directory: Specify the directory to inspect (not specified: current directory)-f,--format: Choose the output format (json, yaml, txt, dict).-o,--output: Specify the output file name.-p,--print: Print the directory structure without saving it.-ns,--not-save: Do not save the generated structure to an output file.-ip,--add-ignore-patterns: Add custom patterns to ignore.-iff,--ignore-from-files: List of files to get the ignore patterns from.-igi,--ignore-git-ignore: Ignore the patterns inside .gitignore file.-fc,--add-content-file-patterns: Include content of specified files.
Example
python pstruc.py /path/to/directory -f json -o output_structure -ip "*.log","__pycache__" -fc "*.md","*.txt"
This command will generate a JSON file output_structure.json representing the directory structure of /path/to/directory, ignoring files matching *.log and __pycache__, and including content of markdown and text files.
Library Usage
As a library, pstruc provides a straightforward API for generating and manipulating directory structures. The core functionality is based on generating the structure, saving it, and pretty-printing.
Example
from pstruc import get_project_structure, save_structure_to_file, pretty_print
# Generate directory structure
structure = get_project_structure('/path/to/directory', 'json', ignore_patterns=["*.log", "__pycache__"], file_content=["*.md", "*.txt"])
# Save to a file
save_structure_to_file('output_structure.json', structure)
# Pretty-print the structure
pretty_print(structure)
Library Available Methods
-
get_project_structure(start_path, output_format, ignore_patterns, file_content): Generates the directory structure.start_path (str): The directory to inspect.output_format (str): The desired output format ('json', 'yaml', 'txt', 'dict').ignore_patterns (list): List of patterns to ignore.file_content (list): List of patterns to determine which file content to include in the structure.
-
save_structure_to_file(output_file, structure): Saves the directory structure to a file.output_file (str): The name of the output file.structure (str): The directory structure content to be saved.
-
pretty_print(structure): Pretty-prints the directory structure.structure (str or dict): The directory structure to print.indentation (str): The current indentation level.
-
get_all_ignore_patterns(start_path, files_with_ignore_patterns, extra_ignore_patterns): Retrieves a combined list of ignore patterns from specified files and additional user-provided patterns.start_path (str): The root directory path from where the search for ignore files begins.files_with_ignore_patterns (list of str): Filenames from which to read ignore patterns (e.g., '.gitignore').extra_ignore_patterns (list of str): Additional patterns provided by the user.
Contributing
Contributions are welcome! Please follow our Contributing Guidelines.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- colorama - For colorful output.
Metadata
Release files for pstruc 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pstruc-1.0.1.tar.gz | 10.2 kB | Without provenance | Details for pstruc-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pstruc-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for pstruc-1.0.1-py3-none-any.whl |
Total release size: 19.7 kB
Release files / pstruc-1.0.1.tar.gz
| Download URL | pstruc-1.0.1.tar.gz |
|---|---|
| Size | 10.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
937712a71f4f6495fd3bc5b3d4baa652714572d2fef74c51c7ed6684b725b84c
|
|
BLAKE2b-256 checksum How to use checksums |
c1a435d69cbde560922eec211a5ef5b6f4c5b114ba55383c2f25193dbe167b28
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.9.18
|
Release files / pstruc-1.0.1-py3-none-any.whl
| Download URL | pstruc-1.0.1-py3-none-any.whl |
|---|---|
| Size | 9.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cdf084f4fec8fb5be80fc824a4da39227a9d7fa51b33e3c247128b9bd751e9c7
|
|
BLAKE2b-256 checksum How to use checksums |
7ea21c78cc5c4604c8ce6d67b070d88e5acd876fa08e44e76d6844e236aaa74d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.9.18
|
Security for pstruc 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.