forked from YunoHost/apps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_id_unicity.py
56 lines (41 loc) · 1.72 KB
/
check_id_unicity.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
import sys
import json
import requests
def get_json(url, verify=True, token=None):
try:
# Retrieve and load manifest
if ".github" in url:
r = requests.get(url, verify=verify, auth=token)
else:
r = requests.get(url, verify=verify)
r.raise_for_status()
return r.json()
except requests.exceptions.RequestException as e:
print("-> Error: unable to request %s, %s" % (url, e))
return None
except ValueError as e:
print("-> Error: unable to decode JSON from %s : %s" % (url, e))
return None
def main(apps):
for app_id, app_data in apps.items():
url = app_data["url"]
github_repo_name = url.split("/")[-1].replace("_ynh", "")
if app_id != github_repo_name:
print "[%s] GitHub repo name is not coherent with app id: '%s' vs '%s' (%s)" % (app_id, app_id, url.split("/")[-1], url)
owner, repo_name = url.split("/")[-2:]
raw_url = "https://raw.githubusercontent.com/%s/%s/%s/manifest.json" % (
owner, repo_name, app_data["revision"]
)
manifest = get_json(raw_url)
if manifest is None:
continue
manifest_id = manifest["id"]
if app_id != manifest_id:
print "[%s] manifest id is different from app id: '%s' vs '%s' (manifest_id" % (app_id, app_id, manifest_id)
if manifest_id != github_repo_name:
print "[%s] manifest id is different from GitHub repo name: '%s' vs '%s' (%s)" % (app_id, manifest_id, url.split("/")[-1], url)
if __name__ == '__main__':
if not sys.argv[1:]:
print "Usage: python check_id_unicity.py list.json"
sys.exit(1)
main(json.load(open(sys.argv[1])))