mirror of
https://github.com/walkxcode/dashboard-icons.git
synced 2024-11-27 13:44:58 +01:00
Compare commits
4 commits
a0101322ee
...
07a06d893e
Author | SHA1 | Date | |
---|---|---|---|
|
07a06d893e | ||
|
df68010f94 | ||
|
16a4a8fd7e | ||
|
478994e9cc |
3 changed files with 2812 additions and 0 deletions
31
.github/workflows/generate_filetree.yml
vendored
Normal file
31
.github/workflows/generate_filetree.yml
vendored
Normal file
|
@ -0,0 +1,31 @@
|
|||
name: 🌴 Generate File Tree
|
||||
|
||||
on:
|
||||
push:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
generate:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Setup Python
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: "3.9"
|
||||
architecture: "x64"
|
||||
|
||||
- name: Generate File Tree
|
||||
run: python config/tree.py svg png
|
||||
|
||||
- name: Load to GitHub
|
||||
run: |-
|
||||
git diff
|
||||
git config --global user.email "noreply@lammers.media"
|
||||
git config --global user.name "Dashboard Icons Bot"
|
||||
git add tree.json
|
||||
git commit -m ":construction_worker: Generates file_tree.json" || exit 0
|
||||
git push
|
54
config/tree.py
Normal file
54
config/tree.py
Normal file
|
@ -0,0 +1,54 @@
|
|||
import os
|
||||
import json
|
||||
import sys
|
||||
|
||||
def folder_to_json(path):
|
||||
tree = {}
|
||||
base_folder_name = os.path.basename(os.path.normpath(path)) # Get the base folder name
|
||||
|
||||
# Ensure the path doesn't return an empty string or dot.
|
||||
base_folder_name = base_folder_name if base_folder_name else os.path.basename(os.getcwd())
|
||||
|
||||
for root, dirs, files in os.walk(path):
|
||||
# Get the relative path of the root directory
|
||||
relative_path = os.path.relpath(root, path)
|
||||
|
||||
# Use base folder name for root, and append relative path for subfolders
|
||||
key = base_folder_name if relative_path == '.' else os.path.join(base_folder_name, relative_path)
|
||||
|
||||
# Only add the folder if there are files
|
||||
if files:
|
||||
tree[key] = files
|
||||
|
||||
return tree
|
||||
|
||||
def generate_combined_tree(paths):
|
||||
combined_tree = {}
|
||||
|
||||
for path in paths:
|
||||
# Add folder tree for each path
|
||||
combined_tree.update(folder_to_json(path))
|
||||
|
||||
return combined_tree
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Get the list of folder paths from command-line arguments
|
||||
folder_paths = sys.argv[1:]
|
||||
|
||||
if not folder_paths:
|
||||
print("Please provide at least one folder path.")
|
||||
sys.exit(1)
|
||||
|
||||
# Check if 'tree.json' exists
|
||||
if os.path.exists('tree.json'):
|
||||
print("'tree.json' already exists. No file was created.")
|
||||
sys.exit(0)
|
||||
|
||||
# Generate the combined folder tree for all specified paths
|
||||
combined_folder_tree = generate_combined_tree(folder_paths)
|
||||
|
||||
# Write the combined JSON structure to a file named tree.json
|
||||
with open('tree.json', 'w') as f:
|
||||
json.dump(combined_folder_tree, f, indent=4)
|
||||
|
||||
print("Folder tree successfully written to 'tree.json'.")
|
Loading…
Reference in a new issue