-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathinfo.py
58 lines (47 loc) · 1.68 KB
/
info.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Update info.json
# this script is used by repo owner
import os
import re
import json
REPO_BASE_PATH = 'https://raw.githubusercontent.com/xfangfang/Macast-plugins/main/'
REPO_URL = "https://github.com/xfangfang/Macast-plugins"
def read_metadata(path):
data = {}
base_name = "/".join(path.split('/')[-2:])
with open(path, 'r', encoding='utf-8') as f:
renderer_file = f.read()
metadata = re.findall("<macast.(.*?)>(.*?)</macast", renderer_file)
print("< Load Renderer from {}".format(base_name))
for key, value in metadata:
print('%-10s: %s' % (key, value))
data[key] = value
data['url'] = REPO_BASE_PATH + base_name
if 'renderer' in data:
data['type'] = 'renderer'
if 'protocol' in data:
data['type'] = 'protocol'
return data
def main():
# get plugins path
current_path = os.path.dirname(os.path.abspath(__file__))
print(current_path)
plugins_path = []
for root, dirs, files in os.walk(current_path):
for file in files:
if ".py" in file and file not in ['update.py', 'info.py', 'example.py']:
plugins_path.append(os.path.join(root, file))
print('\n'.join(plugins_path))
# update info
info = dict()
info['plugin_v1'] = []
info['repo_url'] = REPO_URL
for path in plugins_path:
data = read_metadata(path)
info['plugin_v1'].append(data)
print(info)
# write to file
info_path = os.path.join(current_path, 'info.json')
with open(info_path, "w", encoding='utf-8') as f:
json.dump(obj=info, fp=f, sort_keys=True, indent=4, ensure_ascii=False)
if __name__ == '__main__':
main()