-
Notifications
You must be signed in to change notification settings - Fork 8
/
update-cloned-plugin.py
executable file
·55 lines (48 loc) · 1.98 KB
/
update-cloned-plugin.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
#!/usr/bin/env python3
import sys
import glob
import subprocess
import os
import json
def get_dirs(root):
for (_, dirs, _) in os.walk(root):
return filter(lambda d: not d.startswith('.'), dirs)
return []
def create_plugin_json(account, publisher, plugin, plugin_dir, destination_dir):
tag_query = subprocess.run(['git', 'describe', '--tags', '--abbrev=0'],
stderr=subprocess.DEVNULL,
stdout=subprocess.PIPE,
check=False,
cwd=plugin_dir)
release = tag_query.stdout.decode('utf-8').strip()
if tag_query.returncode != 0:
print("Unable to find release for", plugin_dir, file=sys.stderr)
versions = {}
versions_root = os.path.join(plugin_dir, 'plugins')
for ver in get_dirs(versions_root):
ver_dir = os.path.join(versions_root, ver)
platforms = list(sorted(p for p in get_dirs(ver_dir) if any(os.path.isfile(f) for f in glob.glob(os.path.join(ver_dir, p, '**'), recursive=True))))
if platforms:
versions[ver] = platforms
if versions and release:
output = {
"latest": release,
"supported": versions,
"plugin": plugin,
"publisherId": publisher,
"ghAccount": account
}
output_file = os.path.join(destination_dir, f"{publisher}_{plugin}.json")
orig = {}
if os.path.isfile(output_file):
with open(output_file, "r", encoding='utf-8') as f:
orig = json.load(f)
if not (output.items() <= orig.items()):
for k, v in output.items():
orig[k] = v
with open(output_file, "w", encoding="utf8") as f:
json.dump(orig, f, sort_keys=True, indent=4)
if __name__ == "__main__":
owner, repo = sys.argv[1].split('/', 1)
publisher, plugin = repo.split('-', 1)
create_plugin_json(owner, publisher, plugin, 'current-plugin', 'plugins')