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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
#!/usr/bin/python
# Anas Nashif <anas.nashif@intel.com>
import yaml, sys
import re, os
from kswriter.KSWriter import KSWriter, KSMetaError, yamlload_safe
import copy
import time
import optparse
from time import gmtime, strftime
try:
from lxml import etree
except ImportError:
try:
# Python 2.5
import xml.etree.cElementTree as etree
except ImportError:
try:
# Python 2.5
import xml.etree.ElementTree as etree
except ImportError:
try:
# normal cElementTree install
import cElementTree as etree
except ImportError:
try:
# normal ElementTree install
import elementtree.ElementTree as etree
except ImportError:
print("Failed to import ElementTree from any known place")
def image_xml(root, img):
s = etree.Element("config")
c = etree.Element('name')
c.text = "%s.ks" %img['FileName']
s.append(c)
cc = etree.Element('path')
cc.text = "image-configs/%s.ks" %img['FileName']
s.append(cc)
cc = etree.Element('description')
cc.text = "%s" %img['Name']
s.append(cc)
if img.has_key('Architecture'):
cc = etree.Element('arch')
cc.text = "%s" %img['Architecture']
s.append(cc)
cc = etree.Element('md5')
cc.text = ""
s.append(cc)
cc = etree.Element('schedule')
if img.has_key('Schedule'):
cc.text = img['Schedule']
s.append(cc)
root.append(s)
def create_xml(image_meta, external_configs=[]):
root = etree.Element("image-configs")
if image_meta.has_key('Configurations'):
for img in image_meta['Configurations']:
image_xml(root,img)
external = []
if external_configs:
external = external + external_configs
if image_meta.has_key('ExternalConfigs') and image_meta['ExternalConfigs']:
external = external + image_meta['ExternalConfigs']
for path in external:
for f in os.listdir(path):
if f.endswith('.yaml'):
local = yamlload_safe('%s/%s' %(path, f))
conf = ks.parse(local)
if conf.has_key('Active') and conf['Active']:
image_xml(root,conf)
str = etree.tostring(root, pretty_print=True)
return str
if __name__ == '__main__':
parser = optparse.OptionParser()
parser.add_option("-c", "--configs", type="string", dest="configsfile",
help="configuration meta file")
parser.add_option("-o", "--outdir", type="string", dest="outdir", default=".",
help="outdir")
parser.add_option("-r", "--repos", action="append", type="string", dest="repofile",
help="repo meta file")
parser.add_option("-e", "--external", action="append", type="string", dest="external",
help="Additional external configuration files")
parser.add_option("-i", "--index", type="string", dest="indexfile",
help="generate index file")
parser.add_option("-C", "--config", type="string", dest="config", default=None,
help="Limit to this configuration file")
parser.add_option("-p", "--packages", action="store_true", dest="packages", default=False,
help="return list of packages to be installed for this configuration")
parser.add_option("-T", "--targetdef", action="append", type="string", dest="targetdefs",
help="Targets meta file to specify images for corresponding build target")
parser.add_option("-t", "--target", type="string", dest="target", default=None,
help="Specify build target to filter ks generation")
(options, args) = parser.parse_args()
if options.configsfile is None or options.repofile is None:
print "you need to provide meta files with --configs and --repos"
sys.exit(1)
try:
ks = KSWriter(options.configsfile, options.repofile, options.outdir, options.config, options.packages, options.external, options.targetdefs, options.target)
ks.generate()
except KSMetaError as err:
print 'ERROR:', str(err)
sys.exit(1)
if options.indexfile:
str = create_xml(ks.image_meta, options.external)
f = open(options.indexfile, 'w')
f.write(str)
f.close()
|