2 # Anas Nashif <anas.nashif@intel.com>
6 from kickstart import kickstart
11 from time import gmtime, strftime
14 def __init__(self, im, rep, out):
15 self.image_filename = im
16 self.repo_filename = rep
18 self.image_stream = file(self.image_filename, 'r')
19 self.repo_stream = file(self.repo_filename, 'r')
23 return list(reduce(set.union, input, set()))
26 print yaml.dump(yaml.load(self.stream))
30 print "Creating %s (%s.ks)" %(img['Name'], img['FileName'] )
31 conf = copy.copy(image_meta['Default'])
32 plat = copy.copy(image_meta[img['Platform']])
35 lval = ['Repos', 'Groups', 'PostScripts', 'NoChrootScripts', 'RemovePackages', 'ExtraPackages']
39 if image_meta['Default'].has_key(l) and image_meta['Default'][l]:
40 full = full + image_meta['Default'][l]
41 if plat.has_key(l) and plat[l]:
43 if img.has_key(l) and img[l]:
50 for scr in conf['PostScripts']:
51 f = open('./custom/scripts/%s.post' %scr, 'r')
52 postscript += f.read()
57 for scr in conf['NoChrootScripts']:
58 f = open('./custom/scripts/%s.nochroot' %scr, 'r')
59 nochrootscript += f.read()
60 nochrootscript += "\n\n"
64 if img.has_key("Part"):
65 f = open("./custom/part/%s" %img['Part'] )
70 conf['Post'] = postscript
71 conf['NoChroot'] = nochrootscript
74 def process_files(self, meta, r):
75 nameSpace = {'metadata': meta, 'repos': r}
76 t = kickstart(searchList=[nameSpace])
78 if meta.has_key('FileName') and meta['FileName']:
79 f = open("%s/%s.ks" %( self.outdir, meta['FileName'] ), 'w')
83 if __name__ == '__main__':
84 parser = optparse.OptionParser()
86 parser.add_option("-c", "--configs", type="string", dest="configsfile",
87 help="configuration meta file")
88 parser.add_option("-o", "--outdir", type="string", dest="outdir",
90 parser.add_option("-r", "--repos", type="string", dest="repofile",
91 help="repo meta file")
93 (options, args) = parser.parse_args()
95 if options.configsfile is None or options.repofile is None:
96 print "you need to provide meta files with --configs and --repos"
100 if options.outdir is None:
103 outdir = options.outdir
105 ks = KSWriter(options.configsfile, options.repofile, outdir)
106 repo_meta = yaml.load(ks.repo_stream)
107 image_meta = yaml.load(ks.image_stream)
108 r = repo_meta['Repositories']
109 for img in image_meta['Configurations']:
111 ks.process_files(conf, r)