3
3
import yaml , sys
4
4
import re , os
5
5
from kickstart import kickstart
6
+ from kswriter import KSWriter
6
7
7
8
import copy
8
9
import time
@@ -38,103 +39,6 @@ def mkdir_p(path):
38
39
pass
39
40
else : raise
40
41
41
-
42
- class KSWriter ():
43
- def __init__ (self , im , rep , out ):
44
- self .image_filename = im
45
- self .repo_filename = rep
46
- self .outdir = out
47
- self .image_stream = file (self .image_filename , 'r' )
48
- self .repo_stream = file (self .repo_filename , 'r' )
49
- self .extra = {}
50
- pass
51
- def merge (* input ):
52
- return list (reduce (set .union , input , set ()))
53
-
54
- def dump (self ):
55
- print yaml .dump (yaml .load (self .stream ))
56
-
57
- def parse (self , img ):
58
- conf = copy .copy (image_meta ['Default' ])
59
- plat = copy .copy (image_meta [img ['Platform' ]])
60
- conf .update (plat )
61
- conf .update (img )
62
- lval = ['Repos' , 'Groups' , 'PostScripts' , 'NoChrootScripts' , 'RemovePackages' , 'ExtraPackages' ]
63
- lvald = {}
64
- for l in lval :
65
- full = []
66
- if image_meta ['Default' ].has_key (l ) and image_meta ['Default' ][l ]:
67
- full = full + image_meta ['Default' ][l ]
68
- if plat .has_key (l ) and plat [l ]:
69
- full = full + plat [l ]
70
- if img .has_key (l ) and img [l ]:
71
- full = full + img [l ]
72
- lvald [l ] = sorted (set (full ), key = full .index )
73
- #print full
74
- conf .update (lvald )
75
- #print conf
76
- postscript = ""
77
- for scr in conf ['PostScripts' ]:
78
- if os .path .exists ('./custom/scripts/%s.post' % scr ):
79
- f = open ('./custom/scripts/%s.post' % scr , 'r' )
80
- postscript += f .read ()
81
- postscript += "\n "
82
- f .close ()
83
- else :
84
- print './custom/scripts/%s.post not found, skipping.' % scr
85
-
86
- nochrootscript = ""
87
- for scr in conf ['NoChrootScripts' ]:
88
- if os .path .exists ('./custom/scripts/%s.nochroot' % scr ):
89
- f = open ('./custom/scripts/%s.nochroot' % scr , 'r' )
90
- nochrootscript += f .read ()
91
- nochrootscript += "\n "
92
- f .close ()
93
- else :
94
- print './custom/scripts/%s.nochroot not found, skipping.' % scr
95
-
96
- ptab = ""
97
- for g in [ plat , img ]:
98
- if g .has_key ("Part" ):
99
- f = open ("./custom/part/%s" % g ['Part' ] )
100
- ptab = f .read ()
101
- f .close ()
102
-
103
- conf ['Part' ] = ptab
104
- conf ['Post' ] = postscript
105
- conf ['NoChroot' ] = nochrootscript
106
- return conf
107
-
108
- def process_files (self , meta , repos ):
109
- new_repos = []
110
- #print repos
111
- #print meta
112
- if meta .has_key ("Architecture" ) and meta ['Architecture' ]:
113
- for repo in repos :
114
- r = {}
115
- r ['Name' ] = repo ['Name' ]
116
- if repo .has_key ('Options' ):
117
- r ['Options' ] = repo ['Options' ]
118
- r ['Url' ] = repo ['Url' ].replace ("@ARCH@" , meta ['Architecture' ])
119
- r ['Url' ] = r ['Url' ].replace ("@RELEASE@" , meta ['Baseline' ])
120
- new_repos .append (r )
121
- else :
122
- new_repos = repos
123
-
124
- nameSpace = {'metadata' : meta , 'repos' : new_repos }
125
- t = kickstart (searchList = [nameSpace ])
126
- a = str (t )
127
- if meta .has_key ('FileName' ) and meta ['FileName' ]:
128
- f = None
129
- if meta .has_key ("Baseline" ):
130
- mkdir_p (meta ['Baseline' ])
131
- f = open ("%s/%s/%s.ks" % ( self .outdir , meta ['Baseline' ], meta ['FileName' ] ), 'w' )
132
- else :
133
- f = open ("%s/%s.ks" % ( self .outdir , meta ['FileName' ] ), 'w' )
134
- f .write (a )
135
- f .close ()
136
-
137
-
138
42
def image_xml (root , img ):
139
43
s = etree .Element ("config" )
140
44
c = etree .Element ('name' )
@@ -208,12 +112,9 @@ if __name__ == '__main__':
208
112
outdir = options .outdir
209
113
210
114
ks = KSWriter (options .configsfile , options .repofile , outdir )
211
- repo_meta = yaml .load (ks .repo_stream )
212
- image_meta = yaml .load (ks .image_stream )
213
-
214
- r = repo_meta ['Repositories' ]
215
- if image_meta .has_key ('Configurations' ):
216
- for img in image_meta ['Configurations' ]:
115
+ r = ks .repo_meta ['Repositories' ]
116
+ if ks .image_meta .has_key ('Configurations' ):
117
+ for img in ks .image_meta ['Configurations' ]:
217
118
conf = ks .parse (img )
218
119
if options .config :
219
120
if img .has_key ('FileName' ) and options .config == img ['FileName' ]:
@@ -226,7 +127,7 @@ if __name__ == '__main__':
226
127
ks .process_files (conf , r )
227
128
else :
228
129
print "%s is inactive, not generating %s at this time" % (img ['Name' ], img ['FileName' ] )
229
- for path in image_meta ['ExternalConfigs' ]:
130
+ for path in ks . image_meta ['ExternalConfigs' ]:
230
131
for f in os .listdir (path ):
231
132
if f .endswith ('.yaml' ):
232
133
fp = file ('%s/%s' % (path , f ), 'r' )
@@ -251,7 +152,7 @@ if __name__ == '__main__':
251
152
print "WARNING: File '%s' ignored." % (f )
252
153
253
154
if options .indexfile :
254
- str = create_xml (image_meta )
155
+ str = create_xml (ks . image_meta )
255
156
f = open (options .indexfile , 'w' )
256
157
f .write (str )
257
158
f .close ()
0 commit comments