You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

easy-tree-maker

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

easy-tree-maker

A tool to create a directory and file structure from JSON or Python object

0.1.6
pipPyPI
Maintainers
1

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.

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts