-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathgl_image
executable file
·86 lines (70 loc) · 2.33 KB
/
gl_image
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env python
import sys
import json
import getopt
import logging
from subprocess import check_call
def usage(pname):
print "GL.iNet create released image utility"
print "Usage: " + pname + " <OPTIONS>"
print ""
print " -i|--image Which type image to create"
print " -p|--profile Create image for which profile"
print " -v|--version Released version number"
print " -f|--files Files directory"
def main(argv):
logging.basicConfig(format = '%(levelname)s: %(message)s')
pname = argv[0]
try:
(opts, args) = getopt.getopt(argv[1:],
"hp:v:i:f:",
[ "help", "profile=", "version=", "image=", "files=" ])
except getopt.GetoptError as e:
usage(pname)
return 1
image= None
profile = None
version = None
files = ""
for (o, v) in opts:
if o in ("-h", "--help"):
usage(pname)
return 0
if o in ("-i", "--image"):
image = v
if o in ("-p", "--profile"):
profile = v
if o in ("-v", "--version"):
version = v
if o in ("-f", "--files"):
files = v
if image is None or profile is None or version is None:
logging.error("No (image|profile|version) specified, try run with -h")
return 1
filename = "images.json"
try:
with open(filename) as fd:
data = json.load(fd)
fd.close()
except:
logging.error("Failed to parse jsonfile[%s]" % filename)
return 1
images = data['images']
profiles = data['profiles']
if not image in images.keys():
logging.error("Specified image[%s] is not in jsonfile[%s]" % (image, filename))
return 1
if not profile in profiles.keys():
logging.error("Specified profile[%s] is not in jsonfile[%s]" % (profile, filename))
return 1
include_ipk = ""
for (k, v) in images.items():
if image == k:
include_ipk = v
for (k, v) in profiles.items():
if profile == k and v.has_key(image):
include_ipk = "%s %s" % (include_ipk, v[image])
check_call("make image PROFILE=%s VERSION=%s PACKAGES=\"%s\" FILES=%s" % \
(profile, version, include_ipk, files), shell=True);
if __name__ == "__main__":
sys.exit(main(sys.argv))