Skip to main content

Convert tree-formatted text into filesystem structures

Project description

tree2fs

Convert tree-formatted text into filesystem structures.

Installation

pip install tree2fs

Quick Start

Command Line Usage

# Create structure from tree file
tree2fs tree.txt

# Preview without creating (dry run)
tree2fs tree.txt --dry-run -v

# Create in specific directory
tree2fs tree.txt --base-dir /path/to/project

# Include root directory in creation
tree2fs tree.txt --no-skip-root

# NEW: JSON format with name: content pairs
tree2fs input.json --format json

Python API Usage

from tree2fs import create_from_tree

# Simple usage
stats = create_from_tree("tree.txt", verbose=True)
print(f"Created {stats['total']} items")

# Advanced usage
from tree2fs import TreeParser, FilesystemBuilder
from pathlib import Path

# Parse tree file
parser = TreeParser()
root, _ = parser.build_tree(Path("tree.txt"))

# Build filesystem
builder = FilesystemBuilder(Path("."), verbose=True)
builder.build(root)
builder.print_summary()

Tree File Format

project/
├── README.md
├── LICENSE
├── src/
│   ├── __init__.py
│   ├── main.py          # Main module
│   └── utils.py         # Utility functions
├── tests/
│   ├── __init__.py
│   └── test_main.py
└── docs/
    └── index.md

NEW JSON Format

Uses name: content pairs to represent the tree structure.

{
  "project": {
    "README.md": "# Project\n\nThis is a project.",
    "LICENSE": "MIT License",
    "src": {
      "__init__.py": "",
      "main.py": "# Main module\n\nimport os\n\ndef main():\n    print('it works!')\n\nmain()"
    },
    "tests": {
      "__init__.py": "",
      "test_main.py": "# Test module\n\nimport os\n\ndef test():\n    assert True\n\ntest()"
    },
    "docs": {
      "index.md": "# Documentation\n\nThis is the documentation."
    }
  }
}
  • Directories end with /
  • Comments start with #
  • Supports standard tree drawing characters: , , ,

Features

  • ✅ Parse tree-formatted text files
  • ✅ Create directories and files
  • ✅ Dry-run mode for preview
  • ✅ Verbose output with comments
  • ✅ Skip root directory option
  • ✅ Python 3.9+ support
  • ✅ Type hints throughout

Development

# Clone repository
git clone https://github.com/ABDELLAH-Hallou/tree2fs.git
cd tree2fs

# Install in development mode
pip install -e ".[dev]"

# Run tests
pytest

# Format code
black tree2fs tests

# Type checking
mypy tree2fs

License

MIT License - see LICENSE file for details.

Contributing

Contributions welcome! Please feel free to submit a Pull Request.

17. LICENSE

MIT License

Copyright (c) 2025-present Abdellah HALLOU

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
   list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

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

tree2fs-0.2.1.tar.gz (21.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tree2fs-0.2.1-py3-none-any.whl (16.3 kB view details)

Uploaded Python 3

File details

Details for the file tree2fs-0.2.1.tar.gz.

File metadata

  • Download URL: tree2fs-0.2.1.tar.gz
  • Upload date:
  • Size: 21.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for tree2fs-0.2.1.tar.gz
Algorithm Hash digest
SHA256 696bcab9a253c0526c4f83ff4a05478988d9930ad85c8d035742e38a839187fc
MD5 096bef2a3f9470138279590ecd17e441
BLAKE2b-256 2289e1c1f79ec019f20f5c900f704b920cb5d52a7119a91afb295fed805136f1

See more details on using hashes here.

File details

Details for the file tree2fs-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: tree2fs-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 16.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for tree2fs-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 23136d3456f76d1eeaee20e82db3f431290521b884317006e506aac514c19c8a
MD5 f5f060ba665047cd256c8075027e658f
BLAKE2b-256 f47292dbd47a5c0c3af1f5113471bb640cf6f61eb277b75534e2fea414ffce1b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page