Generate directory structures from ASCII art or Markdown files
Project description
mdirtree
Generate directory structures from ASCII art or Markdown files.
Overview
mdirtree is a command-line tool that converts ASCII directory trees into actual directory structures. It can parse trees from various sources, including plain text files, standard input, or code blocks within Markdown files.
This is useful for quickly setting up project scaffolding, creating test directories, or documenting and implementing directory structures defined in documentation.
Features
- Generate directory structure from ASCII tree diagrams
- Support for Markdown and text files
- Interactive input mode
- Dry run mode
- Comment support (using # after file/directory names)
- Special handling for common files (README.md, init.py, etc.)
- REST API for remote directory generation
Installation
Via pip
pip install mdirtree
Setting up a development environment
Create a virtual environment:
python -m venv venv
Activate the virtual environment:
source venv/bin/activate # On Windows: venv\Scripts\activate
Install dependencies:
pip install --upgrade pip
pip install -r requirements.txt
Install in development mode:
pip install -e .
Usage
Basic usage
# Generate from Markdown file
mdirtree structure.md -o ./output_dir
# Generate from text file
mdirtree structure.txt -o ./output_dir
# Generate from stdin
mdirtree - -o ./output_dir
# Dry run (show planned operations without creating files)
mdirtree --dry-run structure.md
# Enable verbose logging
mdirtree -v structure.md -o ./output_dir
Command-line Options
usage: mdirtree [-h] [--output OUTPUT] [--dry-run] [--verbose] [input]
Generate directory structure from ASCII art or Markdown files
positional arguments:
input Input file (*.md, *.txt) or - for stdin
options:
-h, --help show this help message and exit
--output OUTPUT, -o OUTPUT
Output directory (default: current directory)
--dry-run, -d Show planned operations without creating files
--verbose, -v Enable verbose logging
Input Format Example
project/
├── src/
│ ├── main.py
│ └── utils/
└── tests/
└── test_main.py
REST API
mdirtree also offers a REST API for generating directory structures:
Starting the server
from mdirtree.rest.server import run_server
run_server(host='0.0.0.0', port=5000)
Using the client
from mdirtree.rest.client import MdirtreeClient
client = MdirtreeClient('http://localhost:5000')
structure = """
project/
├── src/
│ └── main.py
└── tests/
└── test_main.py
"""
# Generate structure
result = client.generate_structure(structure, output_path="./output")
print(result)
# Dry run mode
result = client.generate_structure(structure, dry_run=True)
print(result)
REST API Endpoints
- POST /generate
- Request body:
{ "structure": "ASCII art structure", "output_path": "optional output path", "dry_run": false }
- Response:
{ "status": "success", "operations": ["list of operations"], "output_path": "output path" }
- Request body:
License
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file mdirtree-0.1.5.tar.gz
.
File metadata
- Download URL: mdirtree-0.1.5.tar.gz
- Upload date:
- Size: 27.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1c152150ad4dbefdb4dc99feaee44d9b5978f6c1502783d81f7c6cff303f189 |
|
MD5 | 778e808ac79600deb707f89b9251dfc3 |
|
BLAKE2b-256 | 2d5421c7387e36e5570aae6654a39c25871c26493f89c5b61c2957867088888d |
File details
Details for the file mdirtree-0.1.5-py3-none-any.whl
.
File metadata
- Download URL: mdirtree-0.1.5-py3-none-any.whl
- Upload date:
- Size: 14.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 99e3db36cf25542f5017fdbddd3a7f5b62198e5418d4de3ece5c4a4bc075d3f0 |
|
MD5 | 0737bd4c7dd5727bc301c46e54689368 |
|
BLAKE2b-256 | 2d6b90e430b074b2580da9668d2ab965a19198e08fcf3cd12307123da8a78fb5 |