Skip to content

Commit

Permalink
add tools
Browse files Browse the repository at this point in the history
  • Loading branch information
Cp0204 committed Nov 24, 2023
1 parent 4968817 commit 5571a09
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Tools/ConversionArm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import glob
import ruamel.yaml

def modify_yaml(file_path):
yaml = ruamel.yaml.YAML()
yaml.preserve_quotes = True
yaml.width = 2 ** 32
# 读取docker-compose.yml文件内容
with open(file_path, 'r', encoding='utf-8') as file:
data = yaml.load(file)
# 修改数据
app_name = data['name']
app_name = app_name.replace("-arm", "")
app_name_arch = app_name + '-arm'
data['name'] = app_name_arch
data['services'][app_name_arch] = data['services'].pop(app_name)
data['services'][app_name_arch]['container_name'] = app_name_arch
data['x-casaos']['main'] = app_name_arch
# 写回docker-compose.yml文件
with open(file_path, 'w', encoding='utf-8') as file:
yaml.dump(data, file)

# 获取匹配的文件列表
files = glob.glob('./Apps_arm/*/docker-compose.yml')

# 对每个文件进行修改
for file_path in files:
print(file_path)
modify_yaml(file_path)
41 changes: 41 additions & 0 deletions Tools/CreateAppList.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import glob
import os
import yaml
import re

# 获取匹配的文件列表
compose_files = glob.glob('./Apps/*/docker-compose.yml')

# 初始化Markdown表格
markdown_table = "| Icon | AppName | Description |\n"
markdown_table += "|:----:|---------|-------------|\n"

# 读取并解析docker-compose.yml文件,提取字段,并添加到Markdown表格
for compose_file in compose_files:
with open(compose_file, 'r', encoding='utf-8') as f:
try:
data = yaml.safe_load(f)
app_name = os.path.basename(os.path.dirname(compose_file))
icon = data.get('x-casaos', {}).get('icon', '')
title = data.get('x-casaos', {}).get('title', {}).get('en_us', '')
description1 = data.get('x-casaos', {}).get('description', {}).get('en_us', '')
description2 = data.get('x-casaos', {}).get('description', {}).get('zh_cn', '')

markdown_table += f"| ![{title}]({icon}) | [{title}](./Apps/{app_name}) | {description1}<br>{description2} |\n"
except Exception as e:
print(f"Error parsing {compose_file}: {e}")


# 将Markdown表格写入AppList.md文件
#with open('AppList.md', 'w', encoding='utf-8') as readme:
# readme.write(markdown_table)

# 替换README.md文件内容
file_path = 'README.md'
with open(file_path, 'r', encoding='utf-8') as file:
content = file.read()
new_content = re.sub(rf'(## App List / 应用列表)([\w\W]*)', '## App List / 应用列表\n\n' + markdown_table , content)
with open(file_path, 'w', encoding='utf-8') as file:
file.write(new_content)

print("已生成")

0 comments on commit 5571a09

Please sign in to comment.