forked from YunoHost/apps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
change_level.py
executable file
·35 lines (24 loc) · 991 Bytes
/
change_level.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
#!/usr/bin/env python
import os
import sys
import json
if __name__ == '__main__':
if len(sys.argv[1:]) < 3:
print "Usage: ./change_level.py <official.json|community.json> <app_id> <level>"
sys.exit(1)
app_list_name, app_id, level = sys.argv[1:4]
if not os.path.exists(app_list_name):
print "Error: the file '%s' doesn't exist" % app_list_name
sys.exit(1)
app_list = json.load(open(app_list_name))
if app_id not in app_list:
print "Error: app '%s' is not present in %s" % (app_id, app_list_name)
sys.exit(1)
if not level.isdigit():
print "Error: app level must be a number, it's '%s'" % level
sys.exit(1)
if not 0 <= int(level) <= 10:
print "Error: app level must be between 0 and 10, it's '%s'" % level
sys.exit(1)
app_list[app_id]["level"] = int(level)
open(app_list_name, "w").write("\n".join(json.dumps(app_list, indent=4, sort_keys=True).split(" \n")) + "\n")