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, repos):
78 if meta.has_key("Architecture") and meta['Architecture']:
81 r['Name'] = repo['Name']
82 r['Url'] = repo['Url'].replace("@ARCH@", meta['Architecture'])
87 nameSpace = {'metadata': meta, 'repos': new_repos}
88 t = kickstart(searchList=[nameSpace])
90 if meta.has_key('FileName') and meta['FileName']:
91 f = open("%s/%s.ks" %( self.outdir, meta['FileName'] ), 'w')
95 if __name__ == '__main__':
96 parser = optparse.OptionParser()
98 parser.add_option("-c", "--configs", type="string", dest="configsfile",
99 help="configuration meta file")
100 parser.add_option("-o", "--outdir", type="string", dest="outdir",
102 parser.add_option("-r", "--repos", type="string", dest="repofile",
103 help="repo meta file")
105 (options, args) = parser.parse_args()
107 if options.configsfile is None or options.repofile is None:
108 print "you need to provide meta files with --configs and --repos"
112 if options.outdir is None:
115 outdir = options.outdir
117 ks = KSWriter(options.configsfile, options.repofile, outdir)
118 repo_meta = yaml.load(ks.repo_stream)
119 image_meta = yaml.load(ks.image_stream)
120 r = repo_meta['Repositories']
121 for img in image_meta['Configurations']:
123 ks.process_files(conf, r)