diff options
-rw-r--r-- | kswriter/KSWriter.py | 104 | ||||
-rw-r--r-- | kswriter/__init__.py | 1 | ||||
-rw-r--r-- | setup.py | 2 | ||||
-rwxr-xr-x | tools/kickstarter | 111 |
4 files changed, 112 insertions, 106 deletions
diff --git a/kswriter/KSWriter.py b/kswriter/KSWriter.py new file mode 100644 index 0000000..46afe04 --- /dev/null +++ b/kswriter/KSWriter.py @@ -0,0 +1,104 @@ +#!/usr/bin/python + +import copy +import time +import yaml +import os +import sys + +class KSWriter(): + def __init__(self, im, rep, out): + self.image_filename = im + self.repo_filename = rep + self.outdir = out + self.image_stream = file(self.image_filename, 'r') + self.repo_stream = file(self.repo_filename, 'r') + self.extra = {} + self.repo_meta = yaml.load(self.repo_stream) + self.image_meta = yaml.load(self.image_stream) + + pass + def merge(*input): + return list(reduce(set.union, input, set())) + + def dump(self): + print yaml.dump(yaml.load(self.stream)) + + def parse(self, img): + conf = copy.copy(self.image_meta['Default']) + plat = copy.copy(self.image_meta[img['Platform']]) + conf.update(plat) + conf.update(img) + lval = ['Repos', 'Groups', 'PostScripts', 'NoChrootScripts', 'RemovePackages', 'ExtraPackages'] + lvald = {} + for l in lval: + full = [] + if self.image_meta['Default'].has_key(l) and self.image_meta['Default'][l]: + full = full + self.image_meta['Default'][l] + if plat.has_key(l) and plat[l]: + full = full + plat[l] + if img.has_key(l) and img[l]: + full = full + img[l] + lvald[l] = sorted(set(full), key=full.index) + #print full + conf.update(lvald) + #print conf + postscript = "" + for scr in conf['PostScripts']: + if os.path.exists('./custom/scripts/%s.post' %scr): + f = open('./custom/scripts/%s.post' %scr, 'r') + postscript += f.read() + postscript += "\n" + f.close() + else: + print './custom/scripts/%s.post not found, skipping.' %scr + + nochrootscript = "" + for scr in conf['NoChrootScripts']: + if os.path.exists('./custom/scripts/%s.nochroot' %scr): + f = open('./custom/scripts/%s.nochroot' %scr, 'r') + nochrootscript += f.read() + nochrootscript += "\n" + f.close() + else: + print './custom/scripts/%s.nochroot not found, skipping.' %scr + + ptab = "" + for g in [ plat, img ]: + if g.has_key("Part"): + f = open("./custom/part/%s" %g['Part'] ) + ptab = f.read() + f.close() + + conf['Part'] = ptab + conf['Post'] = postscript + conf['NoChroot'] = nochrootscript + return conf + + def process_files(self, meta, repos): + new_repos = [] + if meta.has_key("Architecture") and meta['Architecture']: + for repo in repos: + r = {} + r['Name'] = repo['Name'] + if repo.has_key('Options'): + r['Options'] = repo['Options'] + r['Url'] = repo['Url'].replace("@ARCH@", meta['Architecture']) + r['Url'] = r['Url'].replace("@RELEASE@", meta['Baseline']) + new_repos.append(r) + else: + new_repos = repos + + nameSpace = {'metadata': meta, 'repos': new_repos} + t = kickstart(searchList=[nameSpace]) + a = str(t) + if meta.has_key('FileName') and meta['FileName']: + f = None + if meta.has_key("Baseline"): + mkdir_p(meta['Baseline']) + f = open("%s/%s/%s.ks" %( self.outdir, meta['Baseline'], meta['FileName'] ), 'w') + else: + f = open("%s/%s.ks" %( self.outdir, meta['FileName'] ), 'w') + f.write(a) + f.close() + diff --git a/kswriter/__init__.py b/kswriter/__init__.py new file mode 100644 index 0000000..82212cb --- /dev/null +++ b/kswriter/__init__.py @@ -0,0 +1 @@ +from KSWriter import KSWriter @@ -15,6 +15,6 @@ setup(name='kickstarter', author_email='anas.nashif@intel.com', url='http://meego.com/', scripts=['tools/kickstarter'], - packages=['kickstart'] + packages=['kickstart', 'kswriter'] ) diff --git a/tools/kickstarter b/tools/kickstarter index 1ec2790..87639ff 100755 --- a/tools/kickstarter +++ b/tools/kickstarter @@ -3,6 +3,7 @@ import yaml, sys import re, os from kickstart import kickstart +from kswriter import KSWriter import copy import time @@ -38,103 +39,6 @@ def mkdir_p(path): pass else: raise - -class KSWriter(): - def __init__(self, im, rep, out): - self.image_filename = im - self.repo_filename = rep - self.outdir = out - self.image_stream = file(self.image_filename, 'r') - self.repo_stream = file(self.repo_filename, 'r') - self.extra = {} - pass - def merge(*input): - return list(reduce(set.union, input, set())) - - def dump(self): - print yaml.dump(yaml.load(self.stream)) - - def parse(self, img): - conf = copy.copy(image_meta['Default']) - plat = copy.copy(image_meta[img['Platform']]) - conf.update(plat) - conf.update(img) - lval = ['Repos', 'Groups', 'PostScripts', 'NoChrootScripts', 'RemovePackages', 'ExtraPackages'] - lvald = {} - for l in lval: - full = [] - if image_meta['Default'].has_key(l) and image_meta['Default'][l]: - full = full + image_meta['Default'][l] - if plat.has_key(l) and plat[l]: - full = full + plat[l] - if img.has_key(l) and img[l]: - full = full + img[l] - lvald[l] = sorted(set(full), key=full.index) - #print full - conf.update(lvald) - #print conf - postscript = "" - for scr in conf['PostScripts']: - if os.path.exists('./custom/scripts/%s.post' %scr): - f = open('./custom/scripts/%s.post' %scr, 'r') - postscript += f.read() - postscript += "\n" - f.close() - else: - print './custom/scripts/%s.post not found, skipping.' %scr - - nochrootscript = "" - for scr in conf['NoChrootScripts']: - if os.path.exists('./custom/scripts/%s.nochroot' %scr): - f = open('./custom/scripts/%s.nochroot' %scr, 'r') - nochrootscript += f.read() - nochrootscript += "\n" - f.close() - else: - print './custom/scripts/%s.nochroot not found, skipping.' %scr - - ptab = "" - for g in [ plat, img ]: - if g.has_key("Part"): - f = open("./custom/part/%s" %g['Part'] ) - ptab = f.read() - f.close() - - conf['Part'] = ptab - conf['Post'] = postscript - conf['NoChroot'] = nochrootscript - return conf - - def process_files(self, meta, repos): - new_repos = [] - #print repos - #print meta - if meta.has_key("Architecture") and meta['Architecture']: - for repo in repos: - r = {} - r['Name'] = repo['Name'] - if repo.has_key('Options'): - r['Options'] = repo['Options'] - r['Url'] = repo['Url'].replace("@ARCH@", meta['Architecture']) - r['Url'] = r['Url'].replace("@RELEASE@", meta['Baseline']) - new_repos.append(r) - else: - new_repos = repos - - nameSpace = {'metadata': meta, 'repos': new_repos} - t = kickstart(searchList=[nameSpace]) - a = str(t) - if meta.has_key('FileName') and meta['FileName']: - f = None - if meta.has_key("Baseline"): - mkdir_p(meta['Baseline']) - f = open("%s/%s/%s.ks" %( self.outdir, meta['Baseline'], meta['FileName'] ), 'w') - else: - f = open("%s/%s.ks" %( self.outdir, meta['FileName'] ), 'w') - f.write(a) - f.close() - - def image_xml(root, img): s = etree.Element("config") c = etree.Element('name') @@ -208,12 +112,9 @@ if __name__ == '__main__': outdir = options.outdir ks = KSWriter(options.configsfile, options.repofile, outdir) - repo_meta = yaml.load(ks.repo_stream) - image_meta = yaml.load(ks.image_stream) - - r = repo_meta['Repositories'] - if image_meta.has_key('Configurations'): - for img in image_meta['Configurations']: + r = ks.repo_meta['Repositories'] + if ks.image_meta.has_key('Configurations'): + for img in ks.image_meta['Configurations']: conf = ks.parse(img) if options.config: if img.has_key('FileName') and options.config == img['FileName']: @@ -226,7 +127,7 @@ if __name__ == '__main__': ks.process_files(conf, r) else: print "%s is inactive, not generating %s at this time" %(img['Name'], img['FileName'] ) - for path in image_meta['ExternalConfigs']: + for path in ks.image_meta['ExternalConfigs']: for f in os.listdir(path): if f.endswith('.yaml'): fp = file('%s/%s' %(path, f), 'r') @@ -251,7 +152,7 @@ if __name__ == '__main__': print "WARNING: File '%s' ignored." % (f) if options.indexfile: - str = create_xml(image_meta) + str = create_xml(ks.image_meta) f = open(options.indexfile, 'w') f.write(str) f.close() |