2 # Anas Nashif <anas.nashif@intel.com>
6 from kickstart import kickstart
11 from time import gmtime, strftime
17 except OSError as exc: # Python >2.5
18 if exc.errno == errno.EEXIST:
24 def __init__(self, im, rep, out):
25 self.image_filename = im
26 self.repo_filename = rep
28 self.image_stream = file(self.image_filename, 'r')
29 self.repo_stream = file(self.repo_filename, 'r')
33 return list(reduce(set.union, input, set()))
36 print yaml.dump(yaml.load(self.stream))
40 print "Creating %s (%s.ks)" %(img['Name'], img['FileName'] )
41 conf = copy.copy(image_meta['Default'])
42 plat = copy.copy(image_meta[img['Platform']])
45 lval = ['Repos', 'Groups', 'PostScripts', 'NoChrootScripts', 'RemovePackages', 'ExtraPackages']
49 if image_meta['Default'].has_key(l) and image_meta['Default'][l]:
50 full = full + image_meta['Default'][l]
51 if plat.has_key(l) and plat[l]:
53 if img.has_key(l) and img[l]:
60 for scr in conf['PostScripts']:
61 f = open('./custom/scripts/%s.post' %scr, 'r')
62 postscript += f.read()
67 for scr in conf['NoChrootScripts']:
68 f = open('./custom/scripts/%s.nochroot' %scr, 'r')
69 nochrootscript += f.read()
70 nochrootscript += "\n\n"
74 if img.has_key("Part"):
75 f = open("./custom/part/%s" %img['Part'] )
80 conf['Post'] = postscript
81 conf['NoChroot'] = nochrootscript
84 def process_files(self, meta, repos):
88 if meta.has_key("Architecture") and meta['Architecture']:
91 r['Name'] = repo['Name']
92 r['Url'] = repo['Url'].replace("@ARCH@", meta['Architecture'])
93 r['Url'] = repo['Url'].replace("@RELEASE@", meta['Baseline'])
98 nameSpace = {'metadata': meta, 'repos': new_repos}
99 t = kickstart(searchList=[nameSpace])
101 if meta.has_key('FileName') and meta['FileName']:
103 if meta.has_key("Baseline"):
104 mkdir_p(meta['Baseline'])
105 f = open("%s/%s/%s.ks" %( self.outdir, meta['Baseline'], meta['FileName'] ), 'w')
107 f = open("%s/%s.ks" %( self.outdir, meta['FileName'] ), 'w')
111 if __name__ == '__main__':
112 parser = optparse.OptionParser()
114 parser.add_option("-c", "--configs", type="string", dest="configsfile",
115 help="configuration meta file")
116 parser.add_option("-o", "--outdir", type="string", dest="outdir",
118 parser.add_option("-r", "--repos", type="string", dest="repofile",
119 help="repo meta file")
121 (options, args) = parser.parse_args()
123 if options.configsfile is None or options.repofile is None:
124 print "you need to provide meta files with --configs and --repos"
128 if options.outdir is None:
131 outdir = options.outdir
133 ks = KSWriter(options.configsfile, options.repofile, outdir)
134 repo_meta = yaml.load(ks.repo_stream)
135 image_meta = yaml.load(ks.image_stream)
136 r = repo_meta['Repositories']
137 for img in image_meta['Configurations']:
139 ks.process_files(conf, r)