A tool to create a directory and file structure from JSON or Python object
Project description
Tree Maker
A simple Python package that creates a directory and file structure from a given JSON or Python object.
Installation
You can install the package using pip:
pip install easy-tree-maker
Usage
You can use the TreeMaker class to create directories and files based on a JSON or Python structure.
Example with Python object:
from easy_tree_maker.core import TreeMaker
# Define the tree structure as a Python object
tree_structure = [
{
"type": "directory",
"name": "TestProject",
"contents": [
{"type": "file", "name": "README.md"},
{"type": "directory", "name": "src", "contents": [
{"type": "file", "name": "app.py"}
]}
]
}
]
# Create the tree with the Python object structure
tree_maker = TreeMaker(tree_structure, is_json=False)
tree_maker.create_tree(root_path="./TestDirectory")
Example with JSON string:
import json
from easy_tree_maker.core import TreeMaker
# Define the tree structure as a JSON string
tree_structure_json = json.dumps([
{
"type": "directory",
"name": "TestProject",
"contents": [
{"type": "file", "name": "README.md"},
{"type": "directory", "name": "src", "contents": [
{"type": "file", "name": "app.py"}
]}
]
}
])
# Create the tree with the JSON string structure
tree_maker = TreeMaker(tree_structure_json, is_json=True)
tree_maker.create_tree(root_path="./TestDirectory")
Example with JSON file:
If you have a JSON file containing the tree structure, you can use it as input:
from easy_tree_maker.core import TreeMaker
import json
# Load the tree structure from a JSON file
with open('tree_structure.json', 'r') as f:
tree_structure_json = f.read()
tree_maker = TreeMaker(tree_structure_json, is_json=True)
tree_maker.create_tree(root_path="./TestDirectory")
CLI Usage
You can also use the command-line interface (CLI) to create the tree structure from a JSON file or string.
To use the CLI, run:
easy_tree_maker path_to_json_file_or_string --root /path/to/create/tree
Example:
easy_tree_maker tree_structure.json --root /tmp/test_tree
This will read the JSON file tree_structure.json and create the directory and file structure in /tmp/test_tree.
Project details
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file easy_tree_maker-0.1.6.tar.gz.
File metadata
- Download URL: easy_tree_maker-0.1.6.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8222a8584c0bb9ac072e21abdf29c53f60cb67033d22a8e9a1a07aa797263dcc
|
|
| MD5 |
047031e7d1231117e9dee407cb4e28b1
|
|
| BLAKE2b-256 |
a1f59d1914535cb9c1d972a6a9bc32601655e77260b3a4c4cd2d158ef5708f34
|
File details
Details for the file easy_tree_maker-0.1.6-py3-none-any.whl.
File metadata
- Download URL: easy_tree_maker-0.1.6-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8c045dbc68e5484cbfdbd8e5d04b9d2a95293ed9f0f9cb907f406f00212b1e22
|
|
| MD5 |
4e65dd1c225dad5dbb61d1c62b78d745
|
|
| BLAKE2b-256 |
0cef1a98f60b7384819eb5b4c563fd78834aacdca992847e31bc15210a83d295
|