Skip to main content

tree2proj

tree2proj 是一个用于根据 JSON 格式的目录树结构,自动生成对应的文件夹和文件 的 Python 工具。它依赖 tree2json 包,将项目结构从类似 tree 命令的文本解析为 JSON 后,再由本工具落地为真实的项目结构。


✨ 功能亮点

  • 根据目录树结构生成完整项目目录
  • 支持命令行(CLI)快速构建项目骨架

📦 安装方法

确保 Python ≥ 3.7,先安装 tree2proj:

pip install tree2proj

🧰 用法说明

✅ 方式 1:Python 调用

  1. 分开使用 tree2json 和 tree2proj:
from tree2json import Tree2Json
from tree2proj import ProjBuilder

tree_str = """
bbb
├── 5个创新模块.pdf
├── AIproject
|  ├── mnist.zip
|  └── 论文
├── bihui_pic
|  └── ccccz
├── Blender 4.3.lnk
├── 钉钉.lnk
└── 飞书.lnk
"""

parser = Tree2Json()
parser.from_string(tree_str)

builder = ProjBuilder(parser.to_dict())
builder.create_fs()

此时就会先在目录下创建bbb根目录,然后在其中创建文件和文件夹。


  1. 直接一步到位
from tree2proj import ProjBuilder

tree_str = """
my_project
├── README.md
├── src
│   └── main.py
└── data
    └── sample.txt
"""

ProjBuilder.build_from_tree_str(tree_str)

✅ 方式 2:命令行使用(CLI)

  1. 直接使用
tree2proj

这会自动读取剪切板中的目录树文本(如果不是,会报错),并生成对应的项目结构。

  1. 从 JSON 文件生成项目结构
tree2proj path/to/tree.json --output /path/to/output/dir

注意:

  • 这里不一定需要是json文件,txt等文件类型也可以,只需要确保文件内容能够完整转化成json格式即可。
  • 如果不指定输出目录,则默认在当前目录下创建项目结构。
  • 如果指定了输出目录,那么会在该目录下创建项目结构,且不会创建目录树下的根目录。

🧩 依赖项

  • tree2json ≥ 0.1.3

📝 许可协议

本项目遵循 MIT 开源许可证。欢迎自由使用与修改。


📬 联系作者

作者:@knighthood

欢迎提 Issue、PR 或交流建议!

版本

v0.1.0

  • 发布最基础版本
  • 能够实现windows下使用命令行实现创建项目目录
  • 添加读取剪切板的功能

v0.1.1

  • 使用build_from_tree替代build_from_tree_str
  • 完善相关文档

Metadata

Release files for tree2proj 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tree2proj 0.1.1
File Size Uploaded Provenance Actions
tree2proj-0.1.1.tar.gz 5.4 kB Without provenance Details for tree2proj-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tree2proj 0.1.1
File Interpreter ABI Platform Actions
tree2proj-0.1.1-py3-none-any.whl Python 3 none any Details for tree2proj-0.1.1-py3-none-any.whl

Total release size: 11.6 kB

Release files / tree2proj-0.1.1.tar.gz

Download URL tree2proj-0.1.1.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
b7a359c74eac26041e39bcf2fbfe7343f700879ac883dd213af6c821d4187230
BLAKE2b-256 checksum
How to use checksums
64777f0cc47ff456b45212035b76f2a8ccf8a5d0baccd35405a40e085485c801
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.2

Release files / tree2proj-0.1.1-py3-none-any.whl

Download URL tree2proj-0.1.1-py3-none-any.whl
Size 6.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fabb9091ff9c02136f430bdb9d5baa91cf608fe24b4de6c25c15f9ba28d50656
BLAKE2b-256 checksum
How to use checksums
0af2a202210c013fc5266232bb76abbf6ea8cfe9c7abcf9f5816a6fc17138adf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.2

Security for tree2proj 0.1.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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page