diff options
author | Tom Zanussi <tom.zanussi@linux.intel.com> | 2014-08-08 15:53:52 -0500 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2014-08-11 10:53:12 +0100 |
commit | d8f9d05baee3abd4feb0a5b2f2afe467e919c6b9 (patch) | |
tree | edc6ba90a220ad5bbba41998c3c5c82e1e97760d /scripts/lib/wic/3rdparty/pykickstart | |
parent | a43c1f94205d95c6eb77af2f0a494b4143f9eaf8 (diff) | |
download | poky-d8f9d05baee3abd4feb0a5b2f2afe467e919c6b9.tar.gz |
wic: Rename /mic to /wic
As well as any other stray instances of mic in the codebase that can
be removed.
We don't really need to carry around legacy naming, and the history is
in git.
(From OE-Core rev: 598b120406dc1d2b7e377bd1ab6f0acbef034b22)
Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib/wic/3rdparty/pykickstart')
-rw-r--r-- | scripts/lib/wic/3rdparty/pykickstart/__init__.py | 0 | ||||
-rw-r--r-- | scripts/lib/wic/3rdparty/pykickstart/base.py | 466 | ||||
-rw-r--r-- | scripts/lib/wic/3rdparty/pykickstart/commands/__init__.py | 20 | ||||
-rw-r--r-- | scripts/lib/wic/3rdparty/pykickstart/commands/bootloader.py | 216 | ||||
-rw-r--r-- | scripts/lib/wic/3rdparty/pykickstart/commands/partition.py | 314 | ||||
-rw-r--r-- | scripts/lib/wic/3rdparty/pykickstart/constants.py | 57 | ||||
-rw-r--r-- | scripts/lib/wic/3rdparty/pykickstart/errors.py | 103 | ||||
-rw-r--r-- | scripts/lib/wic/3rdparty/pykickstart/handlers/__init__.py | 0 | ||||
-rw-r--r-- | scripts/lib/wic/3rdparty/pykickstart/handlers/control.py | 46 | ||||
-rw-r--r-- | scripts/lib/wic/3rdparty/pykickstart/handlers/f16.py | 24 | ||||
-rw-r--r-- | scripts/lib/wic/3rdparty/pykickstart/ko.py | 37 | ||||
-rw-r--r-- | scripts/lib/wic/3rdparty/pykickstart/options.py | 204 | ||||
-rw-r--r-- | scripts/lib/wic/3rdparty/pykickstart/parser.py | 702 | ||||
-rw-r--r-- | scripts/lib/wic/3rdparty/pykickstart/sections.py | 244 | ||||
-rw-r--r-- | scripts/lib/wic/3rdparty/pykickstart/version.py | 197 |
15 files changed, 2630 insertions, 0 deletions
diff --git a/scripts/lib/wic/3rdparty/pykickstart/__init__.py b/scripts/lib/wic/3rdparty/pykickstart/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/scripts/lib/wic/3rdparty/pykickstart/__init__.py | |||
diff --git a/scripts/lib/wic/3rdparty/pykickstart/base.py b/scripts/lib/wic/3rdparty/pykickstart/base.py new file mode 100644 index 0000000000..e6c8f56f9d --- /dev/null +++ b/scripts/lib/wic/3rdparty/pykickstart/base.py | |||
@@ -0,0 +1,466 @@ | |||
1 | # | ||
2 | # Chris Lumens <clumens@redhat.com> | ||
3 | # | ||
4 | # Copyright 2006, 2007, 2008 Red Hat, Inc. | ||
5 | # | ||
6 | # This copyrighted material is made available to anyone wishing to use, modify, | ||
7 | # copy, or redistribute it subject to the terms and conditions of the GNU | ||
8 | # General Public License v.2. This program is distributed in the hope that it | ||
9 | # will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the | ||
10 | # implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
11 | # See the GNU General Public License for more details. | ||
12 | # | ||
13 | # You should have received a copy of the GNU General Public License along with | ||
14 | # this program; if not, write to the Free Software Foundation, Inc., 51 | ||
15 | # Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Any Red Hat | ||
16 | # trademarks that are incorporated in the source code or documentation are not | ||
17 | # subject to the GNU General Public License and may only be used or replicated | ||
18 | # with the express permission of Red Hat, Inc. | ||
19 | # | ||
20 | """ | ||
21 | Base classes for creating commands and syntax version object. | ||
22 | |||
23 | This module exports several important base classes: | ||
24 | |||
25 | BaseData - The base abstract class for all data objects. Data objects | ||
26 | are contained within a BaseHandler object. | ||
27 | |||
28 | BaseHandler - The base abstract class from which versioned kickstart | ||
29 | handler are derived. Subclasses of BaseHandler hold | ||
30 | BaseData and KickstartCommand objects. | ||
31 | |||
32 | DeprecatedCommand - An abstract subclass of KickstartCommand that should | ||
33 | be further subclassed by users of this module. When | ||
34 | a subclass is used, a warning message will be | ||
35 | printed. | ||
36 | |||
37 | KickstartCommand - The base abstract class for all kickstart commands. | ||
38 | Command objects are contained within a BaseHandler | ||
39 | object. | ||
40 | """ | ||
41 | import gettext | ||
42 | gettext.textdomain("pykickstart") | ||
43 | _ = lambda x: gettext.ldgettext("pykickstart", x) | ||
44 | |||
45 | import types | ||
46 | import warnings | ||
47 | from pykickstart.errors import * | ||
48 | from pykickstart.ko import * | ||
49 | from pykickstart.parser import Packages | ||
50 | from pykickstart.version import versionToString | ||
51 | |||
52 | ### | ||
53 | ### COMMANDS | ||
54 | ### | ||
55 | class KickstartCommand(KickstartObject): | ||
56 | """The base class for all kickstart commands. This is an abstract class.""" | ||
57 | removedKeywords = [] | ||
58 | removedAttrs = [] | ||
59 | |||
60 | def __init__(self, writePriority=0, *args, **kwargs): | ||
61 | """Create a new KickstartCommand instance. This method must be | ||
62 | provided by all subclasses, but subclasses must call | ||
63 | KickstartCommand.__init__ first. Instance attributes: | ||
64 | |||
65 | currentCmd -- The name of the command in the input file that | ||
66 | caused this handler to be run. | ||
67 | currentLine -- The current unprocessed line from the input file | ||
68 | that caused this handler to be run. | ||
69 | handler -- A reference to the BaseHandler subclass this | ||
70 | command is contained withing. This is needed to | ||
71 | allow referencing of Data objects. | ||
72 | lineno -- The current line number in the input file. | ||
73 | writePriority -- An integer specifying when this command should be | ||
74 | printed when iterating over all commands' __str__ | ||
75 | methods. The higher the number, the later this | ||
76 | command will be written. All commands with the | ||
77 | same priority will be written alphabetically. | ||
78 | """ | ||
79 | |||
80 | # We don't want people using this class by itself. | ||
81 | if self.__class__ is KickstartCommand: | ||
82 | raise TypeError, "KickstartCommand is an abstract class." | ||
83 | |||
84 | KickstartObject.__init__(self, *args, **kwargs) | ||
85 | |||
86 | self.writePriority = writePriority | ||
87 | |||
88 | # These will be set by the dispatcher. | ||
89 | self.currentCmd = "" | ||
90 | self.currentLine = "" | ||
91 | self.handler = None | ||
92 | self.lineno = 0 | ||
93 | |||
94 | # If a subclass provides a removedKeywords list, remove all the | ||
95 | # members from the kwargs list before we start processing it. This | ||
96 | # ensures that subclasses don't continue to recognize arguments that | ||
97 | # were removed. | ||
98 | for arg in filter(kwargs.has_key, self.removedKeywords): | ||
99 | kwargs.pop(arg) | ||
100 | |||
101 | def __call__(self, *args, **kwargs): | ||
102 | """Set multiple attributes on a subclass of KickstartCommand at once | ||
103 | via keyword arguments. Valid attributes are anything specified in | ||
104 | a subclass, but unknown attributes will be ignored. | ||
105 | """ | ||
106 | for (key, val) in kwargs.items(): | ||
107 | # Ignore setting attributes that were removed in a subclass, as | ||
108 | # if they were unknown attributes. | ||
109 | if key in self.removedAttrs: | ||
110 | continue | ||
111 | |||
112 | if hasattr(self, key): | ||
113 | setattr(self, key, val) | ||
114 | |||
115 | def __str__(self): | ||
116 | """Return a string formatted for output to a kickstart file. This | ||
117 | method must be provided by all subclasses. | ||
118 | """ | ||
119 | return KickstartObject.__str__(self) | ||
120 | |||
121 | def parse(self, args): | ||
122 | """Parse the list of args and set data on the KickstartCommand object. | ||
123 | This method must be provided by all subclasses. | ||
124 | """ | ||
125 | raise TypeError, "parse() not implemented for KickstartCommand" | ||
126 | |||
127 | def apply(self, instroot="/"): | ||
128 | """Write out the configuration related to the KickstartCommand object. | ||
129 | Subclasses which do not provide this method will not have their | ||
130 | configuration written out. | ||
131 | """ | ||
132 | return | ||
133 | |||
134 | def dataList(self): | ||
135 | """For commands that can occur multiple times in a single kickstart | ||
136 | file (like network, part, etc.), return the list that we should | ||
137 | append more data objects to. | ||
138 | """ | ||
139 | return None | ||
140 | |||
141 | def deleteRemovedAttrs(self): | ||
142 | """Remove all attributes from self that are given in the removedAttrs | ||
143 | list. This method should be called from __init__ in a subclass, | ||
144 | but only after the superclass's __init__ method has been called. | ||
145 | """ | ||
146 | for attr in filter(lambda k: hasattr(self, k), self.removedAttrs): | ||
147 | delattr(self, attr) | ||
148 | |||
149 | # Set the contents of the opts object (an instance of optparse.Values | ||
150 | # returned by parse_args) as attributes on the KickstartCommand object. | ||
151 | # It's useful to call this from KickstartCommand subclasses after parsing | ||
152 | # the arguments. | ||
153 | def _setToSelf(self, optParser, opts): | ||
154 | self._setToObj(optParser, opts, self) | ||
155 | |||
156 | # Sets the contents of the opts object (an instance of optparse.Values | ||
157 | # returned by parse_args) as attributes on the provided object obj. It's | ||
158 | # useful to call this from KickstartCommand subclasses that handle lists | ||
159 | # of objects (like partitions, network devices, etc.) and need to populate | ||
160 | # a Data object. | ||
161 | def _setToObj(self, optParser, opts, obj): | ||
162 | for key in filter (lambda k: getattr(opts, k) != None, optParser.keys()): | ||
163 | setattr(obj, key, getattr(opts, key)) | ||
164 | |||
165 | class DeprecatedCommand(KickstartCommand): | ||
166 | """Specify that a command is deprecated and no longer has any function. | ||
167 | Any command that is deprecated should be subclassed from this class, | ||
168 | only specifying an __init__ method that calls the superclass's __init__. | ||
169 | This is an abstract class. | ||
170 | """ | ||
171 | def __init__(self, writePriority=None, *args, **kwargs): | ||
172 | # We don't want people using this class by itself. | ||
173 | if self.__class__ is KickstartCommand: | ||
174 | raise TypeError, "DeprecatedCommand is an abstract class." | ||
175 | |||
176 | # Create a new DeprecatedCommand instance. | ||
177 | KickstartCommand.__init__(self, writePriority, *args, **kwargs) | ||
178 | |||
179 | def __str__(self): | ||
180 | """Placeholder since DeprecatedCommands don't work anymore.""" | ||
181 | return "" | ||
182 | |||
183 | def parse(self, args): | ||
184 | """Print a warning message if the command is seen in the input file.""" | ||
185 | mapping = {"lineno": self.lineno, "cmd": self.currentCmd} | ||
186 | warnings.warn(_("Ignoring deprecated command on line %(lineno)s: The %(cmd)s command has been deprecated and no longer has any effect. It may be removed from future releases, which will result in a fatal error from kickstart. Please modify your kickstart file to remove this command.") % mapping, DeprecationWarning) | ||
187 | |||
188 | |||
189 | ### | ||
190 | ### HANDLERS | ||
191 | ### | ||
192 | class BaseHandler(KickstartObject): | ||
193 | """Each version of kickstart syntax is provided by a subclass of this | ||
194 | class. These subclasses are what users will interact with for parsing, | ||
195 | extracting data, and writing out kickstart files. This is an abstract | ||
196 | class. | ||
197 | |||
198 | version -- The version this syntax handler supports. This is set by | ||
199 | a class attribute of a BaseHandler subclass and is used to | ||
200 | set up the command dict. It is for read-only use. | ||
201 | """ | ||
202 | version = None | ||
203 | |||
204 | def __init__(self, mapping=None, dataMapping=None, commandUpdates=None, | ||
205 | dataUpdates=None, *args, **kwargs): | ||
206 | """Create a new BaseHandler instance. This method must be provided by | ||
207 | all subclasses, but subclasses must call BaseHandler.__init__ first. | ||
208 | |||
209 | mapping -- A custom map from command strings to classes, | ||
210 | useful when creating your own handler with | ||
211 | special command objects. It is otherwise unused | ||
212 | and rarely needed. If you give this argument, | ||
213 | the mapping takes the place of the default one | ||
214 | and so must include all commands you want | ||
215 | recognized. | ||
216 | dataMapping -- This is the same as mapping, but for data | ||
217 | objects. All the same comments apply. | ||
218 | commandUpdates -- This is similar to mapping, but does not take | ||
219 | the place of the defaults entirely. Instead, | ||
220 | this mapping is applied after the defaults and | ||
221 | updates it with just the commands you want to | ||
222 | modify. | ||
223 | dataUpdates -- This is the same as commandUpdates, but for | ||
224 | data objects. | ||
225 | |||
226 | |||
227 | Instance attributes: | ||
228 | |||
229 | commands -- A mapping from a string command to a KickstartCommand | ||
230 | subclass object that handles it. Multiple strings can | ||
231 | map to the same object, but only one instance of the | ||
232 | command object should ever exist. Most users should | ||
233 | never have to deal with this directly, as it is | ||
234 | manipulated internally and called through dispatcher. | ||
235 | currentLine -- The current unprocessed line from the input file | ||
236 | that caused this handler to be run. | ||
237 | packages -- An instance of pykickstart.parser.Packages which | ||
238 | describes the packages section of the input file. | ||
239 | platform -- A string describing the hardware platform, which is | ||
240 | needed only by system-config-kickstart. | ||
241 | scripts -- A list of pykickstart.parser.Script instances, which is | ||
242 | populated by KickstartParser.addScript and describes the | ||
243 | %pre/%post/%traceback script section of the input file. | ||
244 | """ | ||
245 | |||
246 | # We don't want people using this class by itself. | ||
247 | if self.__class__ is BaseHandler: | ||
248 | raise TypeError, "BaseHandler is an abstract class." | ||
249 | |||
250 | KickstartObject.__init__(self, *args, **kwargs) | ||
251 | |||
252 | # This isn't really a good place for these, but it's better than | ||
253 | # everything else I can think of. | ||
254 | self.scripts = [] | ||
255 | self.packages = Packages() | ||
256 | self.platform = "" | ||
257 | |||
258 | # These will be set by the dispatcher. | ||
259 | self.commands = {} | ||
260 | self.currentLine = 0 | ||
261 | |||
262 | # A dict keyed by an integer priority number, with each value being a | ||
263 | # list of KickstartCommand subclasses. This dict is maintained by | ||
264 | # registerCommand and used in __str__. No one else should be touching | ||
265 | # it. | ||
266 | self._writeOrder = {} | ||
267 | |||
268 | self._registerCommands(mapping, dataMapping, commandUpdates, dataUpdates) | ||
269 | |||
270 | def __str__(self): | ||
271 | """Return a string formatted for output to a kickstart file.""" | ||
272 | retval = "" | ||
273 | |||
274 | if self.platform != "": | ||
275 | retval += "#platform=%s\n" % self.platform | ||
276 | |||
277 | retval += "#version=%s\n" % versionToString(self.version) | ||
278 | |||
279 | lst = self._writeOrder.keys() | ||
280 | lst.sort() | ||
281 | |||
282 | for prio in lst: | ||
283 | for obj in self._writeOrder[prio]: | ||
284 | retval += obj.__str__() | ||
285 | |||
286 | for script in self.scripts: | ||
287 | retval += script.__str__() | ||
288 | |||
289 | retval += self.packages.__str__() | ||
290 | |||
291 | return retval | ||
292 | |||
293 | def _insertSorted(self, lst, obj): | ||
294 | length = len(lst) | ||
295 | i = 0 | ||
296 | |||
297 | while i < length: | ||
298 | # If the two classes have the same name, it's because we are | ||
299 | # overriding an existing class with one from a later kickstart | ||
300 | # version, so remove the old one in favor of the new one. | ||
301 | if obj.__class__.__name__ > lst[i].__class__.__name__: | ||
302 | i += 1 | ||
303 | elif obj.__class__.__name__ == lst[i].__class__.__name__: | ||
304 | lst[i] = obj | ||
305 | return | ||
306 | elif obj.__class__.__name__ < lst[i].__class__.__name__: | ||
307 | break | ||
308 | |||
309 | if i >= length: | ||
310 | lst.append(obj) | ||
311 | else: | ||
312 | lst.insert(i, obj) | ||
313 | |||
314 | def _setCommand(self, cmdObj): | ||
315 | # Add an attribute on this version object. We need this to provide a | ||
316 | # way for clients to access the command objects. We also need to strip | ||
317 | # off the version part from the front of the name. | ||
318 | if cmdObj.__class__.__name__.find("_") != -1: | ||
319 | name = unicode(cmdObj.__class__.__name__.split("_", 1)[1]) | ||
320 | else: | ||
321 | name = unicode(cmdObj.__class__.__name__).lower() | ||
322 | |||
323 | setattr(self, name.lower(), cmdObj) | ||
324 | |||
325 | # Also, add the object into the _writeOrder dict in the right place. | ||
326 | if cmdObj.writePriority is not None: | ||
327 | if self._writeOrder.has_key(cmdObj.writePriority): | ||
328 | self._insertSorted(self._writeOrder[cmdObj.writePriority], cmdObj) | ||
329 | else: | ||
330 | self._writeOrder[cmdObj.writePriority] = [cmdObj] | ||
331 | |||
332 | def _registerCommands(self, mapping=None, dataMapping=None, commandUpdates=None, | ||
333 | dataUpdates=None): | ||
334 | if mapping == {} or mapping == None: | ||
335 | from pykickstart.handlers.control import commandMap | ||
336 | cMap = commandMap[self.version] | ||
337 | else: | ||
338 | cMap = mapping | ||
339 | |||
340 | if dataMapping == {} or dataMapping == None: | ||
341 | from pykickstart.handlers.control import dataMap | ||
342 | dMap = dataMap[self.version] | ||
343 | else: | ||
344 | dMap = dataMapping | ||
345 | |||
346 | if type(commandUpdates) == types.DictType: | ||
347 | cMap.update(commandUpdates) | ||
348 | |||
349 | if type(dataUpdates) == types.DictType: | ||
350 | dMap.update(dataUpdates) | ||
351 | |||
352 | for (cmdName, cmdClass) in cMap.iteritems(): | ||
353 | # First make sure we haven't instantiated this command handler | ||
354 | # already. If we have, we just need to make another mapping to | ||
355 | # it in self.commands. | ||
356 | cmdObj = None | ||
357 | |||
358 | for (key, val) in self.commands.iteritems(): | ||
359 | if val.__class__.__name__ == cmdClass.__name__: | ||
360 | cmdObj = val | ||
361 | break | ||
362 | |||
363 | # If we didn't find an instance in self.commands, create one now. | ||
364 | if cmdObj == None: | ||
365 | cmdObj = cmdClass() | ||
366 | self._setCommand(cmdObj) | ||
367 | |||
368 | # Finally, add the mapping to the commands dict. | ||
369 | self.commands[cmdName] = cmdObj | ||
370 | self.commands[cmdName].handler = self | ||
371 | |||
372 | # We also need to create attributes for the various data objects. | ||
373 | # No checks here because dMap is a bijection. At least, that's what | ||
374 | # the comment says. Hope no one screws that up. | ||
375 | for (dataName, dataClass) in dMap.iteritems(): | ||
376 | setattr(self, dataName, dataClass) | ||
377 | |||
378 | def dispatcher(self, args, lineno): | ||
379 | """Call the appropriate KickstartCommand handler for the current line | ||
380 | in the kickstart file. A handler for the current command should | ||
381 | be registered, though a handler of None is not an error. Returns | ||
382 | the data object returned by KickstartCommand.parse. | ||
383 | |||
384 | args -- A list of arguments to the current command | ||
385 | lineno -- The line number in the file, for error reporting | ||
386 | """ | ||
387 | cmd = args[0] | ||
388 | |||
389 | if not self.commands.has_key(cmd): | ||
390 | raise KickstartParseError, formatErrorMsg(lineno, msg=_("Unknown command: %s" % cmd)) | ||
391 | elif self.commands[cmd] != None: | ||
392 | self.commands[cmd].currentCmd = cmd | ||
393 | self.commands[cmd].currentLine = self.currentLine | ||
394 | self.commands[cmd].lineno = lineno | ||
395 | |||
396 | # The parser returns the data object that was modified. This could | ||
397 | # be a BaseData subclass that should be put into a list, or it | ||
398 | # could be the command handler object itself. | ||
399 | obj = self.commands[cmd].parse(args[1:]) | ||
400 | lst = self.commands[cmd].dataList() | ||
401 | if lst is not None: | ||
402 | lst.append(obj) | ||
403 | |||
404 | return obj | ||
405 | |||
406 | def maskAllExcept(self, lst): | ||
407 | """Set all entries in the commands dict to None, except the ones in | ||
408 | the lst. All other commands will not be processed. | ||
409 | """ | ||
410 | self._writeOrder = {} | ||
411 | |||
412 | for (key, val) in self.commands.iteritems(): | ||
413 | if not key in lst: | ||
414 | self.commands[key] = None | ||
415 | |||
416 | def hasCommand(self, cmd): | ||
417 | """Return true if there is a handler for the string cmd.""" | ||
418 | return hasattr(self, cmd) | ||
419 | |||
420 | |||
421 | ### | ||
422 | ### DATA | ||
423 | ### | ||
424 | class BaseData(KickstartObject): | ||
425 | """The base class for all data objects. This is an abstract class.""" | ||
426 | removedKeywords = [] | ||
427 | removedAttrs = [] | ||
428 | |||
429 | def __init__(self, *args, **kwargs): | ||
430 | """Create a new BaseData instance. | ||
431 | |||
432 | lineno -- Line number in the ks-file where this object was defined | ||
433 | """ | ||
434 | |||
435 | # We don't want people using this class by itself. | ||
436 | if self.__class__ is BaseData: | ||
437 | raise TypeError, "BaseData is an abstract class." | ||
438 | |||
439 | KickstartObject.__init__(self, *args, **kwargs) | ||
440 | self.lineno = 0 | ||
441 | |||
442 | def __str__(self): | ||
443 | """Return a string formatted for output to a kickstart file.""" | ||
444 | return "" | ||
445 | |||
446 | def __call__(self, *args, **kwargs): | ||
447 | """Set multiple attributes on a subclass of BaseData at once via | ||
448 | keyword arguments. Valid attributes are anything specified in a | ||
449 | subclass, but unknown attributes will be ignored. | ||
450 | """ | ||
451 | for (key, val) in kwargs.items(): | ||
452 | # Ignore setting attributes that were removed in a subclass, as | ||
453 | # if they were unknown attributes. | ||
454 | if key in self.removedAttrs: | ||
455 | continue | ||
456 | |||
457 | if hasattr(self, key): | ||
458 | setattr(self, key, val) | ||
459 | |||
460 | def deleteRemovedAttrs(self): | ||
461 | """Remove all attributes from self that are given in the removedAttrs | ||
462 | list. This method should be called from __init__ in a subclass, | ||
463 | but only after the superclass's __init__ method has been called. | ||
464 | """ | ||
465 | for attr in filter(lambda k: hasattr(self, k), self.removedAttrs): | ||
466 | delattr(self, attr) | ||
diff --git a/scripts/lib/wic/3rdparty/pykickstart/commands/__init__.py b/scripts/lib/wic/3rdparty/pykickstart/commands/__init__.py new file mode 100644 index 0000000000..2d94550935 --- /dev/null +++ b/scripts/lib/wic/3rdparty/pykickstart/commands/__init__.py | |||
@@ -0,0 +1,20 @@ | |||
1 | # | ||
2 | # Chris Lumens <clumens@redhat.com> | ||
3 | # | ||
4 | # Copyright 2009 Red Hat, Inc. | ||
5 | # | ||
6 | # This copyrighted material is made available to anyone wishing to use, modify, | ||
7 | # copy, or redistribute it subject to the terms and conditions of the GNU | ||
8 | # General Public License v.2. This program is distributed in the hope that it | ||
9 | # will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the | ||
10 | # implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
11 | # See the GNU General Public License for more details. | ||
12 | # | ||
13 | # You should have received a copy of the GNU General Public License along with | ||
14 | # this program; if not, write to the Free Software Foundation, Inc., 51 | ||
15 | # Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Any Red Hat | ||
16 | # trademarks that are incorporated in the source code or documentation are not | ||
17 | # subject to the GNU General Public License and may only be used or replicated | ||
18 | # with the express permission of Red Hat, Inc. | ||
19 | # | ||
20 | import bootloader, partition | ||
diff --git a/scripts/lib/wic/3rdparty/pykickstart/commands/bootloader.py b/scripts/lib/wic/3rdparty/pykickstart/commands/bootloader.py new file mode 100644 index 0000000000..c2b552f689 --- /dev/null +++ b/scripts/lib/wic/3rdparty/pykickstart/commands/bootloader.py | |||
@@ -0,0 +1,216 @@ | |||
1 | # | ||
2 | # Chris Lumens <clumens@redhat.com> | ||
3 | # | ||
4 | # Copyright 2007 Red Hat, Inc. | ||
5 | # | ||
6 | # This copyrighted material is made available to anyone wishing to use, modify, | ||
7 | # copy, or redistribute it subject to the terms and conditions of the GNU | ||
8 | # General Public License v.2. This program is distributed in the hope that it | ||
9 | # will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the | ||
10 | # implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
11 | # See the GNU General Public License for more details. | ||
12 | # | ||
13 | # You should have received a copy of the GNU General Public License along with | ||
14 | # this program; if not, write to the Free Software Foundation, Inc., 51 | ||
15 | # Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Any Red Hat | ||
16 | # trademarks that are incorporated in the source code or documentation are not | ||
17 | # subject to the GNU General Public License and may only be used or replicated | ||
18 | # with the express permission of Red Hat, Inc. | ||
19 | # | ||
20 | from pykickstart.base import * | ||
21 | from pykickstart.options import * | ||
22 | |||
23 | class FC3_Bootloader(KickstartCommand): | ||
24 | removedKeywords = KickstartCommand.removedKeywords | ||
25 | removedAttrs = KickstartCommand.removedAttrs | ||
26 | |||
27 | def __init__(self, writePriority=10, *args, **kwargs): | ||
28 | KickstartCommand.__init__(self, writePriority, *args, **kwargs) | ||
29 | self.op = self._getParser() | ||
30 | |||
31 | self.driveorder = kwargs.get("driveorder", []) | ||
32 | self.appendLine = kwargs.get("appendLine", "") | ||
33 | self.forceLBA = kwargs.get("forceLBA", False) | ||
34 | self.linear = kwargs.get("linear", True) | ||
35 | self.location = kwargs.get("location", "") | ||
36 | self.md5pass = kwargs.get("md5pass", "") | ||
37 | self.password = kwargs.get("password", "") | ||
38 | self.upgrade = kwargs.get("upgrade", False) | ||
39 | self.useLilo = kwargs.get("useLilo", False) | ||
40 | |||
41 | self.deleteRemovedAttrs() | ||
42 | |||
43 | def _getArgsAsStr(self): | ||
44 | retval = "" | ||
45 | |||
46 | if self.appendLine != "": | ||
47 | retval += " --append=\"%s\"" % self.appendLine | ||
48 | if self.linear: | ||
49 | retval += " --linear" | ||
50 | if self.location: | ||
51 | retval += " --location=%s" % self.location | ||
52 | if hasattr(self, "forceLBA") and self.forceLBA: | ||
53 | retval += " --lba32" | ||
54 | if self.password != "": | ||
55 | retval += " --password=\"%s\"" % self.password | ||
56 | if self.md5pass != "": | ||
57 | retval += " --md5pass=\"%s\"" % self.md5pass | ||
58 | if self.upgrade: | ||
59 | retval += " --upgrade" | ||
60 | if self.useLilo: | ||
61 | retval += " --useLilo" | ||
62 | if len(self.driveorder) > 0: | ||
63 | retval += " --driveorder=\"%s\"" % ",".join(self.driveorder) | ||
64 | |||
65 | return retval | ||
66 | |||
67 | def __str__(self): | ||
68 | retval = KickstartCommand.__str__(self) | ||
69 | |||
70 | if self.location != "": | ||
71 | retval += "# System bootloader configuration\nbootloader" | ||
72 | retval += self._getArgsAsStr() + "\n" | ||
73 | |||
74 | return retval | ||
75 | |||
76 | def _getParser(self): | ||
77 | def driveorder_cb (option, opt_str, value, parser): | ||
78 | for d in value.split(','): | ||
79 | parser.values.ensure_value(option.dest, []).append(d) | ||
80 | |||
81 | op = KSOptionParser() | ||
82 | op.add_option("--append", dest="appendLine") | ||
83 | op.add_option("--linear", dest="linear", action="store_true", | ||
84 | default=True) | ||
85 | op.add_option("--nolinear", dest="linear", action="store_false") | ||
86 | op.add_option("--location", dest="location", type="choice", | ||
87 | default="mbr", | ||
88 | choices=["mbr", "partition", "none", "boot"]) | ||
89 | op.add_option("--lba32", dest="forceLBA", action="store_true", | ||
90 | default=False) | ||
91 | op.add_option("--password", dest="password", default="") | ||
92 | op.add_option("--md5pass", dest="md5pass", default="") | ||
93 | op.add_option("--upgrade", dest="upgrade", action="store_true", | ||
94 | default=False) | ||
95 | op.add_option("--useLilo", dest="useLilo", action="store_true", | ||
96 | default=False) | ||
97 | op.add_option("--driveorder", dest="driveorder", action="callback", | ||
98 | callback=driveorder_cb, nargs=1, type="string") | ||
99 | return op | ||
100 | |||
101 | def parse(self, args): | ||
102 | (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno) | ||
103 | self._setToSelf(self.op, opts) | ||
104 | |||
105 | if self.currentCmd == "lilo": | ||
106 | self.useLilo = True | ||
107 | |||
108 | return self | ||
109 | |||
110 | class FC4_Bootloader(FC3_Bootloader): | ||
111 | removedKeywords = FC3_Bootloader.removedKeywords + ["linear", "useLilo"] | ||
112 | removedAttrs = FC3_Bootloader.removedAttrs + ["linear", "useLilo"] | ||
113 | |||
114 | def __init__(self, writePriority=10, *args, **kwargs): | ||
115 | FC3_Bootloader.__init__(self, writePriority, *args, **kwargs) | ||
116 | |||
117 | def _getArgsAsStr(self): | ||
118 | retval = "" | ||
119 | if self.appendLine != "": | ||
120 | retval += " --append=\"%s\"" % self.appendLine | ||
121 | if self.location: | ||
122 | retval += " --location=%s" % self.location | ||
123 | if hasattr(self, "forceLBA") and self.forceLBA: | ||
124 | retval += " --lba32" | ||
125 | if self.password != "": | ||
126 | retval += " --password=\"%s\"" % self.password | ||
127 | if self.md5pass != "": | ||
128 | retval += " --md5pass=\"%s\"" % self.md5pass | ||
129 | if self.upgrade: | ||
130 | retval += " --upgrade" | ||
131 | if len(self.driveorder) > 0: | ||
132 | retval += " --driveorder=\"%s\"" % ",".join(self.driveorder) | ||
133 | return retval | ||
134 | |||
135 | def _getParser(self): | ||
136 | op = FC3_Bootloader._getParser(self) | ||
137 | op.remove_option("--linear") | ||
138 | op.remove_option("--nolinear") | ||
139 | op.remove_option("--useLilo") | ||
140 | return op | ||
141 | |||
142 | def parse(self, args): | ||
143 | (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno) | ||
144 | self._setToSelf(self.op, opts) | ||
145 | return self | ||
146 | |||
147 | class F8_Bootloader(FC4_Bootloader): | ||
148 | removedKeywords = FC4_Bootloader.removedKeywords | ||
149 | removedAttrs = FC4_Bootloader.removedAttrs | ||
150 | |||
151 | def __init__(self, writePriority=10, *args, **kwargs): | ||
152 | FC4_Bootloader.__init__(self, writePriority, *args, **kwargs) | ||
153 | |||
154 | self.timeout = kwargs.get("timeout", None) | ||
155 | self.default = kwargs.get("default", "") | ||
156 | |||
157 | def _getArgsAsStr(self): | ||
158 | ret = FC4_Bootloader._getArgsAsStr(self) | ||
159 | |||
160 | if self.timeout is not None: | ||
161 | ret += " --timeout=%d" %(self.timeout,) | ||
162 | if self.default: | ||
163 | ret += " --default=%s" %(self.default,) | ||
164 | |||
165 | return ret | ||
166 | |||
167 | def _getParser(self): | ||
168 | op = FC4_Bootloader._getParser(self) | ||
169 | op.add_option("--timeout", dest="timeout", type="int") | ||
170 | op.add_option("--default", dest="default") | ||
171 | return op | ||
172 | |||
173 | class F12_Bootloader(F8_Bootloader): | ||
174 | removedKeywords = F8_Bootloader.removedKeywords | ||
175 | removedAttrs = F8_Bootloader.removedAttrs | ||
176 | |||
177 | def _getParser(self): | ||
178 | op = F8_Bootloader._getParser(self) | ||
179 | op.add_option("--lba32", dest="forceLBA", deprecated=1, action="store_true") | ||
180 | return op | ||
181 | |||
182 | class F14_Bootloader(F12_Bootloader): | ||
183 | removedKeywords = F12_Bootloader.removedKeywords + ["forceLBA"] | ||
184 | removedAttrs = F12_Bootloader.removedKeywords + ["forceLBA"] | ||
185 | |||
186 | def _getParser(self): | ||
187 | op = F12_Bootloader._getParser(self) | ||
188 | op.remove_option("--lba32") | ||
189 | return op | ||
190 | |||
191 | class F15_Bootloader(F14_Bootloader): | ||
192 | removedKeywords = F14_Bootloader.removedKeywords | ||
193 | removedAttrs = F14_Bootloader.removedAttrs | ||
194 | |||
195 | def __init__(self, writePriority=10, *args, **kwargs): | ||
196 | F14_Bootloader.__init__(self, writePriority, *args, **kwargs) | ||
197 | |||
198 | self.isCrypted = kwargs.get("isCrypted", False) | ||
199 | |||
200 | def _getArgsAsStr(self): | ||
201 | ret = F14_Bootloader._getArgsAsStr(self) | ||
202 | |||
203 | if self.isCrypted: | ||
204 | ret += " --iscrypted" | ||
205 | |||
206 | return ret | ||
207 | |||
208 | def _getParser(self): | ||
209 | def password_cb(option, opt_str, value, parser): | ||
210 | parser.values.isCrypted = True | ||
211 | parser.values.password = value | ||
212 | |||
213 | op = F14_Bootloader._getParser(self) | ||
214 | op.add_option("--iscrypted", dest="isCrypted", action="store_true", default=False) | ||
215 | op.add_option("--md5pass", action="callback", callback=password_cb, nargs=1, type="string") | ||
216 | return op | ||
diff --git a/scripts/lib/wic/3rdparty/pykickstart/commands/partition.py b/scripts/lib/wic/3rdparty/pykickstart/commands/partition.py new file mode 100644 index 0000000000..56b91aa9d9 --- /dev/null +++ b/scripts/lib/wic/3rdparty/pykickstart/commands/partition.py | |||
@@ -0,0 +1,314 @@ | |||
1 | # | ||
2 | # Chris Lumens <clumens@redhat.com> | ||
3 | # | ||
4 | # Copyright 2005, 2006, 2007, 2008 Red Hat, Inc. | ||
5 | # | ||
6 | # This copyrighted material is made available to anyone wishing to use, modify, | ||
7 | # copy, or redistribute it subject to the terms and conditions of the GNU | ||
8 | # General Public License v.2. This program is distributed in the hope that it | ||
9 | # will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the | ||
10 | # implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
11 | # See the GNU General Public License for more details. | ||
12 | # | ||
13 | # You should have received a copy of the GNU General Public License along with | ||
14 | # this program; if not, write to the Free Software Foundation, Inc., 51 | ||
15 | # Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Any Red Hat | ||
16 | # trademarks that are incorporated in the source code or documentation are not | ||
17 | # subject to the GNU General Public License and may only be used or replicated | ||
18 | # with the express permission of Red Hat, Inc. | ||
19 | # | ||
20 | from pykickstart.base import * | ||
21 | from pykickstart.errors import * | ||
22 | from pykickstart.options import * | ||
23 | |||
24 | import gettext | ||
25 | import warnings | ||
26 | _ = lambda x: gettext.ldgettext("pykickstart", x) | ||
27 | |||
28 | class FC3_PartData(BaseData): | ||
29 | removedKeywords = BaseData.removedKeywords | ||
30 | removedAttrs = BaseData.removedAttrs | ||
31 | |||
32 | def __init__(self, *args, **kwargs): | ||
33 | BaseData.__init__(self, *args, **kwargs) | ||
34 | self.active = kwargs.get("active", False) | ||
35 | self.primOnly = kwargs.get("primOnly", False) | ||
36 | self.end = kwargs.get("end", 0) | ||
37 | self.fstype = kwargs.get("fstype", "") | ||
38 | self.grow = kwargs.get("grow", False) | ||
39 | self.maxSizeMB = kwargs.get("maxSizeMB", 0) | ||
40 | self.format = kwargs.get("format", True) | ||
41 | self.onbiosdisk = kwargs.get("onbiosdisk", "") | ||
42 | self.disk = kwargs.get("disk", "") | ||
43 | self.onPart = kwargs.get("onPart", "") | ||
44 | self.recommended = kwargs.get("recommended", False) | ||
45 | self.size = kwargs.get("size", None) | ||
46 | self.start = kwargs.get("start", 0) | ||
47 | self.mountpoint = kwargs.get("mountpoint", "") | ||
48 | |||
49 | def __eq__(self, y): | ||
50 | if self.mountpoint: | ||
51 | return self.mountpoint == y.mountpoint | ||
52 | else: | ||
53 | return False | ||
54 | |||
55 | def _getArgsAsStr(self): | ||
56 | retval = "" | ||
57 | |||
58 | if self.active: | ||
59 | retval += " --active" | ||
60 | if self.primOnly: | ||
61 | retval += " --asprimary" | ||
62 | if hasattr(self, "end") and self.end != 0: | ||
63 | retval += " --end=%s" % self.end | ||
64 | if self.fstype != "": | ||
65 | retval += " --fstype=\"%s\"" % self.fstype | ||
66 | if self.grow: | ||
67 | retval += " --grow" | ||
68 | if self.maxSizeMB > 0: | ||
69 | retval += " --maxsize=%d" % self.maxSizeMB | ||
70 | if not self.format: | ||
71 | retval += " --noformat" | ||
72 | if self.onbiosdisk != "": | ||
73 | retval += " --onbiosdisk=%s" % self.onbiosdisk | ||
74 | if self.disk != "": | ||
75 | retval += " --ondisk=%s" % self.disk | ||
76 | if self.onPart != "": | ||
77 | retval += " --onpart=%s" % self.onPart | ||
78 | if self.recommended: | ||
79 | retval += " --recommended" | ||
80 | if self.size and self.size != 0: | ||
81 | retval += " --size=%s" % self.size | ||
82 | if hasattr(self, "start") and self.start != 0: | ||
83 | retval += " --start=%s" % self.start | ||
84 | |||
85 | return retval | ||
86 | |||
87 | def __str__(self): | ||
88 | retval = BaseData.__str__(self) | ||
89 | if self.mountpoint: | ||
90 | mountpoint_str = "%s" % self.mountpoint | ||
91 | else: | ||
92 | mountpoint_str = "(No mount point)" | ||
93 | retval += "part %s%s\n" % (mountpoint_str, self._getArgsAsStr()) | ||
94 | return retval | ||
95 | |||
96 | class FC4_PartData(FC3_PartData): | ||
97 | removedKeywords = FC3_PartData.removedKeywords | ||
98 | removedAttrs = FC3_PartData.removedAttrs | ||
99 | |||
100 | def __init__(self, *args, **kwargs): | ||
101 | FC3_PartData.__init__(self, *args, **kwargs) | ||
102 | self.bytesPerInode = kwargs.get("bytesPerInode", 4096) | ||
103 | self.fsopts = kwargs.get("fsopts", "") | ||
104 | self.label = kwargs.get("label", "") | ||
105 | |||
106 | def _getArgsAsStr(self): | ||
107 | retval = FC3_PartData._getArgsAsStr(self) | ||
108 | |||
109 | if hasattr(self, "bytesPerInode") and self.bytesPerInode != 0: | ||
110 | retval += " --bytes-per-inode=%d" % self.bytesPerInode | ||
111 | if self.fsopts != "": | ||
112 | retval += " --fsoptions=\"%s\"" % self.fsopts | ||
113 | if self.label != "": | ||
114 | retval += " --label=%s" % self.label | ||
115 | |||
116 | return retval | ||
117 | |||
118 | class F9_PartData(FC4_PartData): | ||
119 | removedKeywords = FC4_PartData.removedKeywords + ["bytesPerInode"] | ||
120 | removedAttrs = FC4_PartData.removedAttrs + ["bytesPerInode"] | ||
121 | |||
122 | def __init__(self, *args, **kwargs): | ||
123 | FC4_PartData.__init__(self, *args, **kwargs) | ||
124 | self.deleteRemovedAttrs() | ||
125 | |||
126 | self.fsopts = kwargs.get("fsopts", "") | ||
127 | self.label = kwargs.get("label", "") | ||
128 | self.fsprofile = kwargs.get("fsprofile", "") | ||
129 | self.encrypted = kwargs.get("encrypted", False) | ||
130 | self.passphrase = kwargs.get("passphrase", "") | ||
131 | |||
132 | def _getArgsAsStr(self): | ||
133 | retval = FC4_PartData._getArgsAsStr(self) | ||
134 | |||
135 | if self.fsprofile != "": | ||
136 | retval += " --fsprofile=\"%s\"" % self.fsprofile | ||
137 | if self.encrypted: | ||
138 | retval += " --encrypted" | ||
139 | |||
140 | if self.passphrase != "": | ||
141 | retval += " --passphrase=\"%s\"" % self.passphrase | ||
142 | |||
143 | return retval | ||
144 | |||
145 | class F11_PartData(F9_PartData): | ||
146 | removedKeywords = F9_PartData.removedKeywords + ["start", "end"] | ||
147 | removedAttrs = F9_PartData.removedAttrs + ["start", "end"] | ||
148 | |||
149 | class F12_PartData(F11_PartData): | ||
150 | removedKeywords = F11_PartData.removedKeywords | ||
151 | removedAttrs = F11_PartData.removedAttrs | ||
152 | |||
153 | def __init__(self, *args, **kwargs): | ||
154 | F11_PartData.__init__(self, *args, **kwargs) | ||
155 | |||
156 | self.escrowcert = kwargs.get("escrowcert", "") | ||
157 | self.backuppassphrase = kwargs.get("backuppassphrase", False) | ||
158 | |||
159 | def _getArgsAsStr(self): | ||
160 | retval = F11_PartData._getArgsAsStr(self) | ||
161 | |||
162 | if self.encrypted and self.escrowcert != "": | ||
163 | retval += " --escrowcert=\"%s\"" % self.escrowcert | ||
164 | |||
165 | if self.backuppassphrase: | ||
166 | retval += " --backuppassphrase" | ||
167 | |||
168 | return retval | ||
169 | |||
170 | F14_PartData = F12_PartData | ||
171 | |||
172 | class FC3_Partition(KickstartCommand): | ||
173 | removedKeywords = KickstartCommand.removedKeywords | ||
174 | removedAttrs = KickstartCommand.removedAttrs | ||
175 | |||
176 | def __init__(self, writePriority=130, *args, **kwargs): | ||
177 | KickstartCommand.__init__(self, writePriority, *args, **kwargs) | ||
178 | self.op = self._getParser() | ||
179 | |||
180 | self.partitions = kwargs.get("partitions", []) | ||
181 | |||
182 | def __str__(self): | ||
183 | retval = "" | ||
184 | |||
185 | for part in self.partitions: | ||
186 | retval += part.__str__() | ||
187 | |||
188 | if retval != "": | ||
189 | return "# Disk partitioning information\n" + retval | ||
190 | else: | ||
191 | return "" | ||
192 | |||
193 | def _getParser(self): | ||
194 | def part_cb (option, opt_str, value, parser): | ||
195 | if value.startswith("/dev/"): | ||
196 | parser.values.ensure_value(option.dest, value[5:]) | ||
197 | else: | ||
198 | parser.values.ensure_value(option.dest, value) | ||
199 | |||
200 | op = KSOptionParser() | ||
201 | op.add_option("--active", dest="active", action="store_true", | ||
202 | default=False) | ||
203 | op.add_option("--asprimary", dest="primOnly", action="store_true", | ||
204 | default=False) | ||
205 | op.add_option("--end", dest="end", action="store", type="int", | ||
206 | nargs=1) | ||
207 | op.add_option("--fstype", "--type", dest="fstype") | ||
208 | op.add_option("--grow", dest="grow", action="store_true", default=False) | ||
209 | op.add_option("--maxsize", dest="maxSizeMB", action="store", type="int", | ||
210 | nargs=1) | ||
211 | op.add_option("--noformat", dest="format", action="store_false", | ||
212 | default=True) | ||
213 | op.add_option("--onbiosdisk", dest="onbiosdisk") | ||
214 | op.add_option("--ondisk", "--ondrive", dest="disk") | ||
215 | op.add_option("--onpart", "--usepart", dest="onPart", action="callback", | ||
216 | callback=part_cb, nargs=1, type="string") | ||
217 | op.add_option("--recommended", dest="recommended", action="store_true", | ||
218 | default=False) | ||
219 | op.add_option("--size", dest="size", action="store", type="int", | ||
220 | nargs=1) | ||
221 | op.add_option("--start", dest="start", action="store", type="int", | ||
222 | nargs=1) | ||
223 | return op | ||
224 | |||
225 | def parse(self, args): | ||
226 | (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno) | ||
227 | |||
228 | pd = self.handler.PartData() | ||
229 | self._setToObj(self.op, opts, pd) | ||
230 | pd.lineno = self.lineno | ||
231 | if extra: | ||
232 | pd.mountpoint = extra[0] | ||
233 | if pd in self.dataList(): | ||
234 | warnings.warn(_("A partition with the mountpoint %s has already been defined.") % pd.mountpoint) | ||
235 | else: | ||
236 | pd.mountpoint = None | ||
237 | |||
238 | return pd | ||
239 | |||
240 | def dataList(self): | ||
241 | return self.partitions | ||
242 | |||
243 | class FC4_Partition(FC3_Partition): | ||
244 | removedKeywords = FC3_Partition.removedKeywords | ||
245 | removedAttrs = FC3_Partition.removedAttrs | ||
246 | |||
247 | def __init__(self, writePriority=130, *args, **kwargs): | ||
248 | FC3_Partition.__init__(self, writePriority, *args, **kwargs) | ||
249 | |||
250 | def part_cb (option, opt_str, value, parser): | ||
251 | if value.startswith("/dev/"): | ||
252 | parser.values.ensure_value(option.dest, value[5:]) | ||
253 | else: | ||
254 | parser.values.ensure_value(option.dest, value) | ||
255 | |||
256 | def _getParser(self): | ||
257 | op = FC3_Partition._getParser(self) | ||
258 | op.add_option("--bytes-per-inode", dest="bytesPerInode", action="store", | ||
259 | type="int", nargs=1) | ||
260 | op.add_option("--fsoptions", dest="fsopts") | ||
261 | op.add_option("--label", dest="label") | ||
262 | return op | ||
263 | |||
264 | class F9_Partition(FC4_Partition): | ||
265 | removedKeywords = FC4_Partition.removedKeywords | ||
266 | removedAttrs = FC4_Partition.removedAttrs | ||
267 | |||
268 | def __init__(self, writePriority=130, *args, **kwargs): | ||
269 | FC4_Partition.__init__(self, writePriority, *args, **kwargs) | ||
270 | |||
271 | def part_cb (option, opt_str, value, parser): | ||
272 | if value.startswith("/dev/"): | ||
273 | parser.values.ensure_value(option.dest, value[5:]) | ||
274 | else: | ||
275 | parser.values.ensure_value(option.dest, value) | ||
276 | |||
277 | def _getParser(self): | ||
278 | op = FC4_Partition._getParser(self) | ||
279 | op.add_option("--bytes-per-inode", deprecated=1) | ||
280 | op.add_option("--fsprofile") | ||
281 | op.add_option("--encrypted", action="store_true", default=False) | ||
282 | op.add_option("--passphrase") | ||
283 | return op | ||
284 | |||
285 | class F11_Partition(F9_Partition): | ||
286 | removedKeywords = F9_Partition.removedKeywords | ||
287 | removedAttrs = F9_Partition.removedAttrs | ||
288 | |||
289 | def _getParser(self): | ||
290 | op = F9_Partition._getParser(self) | ||
291 | op.add_option("--start", deprecated=1) | ||
292 | op.add_option("--end", deprecated=1) | ||
293 | return op | ||
294 | |||
295 | class F12_Partition(F11_Partition): | ||
296 | removedKeywords = F11_Partition.removedKeywords | ||
297 | removedAttrs = F11_Partition.removedAttrs | ||
298 | |||
299 | def _getParser(self): | ||
300 | op = F11_Partition._getParser(self) | ||
301 | op.add_option("--escrowcert") | ||
302 | op.add_option("--backuppassphrase", action="store_true", default=False) | ||
303 | return op | ||
304 | |||
305 | class F14_Partition(F12_Partition): | ||
306 | removedKeywords = F12_Partition.removedKeywords | ||
307 | removedAttrs = F12_Partition.removedAttrs | ||
308 | |||
309 | def _getParser(self): | ||
310 | op = F12_Partition._getParser(self) | ||
311 | op.remove_option("--bytes-per-inode") | ||
312 | op.remove_option("--start") | ||
313 | op.remove_option("--end") | ||
314 | return op | ||
diff --git a/scripts/lib/wic/3rdparty/pykickstart/constants.py b/scripts/lib/wic/3rdparty/pykickstart/constants.py new file mode 100644 index 0000000000..5e12fc80ec --- /dev/null +++ b/scripts/lib/wic/3rdparty/pykickstart/constants.py | |||
@@ -0,0 +1,57 @@ | |||
1 | # | ||
2 | # Chris Lumens <clumens@redhat.com> | ||
3 | # | ||
4 | # Copyright 2005-2007 Red Hat, Inc. | ||
5 | # | ||
6 | # This copyrighted material is made available to anyone wishing to use, modify, | ||
7 | # copy, or redistribute it subject to the terms and conditions of the GNU | ||
8 | # General Public License v.2. This program is distributed in the hope that it | ||
9 | # will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the | ||
10 | # implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
11 | # See the GNU General Public License for more details. | ||
12 | # | ||
13 | # You should have received a copy of the GNU General Public License along with | ||
14 | # this program; if not, write to the Free Software Foundation, Inc., 51 | ||
15 | # Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Any Red Hat | ||
16 | # trademarks that are incorporated in the source code or documentation are not | ||
17 | # subject to the GNU General Public License and may only be used or replicated | ||
18 | # with the express permission of Red Hat, Inc. | ||
19 | # | ||
20 | CLEARPART_TYPE_LINUX = 0 | ||
21 | CLEARPART_TYPE_ALL = 1 | ||
22 | CLEARPART_TYPE_NONE = 2 | ||
23 | |||
24 | DISPLAY_MODE_CMDLINE = 0 | ||
25 | DISPLAY_MODE_GRAPHICAL = 1 | ||
26 | DISPLAY_MODE_TEXT = 2 | ||
27 | |||
28 | FIRSTBOOT_DEFAULT = 0 | ||
29 | FIRSTBOOT_SKIP = 1 | ||
30 | FIRSTBOOT_RECONFIG = 2 | ||
31 | |||
32 | KS_MISSING_PROMPT = 0 | ||
33 | KS_MISSING_IGNORE = 1 | ||
34 | |||
35 | SELINUX_DISABLED = 0 | ||
36 | SELINUX_ENFORCING = 1 | ||
37 | SELINUX_PERMISSIVE = 2 | ||
38 | |||
39 | KS_SCRIPT_PRE = 0 | ||
40 | KS_SCRIPT_POST = 1 | ||
41 | KS_SCRIPT_TRACEBACK = 2 | ||
42 | |||
43 | KS_WAIT = 0 | ||
44 | KS_REBOOT = 1 | ||
45 | KS_SHUTDOWN = 2 | ||
46 | |||
47 | KS_INSTKEY_SKIP = -99 | ||
48 | |||
49 | BOOTPROTO_DHCP = "dhcp" | ||
50 | BOOTPROTO_BOOTP = "bootp" | ||
51 | BOOTPROTO_STATIC = "static" | ||
52 | BOOTPROTO_QUERY = "query" | ||
53 | BOOTPROTO_IBFT = "ibft" | ||
54 | |||
55 | GROUP_REQUIRED = 0 | ||
56 | GROUP_DEFAULT = 1 | ||
57 | GROUP_ALL = 2 | ||
diff --git a/scripts/lib/wic/3rdparty/pykickstart/errors.py b/scripts/lib/wic/3rdparty/pykickstart/errors.py new file mode 100644 index 0000000000..a234d99d43 --- /dev/null +++ b/scripts/lib/wic/3rdparty/pykickstart/errors.py | |||
@@ -0,0 +1,103 @@ | |||
1 | # | ||
2 | # errors.py: Kickstart error handling. | ||
3 | # | ||
4 | # Chris Lumens <clumens@redhat.com> | ||
5 | # | ||
6 | # This copyrighted material is made available to anyone wishing to use, modify, | ||
7 | # copy, or redistribute it subject to the terms and conditions of the GNU | ||
8 | # General Public License v.2. This program is distributed in the hope that it | ||
9 | # will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the | ||
10 | # implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
11 | # See the GNU General Public License for more details. | ||
12 | # | ||
13 | # You should have received a copy of the GNU General Public License along with | ||
14 | # this program; if not, write to the Free Software Foundation, Inc., 51 | ||
15 | # Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Any Red Hat | ||
16 | # trademarks that are incorporated in the source code or documentation are not | ||
17 | # subject to the GNU General Public License and may only be used or replicated | ||
18 | # with the express permission of Red Hat, Inc. | ||
19 | # | ||
20 | """ | ||
21 | Error handling classes and functions. | ||
22 | |||
23 | This module exports a single function: | ||
24 | |||
25 | formatErrorMsg - Properly formats an error message. | ||
26 | |||
27 | It also exports several exception classes: | ||
28 | |||
29 | KickstartError - A generic exception class. | ||
30 | |||
31 | KickstartParseError - An exception for errors relating to parsing. | ||
32 | |||
33 | KickstartValueError - An exception for errors relating to option | ||
34 | processing. | ||
35 | |||
36 | KickstartVersionError - An exception for errors relating to unsupported | ||
37 | syntax versions. | ||
38 | """ | ||
39 | import gettext | ||
40 | _ = lambda x: gettext.ldgettext("pykickstart", x) | ||
41 | |||
42 | def formatErrorMsg(lineno, msg=""): | ||
43 | """Properly format the error message msg for inclusion in an exception.""" | ||
44 | if msg != "": | ||
45 | mapping = {"lineno": lineno, "msg": msg} | ||
46 | return _("The following problem occurred on line %(lineno)s of the kickstart file:\n\n%(msg)s\n") % mapping | ||
47 | else: | ||
48 | return _("There was a problem reading from line %s of the kickstart file") % lineno | ||
49 | |||
50 | class KickstartError(Exception): | ||
51 | """A generic exception class for unspecific error conditions.""" | ||
52 | def __init__(self, val = ""): | ||
53 | """Create a new KickstartError exception instance with the descriptive | ||
54 | message val. val should be the return value of formatErrorMsg. | ||
55 | """ | ||
56 | Exception.__init__(self) | ||
57 | self.value = val | ||
58 | |||
59 | def __str__ (self): | ||
60 | return self.value | ||
61 | |||
62 | class KickstartParseError(KickstartError): | ||
63 | """An exception class for errors when processing the input file, such as | ||
64 | unknown options, commands, or sections. | ||
65 | """ | ||
66 | def __init__(self, msg): | ||
67 | """Create a new KickstartParseError exception instance with the | ||
68 | descriptive message val. val should be the return value of | ||
69 | formatErrorMsg. | ||
70 | """ | ||
71 | KickstartError.__init__(self, msg) | ||
72 | |||
73 | def __str__(self): | ||
74 | return self.value | ||
75 | |||
76 | class KickstartValueError(KickstartError): | ||
77 | """An exception class for errors when processing arguments to commands, | ||
78 | such as too many arguments, too few arguments, or missing required | ||
79 | arguments. | ||
80 | """ | ||
81 | def __init__(self, msg): | ||
82 | """Create a new KickstartValueError exception instance with the | ||
83 | descriptive message val. val should be the return value of | ||
84 | formatErrorMsg. | ||
85 | """ | ||
86 | KickstartError.__init__(self, msg) | ||
87 | |||
88 | def __str__ (self): | ||
89 | return self.value | ||
90 | |||
91 | class KickstartVersionError(KickstartError): | ||
92 | """An exception class for errors related to using an incorrect version of | ||
93 | kickstart syntax. | ||
94 | """ | ||
95 | def __init__(self, msg): | ||
96 | """Create a new KickstartVersionError exception instance with the | ||
97 | descriptive message val. val should be the return value of | ||
98 | formatErrorMsg. | ||
99 | """ | ||
100 | KickstartError.__init__(self, msg) | ||
101 | |||
102 | def __str__ (self): | ||
103 | return self.value | ||
diff --git a/scripts/lib/wic/3rdparty/pykickstart/handlers/__init__.py b/scripts/lib/wic/3rdparty/pykickstart/handlers/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/scripts/lib/wic/3rdparty/pykickstart/handlers/__init__.py | |||
diff --git a/scripts/lib/wic/3rdparty/pykickstart/handlers/control.py b/scripts/lib/wic/3rdparty/pykickstart/handlers/control.py new file mode 100644 index 0000000000..8dc80d1ebe --- /dev/null +++ b/scripts/lib/wic/3rdparty/pykickstart/handlers/control.py | |||
@@ -0,0 +1,46 @@ | |||
1 | # | ||
2 | # Chris Lumens <clumens@redhat.com> | ||
3 | # | ||
4 | # Copyright 2007, 2008, 2009, 2010 Red Hat, Inc. | ||
5 | # | ||
6 | # This copyrighted material is made available to anyone wishing to use, modify, | ||
7 | # copy, or redistribute it subject to the terms and conditions of the GNU | ||
8 | # General Public License v.2. This program is distributed in the hope that it | ||
9 | # will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the | ||
10 | # implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
11 | # See the GNU General Public License for more details. | ||
12 | # | ||
13 | # You should have received a copy of the GNU General Public License along with | ||
14 | # this program; if not, write to the Free Software Foundation, Inc., 51 | ||
15 | # Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Any Red Hat | ||
16 | # trademarks that are incorporated in the source code or documentation are not | ||
17 | # subject to the GNU General Public License and may only be used or replicated | ||
18 | # with the express permission of Red Hat, Inc. | ||
19 | # | ||
20 | from pykickstart.version import * | ||
21 | from pykickstart.commands import * | ||
22 | |||
23 | # This map is keyed on kickstart syntax version as provided by | ||
24 | # pykickstart.version. Within each sub-dict is a mapping from command name | ||
25 | # to the class that handles it. This is an onto mapping - that is, multiple | ||
26 | # command names can map to the same class. However, the Handler will ensure | ||
27 | # that only one instance of each class ever exists. | ||
28 | commandMap = { | ||
29 | # based on f15 | ||
30 | F16: { | ||
31 | "bootloader": bootloader.F15_Bootloader, | ||
32 | "part": partition.F14_Partition, | ||
33 | "partition": partition.F14_Partition, | ||
34 | }, | ||
35 | } | ||
36 | |||
37 | # This map is keyed on kickstart syntax version as provided by | ||
38 | # pykickstart.version. Within each sub-dict is a mapping from a data object | ||
39 | # name to the class that provides it. This is a bijective mapping - that is, | ||
40 | # each name maps to exactly one data class and all data classes have a name. | ||
41 | # More than one instance of each class is allowed to exist, however. | ||
42 | dataMap = { | ||
43 | F16: { | ||
44 | "PartData": partition.F14_PartData, | ||
45 | }, | ||
46 | } | ||
diff --git a/scripts/lib/wic/3rdparty/pykickstart/handlers/f16.py b/scripts/lib/wic/3rdparty/pykickstart/handlers/f16.py new file mode 100644 index 0000000000..3c52f8d754 --- /dev/null +++ b/scripts/lib/wic/3rdparty/pykickstart/handlers/f16.py | |||
@@ -0,0 +1,24 @@ | |||
1 | # | ||
2 | # Chris Lumens <clumens@redhat.com> | ||
3 | # | ||
4 | # Copyright 2011 Red Hat, Inc. | ||
5 | # | ||
6 | # This copyrighted material is made available to anyone wishing to use, modify, | ||
7 | # copy, or redistribute it subject to the terms and conditions of the GNU | ||
8 | # General Public License v.2. This program is distributed in the hope that it | ||
9 | # will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the | ||
10 | # implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
11 | # See the GNU General Public License for more details. | ||
12 | # | ||
13 | # You should have received a copy of the GNU General Public License along with | ||
14 | # this program; if not, write to the Free Software Foundation, Inc., 51 | ||
15 | # Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Any Red Hat | ||
16 | # trademarks that are incorporated in the source code or documentation are not | ||
17 | # subject to the GNU General Public License and may only be used or replicated | ||
18 | # with the express permission of Red Hat, Inc. | ||
19 | # | ||
20 | from pykickstart.base import * | ||
21 | from pykickstart.version import * | ||
22 | |||
23 | class F16Handler(BaseHandler): | ||
24 | version = F16 | ||
diff --git a/scripts/lib/wic/3rdparty/pykickstart/ko.py b/scripts/lib/wic/3rdparty/pykickstart/ko.py new file mode 100644 index 0000000000..1350d19c70 --- /dev/null +++ b/scripts/lib/wic/3rdparty/pykickstart/ko.py | |||
@@ -0,0 +1,37 @@ | |||
1 | # | ||
2 | # Chris Lumens <clumens@redhat.com> | ||
3 | # | ||
4 | # Copyright 2009 Red Hat, Inc. | ||
5 | # | ||
6 | # This copyrighted material is made available to anyone wishing to use, modify, | ||
7 | # copy, or redistribute it subject to the terms and conditions of the GNU | ||
8 | # General Public License v.2. This program is distributed in the hope that it | ||
9 | # will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the | ||
10 | # implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
11 | # See the GNU General Public License for more details. | ||
12 | # | ||
13 | # You should have received a copy of the GNU General Public License along with | ||
14 | # this program; if not, write to the Free Software Foundation, Inc., 51 | ||
15 | # Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Any Red Hat | ||
16 | # trademarks that are incorporated in the source code or documentation are not | ||
17 | # subject to the GNU General Public License and may only be used or replicated | ||
18 | # with the express permission of Red Hat, Inc. | ||
19 | # | ||
20 | """ | ||
21 | Base classes for internal pykickstart use. | ||
22 | |||
23 | The module exports the following important classes: | ||
24 | |||
25 | KickstartObject - The base class for all classes in pykickstart | ||
26 | """ | ||
27 | |||
28 | class KickstartObject(object): | ||
29 | """The base class for all other classes in pykickstart.""" | ||
30 | def __init__(self, *args, **kwargs): | ||
31 | """Create a new KickstartObject instance. All other classes in | ||
32 | pykickstart should be derived from this one. Instance attributes: | ||
33 | """ | ||
34 | pass | ||
35 | |||
36 | def __str__(self): | ||
37 | return "" | ||
diff --git a/scripts/lib/wic/3rdparty/pykickstart/options.py b/scripts/lib/wic/3rdparty/pykickstart/options.py new file mode 100644 index 0000000000..341c5d7298 --- /dev/null +++ b/scripts/lib/wic/3rdparty/pykickstart/options.py | |||
@@ -0,0 +1,204 @@ | |||
1 | # | ||
2 | # Chris Lumens <clumens@redhat.com> | ||
3 | # | ||
4 | # Copyright 2005, 2006, 2007 Red Hat, Inc. | ||
5 | # | ||
6 | # This copyrighted material is made available to anyone wishing to use, modify, | ||
7 | # copy, or redistribute it subject to the terms and conditions of the GNU | ||
8 | # General Public License v.2. This program is distributed in the hope that it | ||
9 | # will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the | ||
10 | # implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
11 | # See the GNU General Public License for more details. | ||
12 | # | ||
13 | # You should have received a copy of the GNU General Public License along with | ||
14 | # this program; if not, write to the Free Software Foundation, Inc., 51 | ||
15 | # Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Any Red Hat | ||
16 | # trademarks that are incorporated in the source code or documentation are not | ||
17 | # subject to the GNU General Public License and may only be used or replicated | ||
18 | # with the express permission of Red Hat, Inc. | ||
19 | # | ||
20 | """ | ||
21 | Specialized option handling. | ||
22 | |||
23 | This module exports two classes: | ||
24 | |||
25 | KSOptionParser - A specialized subclass of OptionParser to be used | ||
26 | in BaseHandler subclasses. | ||
27 | |||
28 | KSOption - A specialized subclass of Option. | ||
29 | """ | ||
30 | import warnings | ||
31 | from copy import copy | ||
32 | from optparse import * | ||
33 | |||
34 | from constants import * | ||
35 | from errors import * | ||
36 | from version import * | ||
37 | |||
38 | import gettext | ||
39 | _ = lambda x: gettext.ldgettext("pykickstart", x) | ||
40 | |||
41 | class KSOptionParser(OptionParser): | ||
42 | """A specialized subclass of optparse.OptionParser to handle extra option | ||
43 | attribute checking, work error reporting into the KickstartParseError | ||
44 | framework, and to turn off the default help. | ||
45 | """ | ||
46 | def exit(self, status=0, msg=None): | ||
47 | pass | ||
48 | |||
49 | def error(self, msg): | ||
50 | if self.lineno != None: | ||
51 | raise KickstartParseError, formatErrorMsg(self.lineno, msg=msg) | ||
52 | else: | ||
53 | raise KickstartParseError, msg | ||
54 | |||
55 | def keys(self): | ||
56 | retval = [] | ||
57 | |||
58 | for opt in self.option_list: | ||
59 | if opt not in retval: | ||
60 | retval.append(opt.dest) | ||
61 | |||
62 | return retval | ||
63 | |||
64 | def _init_parsing_state (self): | ||
65 | OptionParser._init_parsing_state(self) | ||
66 | self.option_seen = {} | ||
67 | |||
68 | def check_values (self, values, args): | ||
69 | def seen(self, option): | ||
70 | return self.option_seen.has_key(option) | ||
71 | |||
72 | def usedTooNew(self, option): | ||
73 | return option.introduced and option.introduced > self.version | ||
74 | |||
75 | def usedDeprecated(self, option): | ||
76 | return option.deprecated | ||
77 | |||
78 | def usedRemoved(self, option): | ||
79 | return option.removed and option.removed <= self.version | ||
80 | |||
81 | for option in filter(lambda o: isinstance(o, Option), self.option_list): | ||
82 | if option.required and not seen(self, option): | ||
83 | raise KickstartValueError, formatErrorMsg(self.lineno, _("Option %s is required") % option) | ||
84 | elif seen(self, option) and usedTooNew(self, option): | ||
85 | mapping = {"option": option, "intro": versionToString(option.introduced), | ||
86 | "version": versionToString(self.version)} | ||
87 | self.error(_("The %(option)s option was introduced in version %(intro)s, but you are using kickstart syntax version %(version)s.") % mapping) | ||
88 | elif seen(self, option) and usedRemoved(self, option): | ||
89 | mapping = {"option": option, "removed": versionToString(option.removed), | ||
90 | "version": versionToString(self.version)} | ||
91 | |||
92 | if option.removed == self.version: | ||
93 | self.error(_("The %(option)s option is no longer supported.") % mapping) | ||
94 | else: | ||
95 | self.error(_("The %(option)s option was removed in version %(removed)s, but you are using kickstart syntax version %(version)s.") % mapping) | ||
96 | elif seen(self, option) and usedDeprecated(self, option): | ||
97 | mapping = {"lineno": self.lineno, "option": option} | ||
98 | warnings.warn(_("Ignoring deprecated option on line %(lineno)s: The %(option)s option has been deprecated and no longer has any effect. It may be removed from future releases, which will result in a fatal error from kickstart. Please modify your kickstart file to remove this option.") % mapping, DeprecationWarning) | ||
99 | |||
100 | return (values, args) | ||
101 | |||
102 | def parse_args(self, *args, **kwargs): | ||
103 | if kwargs.has_key("lineno"): | ||
104 | self.lineno = kwargs.pop("lineno") | ||
105 | |||
106 | return OptionParser.parse_args(self, **kwargs) | ||
107 | |||
108 | def __init__(self, mapping=None, version=None): | ||
109 | """Create a new KSOptionParser instance. Each KickstartCommand | ||
110 | subclass should create one instance of KSOptionParser, providing | ||
111 | at least the lineno attribute. mapping and version are not required. | ||
112 | Instance attributes: | ||
113 | |||
114 | mapping -- A mapping from option strings to different values. | ||
115 | version -- The version of the kickstart syntax we are checking | ||
116 | against. | ||
117 | """ | ||
118 | OptionParser.__init__(self, option_class=KSOption, | ||
119 | add_help_option=False, | ||
120 | conflict_handler="resolve") | ||
121 | if mapping is None: | ||
122 | self.map = {} | ||
123 | else: | ||
124 | self.map = mapping | ||
125 | |||
126 | self.lineno = None | ||
127 | self.option_seen = {} | ||
128 | self.version = version | ||
129 | |||
130 | def _check_ksboolean(option, opt, value): | ||
131 | if value.lower() in ("on", "yes", "true", "1"): | ||
132 | return True | ||
133 | elif value.lower() in ("off", "no", "false", "0"): | ||
134 | return False | ||
135 | else: | ||
136 | mapping = {"opt": opt, "value": value} | ||
137 | raise OptionValueError(_("Option %(opt)s: invalid boolean value: %(value)r") % mapping) | ||
138 | |||
139 | def _check_string(option, opt, value): | ||
140 | if len(value) > 2 and value.startswith("--"): | ||
141 | mapping = {"opt": opt, "value": value} | ||
142 | raise OptionValueError(_("Option %(opt)s: invalid string value: %(value)r") % mapping) | ||
143 | else: | ||
144 | return value | ||
145 | |||
146 | # Creates a new Option class that supports several new attributes: | ||
147 | # - required: any option with this attribute must be supplied or an exception | ||
148 | # is thrown | ||
149 | # - introduced: the kickstart syntax version that this option first appeared | ||
150 | # in - an exception will be raised if the option is used and | ||
151 | # the specified syntax version is less than the value of this | ||
152 | # attribute | ||
153 | # - deprecated: the kickstart syntax version that this option was deprecated | ||
154 | # in - a DeprecationWarning will be thrown if the option is | ||
155 | # used and the specified syntax version is greater than the | ||
156 | # value of this attribute | ||
157 | # - removed: the kickstart syntax version that this option was removed in - an | ||
158 | # exception will be raised if the option is used and the specified | ||
159 | # syntax version is greated than the value of this attribute | ||
160 | # Also creates a new type: | ||
161 | # - ksboolean: support various kinds of boolean values on an option | ||
162 | # And two new actions: | ||
163 | # - map : allows you to define an opt -> val mapping such that dest gets val | ||
164 | # when opt is seen | ||
165 | # - map_extend: allows you to define an opt -> [val1, ... valn] mapping such | ||
166 | # that dest gets a list of vals built up when opt is seen | ||
167 | class KSOption (Option): | ||
168 | ATTRS = Option.ATTRS + ['introduced', 'deprecated', 'removed', 'required'] | ||
169 | ACTIONS = Option.ACTIONS + ("map", "map_extend",) | ||
170 | STORE_ACTIONS = Option.STORE_ACTIONS + ("map", "map_extend",) | ||
171 | |||
172 | TYPES = Option.TYPES + ("ksboolean", "string") | ||
173 | TYPE_CHECKER = copy(Option.TYPE_CHECKER) | ||
174 | TYPE_CHECKER["ksboolean"] = _check_ksboolean | ||
175 | TYPE_CHECKER["string"] = _check_string | ||
176 | |||
177 | def _check_required(self): | ||
178 | if self.required and not self.takes_value(): | ||
179 | raise OptionError(_("Required flag set for option that doesn't take a value"), self) | ||
180 | |||
181 | # Make sure _check_required() is called from the constructor! | ||
182 | CHECK_METHODS = Option.CHECK_METHODS + [_check_required] | ||
183 | |||
184 | def process (self, opt, value, values, parser): | ||
185 | Option.process(self, opt, value, values, parser) | ||
186 | parser.option_seen[self] = 1 | ||
187 | |||
188 | # Override default take_action method to handle our custom actions. | ||
189 | def take_action(self, action, dest, opt, value, values, parser): | ||
190 | if action == "map": | ||
191 | values.ensure_value(dest, parser.map[opt.lstrip('-')]) | ||
192 | elif action == "map_extend": | ||
193 | values.ensure_value(dest, []).extend(parser.map[opt.lstrip('-')]) | ||
194 | else: | ||
195 | Option.take_action(self, action, dest, opt, value, values, parser) | ||
196 | |||
197 | def takes_value(self): | ||
198 | # Deprecated options don't take a value. | ||
199 | return Option.takes_value(self) and not self.deprecated | ||
200 | |||
201 | def __init__(self, *args, **kwargs): | ||
202 | self.deprecated = False | ||
203 | self.required = False | ||
204 | Option.__init__(self, *args, **kwargs) | ||
diff --git a/scripts/lib/wic/3rdparty/pykickstart/parser.py b/scripts/lib/wic/3rdparty/pykickstart/parser.py new file mode 100644 index 0000000000..840a448673 --- /dev/null +++ b/scripts/lib/wic/3rdparty/pykickstart/parser.py | |||
@@ -0,0 +1,702 @@ | |||
1 | # | ||
2 | # parser.py: Kickstart file parser. | ||
3 | # | ||
4 | # Chris Lumens <clumens@redhat.com> | ||
5 | # | ||
6 | # Copyright 2005, 2006, 2007, 2008, 2011 Red Hat, Inc. | ||
7 | # | ||
8 | # This copyrighted material is made available to anyone wishing to use, modify, | ||
9 | # copy, or redistribute it subject to the terms and conditions of the GNU | ||
10 | # General Public License v.2. This program is distributed in the hope that it | ||
11 | # will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the | ||
12 | # implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
13 | # See the GNU General Public License for more details. | ||
14 | # | ||
15 | # You should have received a copy of the GNU General Public License along with | ||
16 | # this program; if not, write to the Free Software Foundation, Inc., 51 | ||
17 | # Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Any Red Hat | ||
18 | # trademarks that are incorporated in the source code or documentation are not | ||
19 | # subject to the GNU General Public License and may only be used or replicated | ||
20 | # with the express permission of Red Hat, Inc. | ||
21 | # | ||
22 | """ | ||
23 | Main kickstart file processing module. | ||
24 | |||
25 | This module exports several important classes: | ||
26 | |||
27 | Script - Representation of a single %pre, %post, or %traceback script. | ||
28 | |||
29 | Packages - Representation of the %packages section. | ||
30 | |||
31 | KickstartParser - The kickstart file parser state machine. | ||
32 | """ | ||
33 | |||
34 | from collections import Iterator | ||
35 | import os | ||
36 | import shlex | ||
37 | import sys | ||
38 | import tempfile | ||
39 | from copy import copy | ||
40 | from optparse import * | ||
41 | from urlgrabber import urlread | ||
42 | import urlgrabber.grabber as grabber | ||
43 | |||
44 | import constants | ||
45 | from errors import KickstartError, KickstartParseError, KickstartValueError, formatErrorMsg | ||
46 | from ko import KickstartObject | ||
47 | from sections import * | ||
48 | import version | ||
49 | |||
50 | import gettext | ||
51 | _ = lambda x: gettext.ldgettext("pykickstart", x) | ||
52 | |||
53 | STATE_END = "end" | ||
54 | STATE_COMMANDS = "commands" | ||
55 | |||
56 | ver = version.DEVEL | ||
57 | |||
58 | def _preprocessStateMachine (lineIter): | ||
59 | l = None | ||
60 | lineno = 0 | ||
61 | |||
62 | # Now open an output kickstart file that we are going to write to one | ||
63 | # line at a time. | ||
64 | (outF, outName) = tempfile.mkstemp("-ks.cfg", "", "/tmp") | ||
65 | |||
66 | while True: | ||
67 | try: | ||
68 | l = lineIter.next() | ||
69 | except StopIteration: | ||
70 | break | ||
71 | |||
72 | # At the end of the file? | ||
73 | if l == "": | ||
74 | break | ||
75 | |||
76 | lineno += 1 | ||
77 | url = None | ||
78 | |||
79 | ll = l.strip() | ||
80 | if not ll.startswith("%ksappend"): | ||
81 | os.write(outF, l) | ||
82 | continue | ||
83 | |||
84 | # Try to pull down the remote file. | ||
85 | try: | ||
86 | ksurl = ll.split(' ')[1] | ||
87 | except: | ||
88 | raise KickstartParseError, formatErrorMsg(lineno, msg=_("Illegal url for %%ksappend: %s") % ll) | ||
89 | |||
90 | try: | ||
91 | url = grabber.urlopen(ksurl) | ||
92 | except grabber.URLGrabError, e: | ||
93 | raise KickstartError, formatErrorMsg(lineno, msg=_("Unable to open %%ksappend file: %s") % e.strerror) | ||
94 | else: | ||
95 | # Sanity check result. Sometimes FTP doesn't catch a file | ||
96 | # is missing. | ||
97 | try: | ||
98 | if url.size < 1: | ||
99 | raise KickstartError, formatErrorMsg(lineno, msg=_("Unable to open %%ksappend file")) | ||
100 | except: | ||
101 | raise KickstartError, formatErrorMsg(lineno, msg=_("Unable to open %%ksappend file")) | ||
102 | |||
103 | # If that worked, write the remote file to the output kickstart | ||
104 | # file in one burst. Then close everything up to get ready to | ||
105 | # read ahead in the input file. This allows multiple %ksappend | ||
106 | # lines to exist. | ||
107 | if url is not None: | ||
108 | os.write(outF, url.read()) | ||
109 | url.close() | ||
110 | |||
111 | # All done - close the temp file and return its location. | ||
112 | os.close(outF) | ||
113 | return outName | ||
114 | |||
115 | def preprocessFromString (s): | ||
116 | """Preprocess the kickstart file, provided as the string str. This | ||
117 | method is currently only useful for handling %ksappend lines, | ||
118 | which need to be fetched before the real kickstart parser can be | ||
119 | run. Returns the location of the complete kickstart file. | ||
120 | """ | ||
121 | i = iter(s.splitlines(True) + [""]) | ||
122 | rc = _preprocessStateMachine (i.next) | ||
123 | return rc | ||
124 | |||
125 | def preprocessKickstart (f): | ||
126 | """Preprocess the kickstart file, given by the filename file. This | ||
127 | method is currently only useful for handling %ksappend lines, | ||
128 | which need to be fetched before the real kickstart parser can be | ||
129 | run. Returns the location of the complete kickstart file. | ||
130 | """ | ||
131 | try: | ||
132 | fh = urlopen(f) | ||
133 | except grabber.URLGrabError, e: | ||
134 | raise KickstartError, formatErrorMsg(0, msg=_("Unable to open input kickstart file: %s") % e.strerror) | ||
135 | |||
136 | rc = _preprocessStateMachine (iter(fh.readlines())) | ||
137 | fh.close() | ||
138 | return rc | ||
139 | |||
140 | class PutBackIterator(Iterator): | ||
141 | def __init__(self, iterable): | ||
142 | self._iterable = iter(iterable) | ||
143 | self._buf = None | ||
144 | |||
145 | def __iter__(self): | ||
146 | return self | ||
147 | |||
148 | def put(self, s): | ||
149 | self._buf = s | ||
150 | |||
151 | def next(self): | ||
152 | if self._buf: | ||
153 | retval = self._buf | ||
154 | self._buf = None | ||
155 | return retval | ||
156 | else: | ||
157 | return self._iterable.next() | ||
158 | |||
159 | ### | ||
160 | ### SCRIPT HANDLING | ||
161 | ### | ||
162 | class Script(KickstartObject): | ||
163 | """A class representing a single kickstart script. If functionality beyond | ||
164 | just a data representation is needed (for example, a run method in | ||
165 | anaconda), Script may be subclassed. Although a run method is not | ||
166 | provided, most of the attributes of Script have to do with running the | ||
167 | script. Instances of Script are held in a list by the Version object. | ||
168 | """ | ||
169 | def __init__(self, script, *args , **kwargs): | ||
170 | """Create a new Script instance. Instance attributes: | ||
171 | |||
172 | errorOnFail -- If execution of the script fails, should anaconda | ||
173 | stop, display an error, and then reboot without | ||
174 | running any other scripts? | ||
175 | inChroot -- Does the script execute in anaconda's chroot | ||
176 | environment or not? | ||
177 | interp -- The program that should be used to interpret this | ||
178 | script. | ||
179 | lineno -- The line number this script starts on. | ||
180 | logfile -- Where all messages from the script should be logged. | ||
181 | script -- A string containing all the lines of the script. | ||
182 | type -- The type of the script, which can be KS_SCRIPT_* from | ||
183 | pykickstart.constants. | ||
184 | """ | ||
185 | KickstartObject.__init__(self, *args, **kwargs) | ||
186 | self.script = "".join(script) | ||
187 | |||
188 | self.interp = kwargs.get("interp", "/bin/sh") | ||
189 | self.inChroot = kwargs.get("inChroot", False) | ||
190 | self.lineno = kwargs.get("lineno", None) | ||
191 | self.logfile = kwargs.get("logfile", None) | ||
192 | self.errorOnFail = kwargs.get("errorOnFail", False) | ||
193 | self.type = kwargs.get("type", constants.KS_SCRIPT_PRE) | ||
194 | |||
195 | def __str__(self): | ||
196 | """Return a string formatted for output to a kickstart file.""" | ||
197 | retval = "" | ||
198 | |||
199 | if self.type == constants.KS_SCRIPT_PRE: | ||
200 | retval += '\n%pre' | ||
201 | elif self.type == constants.KS_SCRIPT_POST: | ||
202 | retval += '\n%post' | ||
203 | elif self.type == constants.KS_SCRIPT_TRACEBACK: | ||
204 | retval += '\n%traceback' | ||
205 | |||
206 | if self.interp != "/bin/sh" and self.interp != "": | ||
207 | retval += " --interpreter=%s" % self.interp | ||
208 | if self.type == constants.KS_SCRIPT_POST and not self.inChroot: | ||
209 | retval += " --nochroot" | ||
210 | if self.logfile != None: | ||
211 | retval += " --logfile %s" % self.logfile | ||
212 | if self.errorOnFail: | ||
213 | retval += " --erroronfail" | ||
214 | |||
215 | if self.script.endswith("\n"): | ||
216 | if ver >= version.F8: | ||
217 | return retval + "\n%s%%end\n" % self.script | ||
218 | else: | ||
219 | return retval + "\n%s\n" % self.script | ||
220 | else: | ||
221 | if ver >= version.F8: | ||
222 | return retval + "\n%s\n%%end\n" % self.script | ||
223 | else: | ||
224 | return retval + "\n%s\n" % self.script | ||
225 | |||
226 | |||
227 | ## | ||
228 | ## PACKAGE HANDLING | ||
229 | ## | ||
230 | class Group: | ||
231 | """A class representing a single group in the %packages section.""" | ||
232 | def __init__(self, name="", include=constants.GROUP_DEFAULT): | ||
233 | """Create a new Group instance. Instance attributes: | ||
234 | |||
235 | name -- The group's identifier | ||
236 | include -- The level of how much of the group should be included. | ||
237 | Values can be GROUP_* from pykickstart.constants. | ||
238 | """ | ||
239 | self.name = name | ||
240 | self.include = include | ||
241 | |||
242 | def __str__(self): | ||
243 | """Return a string formatted for output to a kickstart file.""" | ||
244 | if self.include == constants.GROUP_REQUIRED: | ||
245 | return "@%s --nodefaults" % self.name | ||
246 | elif self.include == constants.GROUP_ALL: | ||
247 | return "@%s --optional" % self.name | ||
248 | else: | ||
249 | return "@%s" % self.name | ||
250 | |||
251 | def __cmp__(self, other): | ||
252 | if self.name < other.name: | ||
253 | return -1 | ||
254 | elif self.name > other.name: | ||
255 | return 1 | ||
256 | return 0 | ||
257 | |||
258 | class Packages(KickstartObject): | ||
259 | """A class representing the %packages section of the kickstart file.""" | ||
260 | def __init__(self, *args, **kwargs): | ||
261 | """Create a new Packages instance. Instance attributes: | ||
262 | |||
263 | addBase -- Should the Base group be installed even if it is | ||
264 | not specified? | ||
265 | default -- Should the default package set be selected? | ||
266 | excludedList -- A list of all the packages marked for exclusion in | ||
267 | the %packages section, without the leading minus | ||
268 | symbol. | ||
269 | excludeDocs -- Should documentation in each package be excluded? | ||
270 | groupList -- A list of Group objects representing all the groups | ||
271 | specified in the %packages section. Names will be | ||
272 | stripped of the leading @ symbol. | ||
273 | excludedGroupList -- A list of Group objects representing all the | ||
274 | groups specified for removal in the %packages | ||
275 | section. Names will be stripped of the leading | ||
276 | -@ symbols. | ||
277 | handleMissing -- If unknown packages are specified in the %packages | ||
278 | section, should it be ignored or not? Values can | ||
279 | be KS_MISSING_* from pykickstart.constants. | ||
280 | packageList -- A list of all the packages specified in the | ||
281 | %packages section. | ||
282 | instLangs -- A list of languages to install. | ||
283 | """ | ||
284 | KickstartObject.__init__(self, *args, **kwargs) | ||
285 | |||
286 | self.addBase = True | ||
287 | self.default = False | ||
288 | self.excludedList = [] | ||
289 | self.excludedGroupList = [] | ||
290 | self.excludeDocs = False | ||
291 | self.groupList = [] | ||
292 | self.handleMissing = constants.KS_MISSING_PROMPT | ||
293 | self.packageList = [] | ||
294 | self.instLangs = None | ||
295 | |||
296 | def __str__(self): | ||
297 | """Return a string formatted for output to a kickstart file.""" | ||
298 | pkgs = "" | ||
299 | |||
300 | if not self.default: | ||
301 | grps = self.groupList | ||
302 | grps.sort() | ||
303 | for grp in grps: | ||
304 | pkgs += "%s\n" % grp.__str__() | ||
305 | |||
306 | p = self.packageList | ||
307 | p.sort() | ||
308 | for pkg in p: | ||
309 | pkgs += "%s\n" % pkg | ||
310 | |||
311 | grps = self.excludedGroupList | ||
312 | grps.sort() | ||
313 | for grp in grps: | ||
314 | pkgs += "-%s\n" % grp.__str__() | ||
315 | |||
316 | p = self.excludedList | ||
317 | p.sort() | ||
318 | for pkg in p: | ||
319 | pkgs += "-%s\n" % pkg | ||
320 | |||
321 | if pkgs == "": | ||
322 | return "" | ||
323 | |||
324 | retval = "\n%packages" | ||
325 | |||
326 | if self.default: | ||
327 | retval += " --default" | ||
328 | if self.excludeDocs: | ||
329 | retval += " --excludedocs" | ||
330 | if not self.addBase: | ||
331 | retval += " --nobase" | ||
332 | if self.handleMissing == constants.KS_MISSING_IGNORE: | ||
333 | retval += " --ignoremissing" | ||
334 | if self.instLangs: | ||
335 | retval += " --instLangs=%s" % self.instLangs | ||
336 | |||
337 | if ver >= version.F8: | ||
338 | return retval + "\n" + pkgs + "\n%end\n" | ||
339 | else: | ||
340 | return retval + "\n" + pkgs + "\n" | ||
341 | |||
342 | def _processGroup (self, line): | ||
343 | op = OptionParser() | ||
344 | op.add_option("--nodefaults", action="store_true", default=False) | ||
345 | op.add_option("--optional", action="store_true", default=False) | ||
346 | |||
347 | (opts, extra) = op.parse_args(args=line.split()) | ||
348 | |||
349 | if opts.nodefaults and opts.optional: | ||
350 | raise KickstartValueError, _("Group cannot specify both --nodefaults and --optional") | ||
351 | |||
352 | # If the group name has spaces in it, we have to put it back together | ||
353 | # now. | ||
354 | grp = " ".join(extra) | ||
355 | |||
356 | if opts.nodefaults: | ||
357 | self.groupList.append(Group(name=grp, include=constants.GROUP_REQUIRED)) | ||
358 | elif opts.optional: | ||
359 | self.groupList.append(Group(name=grp, include=constants.GROUP_ALL)) | ||
360 | else: | ||
361 | self.groupList.append(Group(name=grp, include=constants.GROUP_DEFAULT)) | ||
362 | |||
363 | def add (self, pkgList): | ||
364 | """Given a list of lines from the input file, strip off any leading | ||
365 | symbols and add the result to the appropriate list. | ||
366 | """ | ||
367 | existingExcludedSet = set(self.excludedList) | ||
368 | existingPackageSet = set(self.packageList) | ||
369 | newExcludedSet = set() | ||
370 | newPackageSet = set() | ||
371 | |||
372 | excludedGroupList = [] | ||
373 | |||
374 | for pkg in pkgList: | ||
375 | stripped = pkg.strip() | ||
376 | |||
377 | if stripped[0] == "@": | ||
378 | self._processGroup(stripped[1:]) | ||
379 | elif stripped[0] == "-": | ||
380 | if stripped[1] == "@": | ||
381 | excludedGroupList.append(Group(name=stripped[2:])) | ||
382 | else: | ||
383 | newExcludedSet.add(stripped[1:]) | ||
384 | else: | ||
385 | newPackageSet.add(stripped) | ||
386 | |||
387 | # Groups have to be excluded in two different ways (note: can't use | ||
388 | # sets here because we have to store objects): | ||
389 | excludedGroupNames = map(lambda g: g.name, excludedGroupList) | ||
390 | |||
391 | # First, an excluded group may be cancelling out a previously given | ||
392 | # one. This is often the case when using %include. So there we should | ||
393 | # just remove the group from the list. | ||
394 | self.groupList = filter(lambda g: g.name not in excludedGroupNames, self.groupList) | ||
395 | |||
396 | # Second, the package list could have included globs which are not | ||
397 | # processed by pykickstart. In that case we need to preserve a list of | ||
398 | # excluded groups so whatever tool doing package/group installation can | ||
399 | # take appropriate action. | ||
400 | self.excludedGroupList.extend(excludedGroupList) | ||
401 | |||
402 | existingPackageSet = (existingPackageSet - newExcludedSet) | newPackageSet | ||
403 | existingExcludedSet = (existingExcludedSet - existingPackageSet) | newExcludedSet | ||
404 | |||
405 | self.packageList = list(existingPackageSet) | ||
406 | self.excludedList = list(existingExcludedSet) | ||
407 | |||
408 | |||
409 | ### | ||
410 | ### PARSER | ||
411 | ### | ||
412 | class KickstartParser: | ||
413 | """The kickstart file parser class as represented by a basic state | ||
414 | machine. To create a specialized parser, make a subclass and override | ||
415 | any of the methods you care about. Methods that don't need to do | ||
416 | anything may just pass. However, _stateMachine should never be | ||
417 | overridden. | ||
418 | """ | ||
419 | def __init__ (self, handler, followIncludes=True, errorsAreFatal=True, | ||
420 | missingIncludeIsFatal=True): | ||
421 | """Create a new KickstartParser instance. Instance attributes: | ||
422 | |||
423 | errorsAreFatal -- Should errors cause processing to halt, or | ||
424 | just print a message to the screen? This | ||
425 | is most useful for writing syntax checkers | ||
426 | that may want to continue after an error is | ||
427 | encountered. | ||
428 | followIncludes -- If %include is seen, should the included | ||
429 | file be checked as well or skipped? | ||
430 | handler -- An instance of a BaseHandler subclass. If | ||
431 | None, the input file will still be parsed | ||
432 | but no data will be saved and no commands | ||
433 | will be executed. | ||
434 | missingIncludeIsFatal -- Should missing include files be fatal, even | ||
435 | if errorsAreFatal is False? | ||
436 | """ | ||
437 | self.errorsAreFatal = errorsAreFatal | ||
438 | self.followIncludes = followIncludes | ||
439 | self.handler = handler | ||
440 | self.currentdir = {} | ||
441 | self.missingIncludeIsFatal = missingIncludeIsFatal | ||
442 | |||
443 | self._state = STATE_COMMANDS | ||
444 | self._includeDepth = 0 | ||
445 | self._line = "" | ||
446 | |||
447 | self.version = self.handler.version | ||
448 | |||
449 | global ver | ||
450 | ver = self.version | ||
451 | |||
452 | self._sections = {} | ||
453 | self.setupSections() | ||
454 | |||
455 | def _reset(self): | ||
456 | """Reset the internal variables of the state machine for a new kickstart file.""" | ||
457 | self._state = STATE_COMMANDS | ||
458 | self._includeDepth = 0 | ||
459 | |||
460 | def getSection(self, s): | ||
461 | """Return a reference to the requested section (s must start with '%'s), | ||
462 | or raise KeyError if not found. | ||
463 | """ | ||
464 | return self._sections[s] | ||
465 | |||
466 | def handleCommand (self, lineno, args): | ||
467 | """Given the list of command and arguments, call the Version's | ||
468 | dispatcher method to handle the command. Returns the command or | ||
469 | data object returned by the dispatcher. This method may be | ||
470 | overridden in a subclass if necessary. | ||
471 | """ | ||
472 | if self.handler: | ||
473 | self.handler.currentCmd = args[0] | ||
474 | self.handler.currentLine = self._line | ||
475 | retval = self.handler.dispatcher(args, lineno) | ||
476 | |||
477 | return retval | ||
478 | |||
479 | def registerSection(self, obj): | ||
480 | """Given an instance of a Section subclass, register the new section | ||
481 | with the parser. Calling this method means the parser will | ||
482 | recognize your new section and dispatch into the given object to | ||
483 | handle it. | ||
484 | """ | ||
485 | if not obj.sectionOpen: | ||
486 | raise TypeError, "no sectionOpen given for section %s" % obj | ||
487 | |||
488 | if not obj.sectionOpen.startswith("%"): | ||
489 | raise TypeError, "section %s tag does not start with a %%" % obj.sectionOpen | ||
490 | |||
491 | self._sections[obj.sectionOpen] = obj | ||
492 | |||
493 | def _finalize(self, obj): | ||
494 | """Called at the close of a kickstart section to take any required | ||
495 | actions. Internally, this is used to add scripts once we have the | ||
496 | whole body read. | ||
497 | """ | ||
498 | obj.finalize() | ||
499 | self._state = STATE_COMMANDS | ||
500 | |||
501 | def _handleSpecialComments(self, line): | ||
502 | """Kickstart recognizes a couple special comments.""" | ||
503 | if self._state != STATE_COMMANDS: | ||
504 | return | ||
505 | |||
506 | # Save the platform for s-c-kickstart. | ||
507 | if line[:10] == "#platform=": | ||
508 | self.handler.platform = self._line[11:] | ||
509 | |||
510 | def _readSection(self, lineIter, lineno): | ||
511 | obj = self._sections[self._state] | ||
512 | |||
513 | while True: | ||
514 | try: | ||
515 | line = lineIter.next() | ||
516 | if line == "": | ||
517 | # This section ends at the end of the file. | ||
518 | if self.version >= version.F8: | ||
519 | raise KickstartParseError, formatErrorMsg(lineno, msg=_("Section does not end with %%end.")) | ||
520 | |||
521 | self._finalize(obj) | ||
522 | except StopIteration: | ||
523 | break | ||
524 | |||
525 | lineno += 1 | ||
526 | |||
527 | # Throw away blank lines and comments, unless the section wants all | ||
528 | # lines. | ||
529 | if self._isBlankOrComment(line) and not obj.allLines: | ||
530 | continue | ||
531 | |||
532 | if line.startswith("%"): | ||
533 | args = shlex.split(line) | ||
534 | |||
535 | if args and args[0] == "%end": | ||
536 | # This is a properly terminated section. | ||
537 | self._finalize(obj) | ||
538 | break | ||
539 | elif args and args[0] == "%ksappend": | ||
540 | continue | ||
541 | elif args and (self._validState(args[0]) or args[0] in ["%include", "%ksappend"]): | ||
542 | # This is an unterminated section. | ||
543 | if self.version >= version.F8: | ||
544 | raise KickstartParseError, formatErrorMsg(lineno, msg=_("Section does not end with %%end.")) | ||
545 | |||
546 | # Finish up. We do not process the header here because | ||
547 | # kicking back out to STATE_COMMANDS will ensure that happens. | ||
548 | lineIter.put(line) | ||
549 | lineno -= 1 | ||
550 | self._finalize(obj) | ||
551 | break | ||
552 | else: | ||
553 | # This is just a line within a section. Pass it off to whatever | ||
554 | # section handles it. | ||
555 | obj.handleLine(line) | ||
556 | |||
557 | return lineno | ||
558 | |||
559 | def _validState(self, st): | ||
560 | """Is the given section tag one that has been registered with the parser?""" | ||
561 | return st in self._sections.keys() | ||
562 | |||
563 | def _tryFunc(self, fn): | ||
564 | """Call the provided function (which doesn't take any arguments) and | ||
565 | do the appropriate error handling. If errorsAreFatal is False, this | ||
566 | function will just print the exception and keep going. | ||
567 | """ | ||
568 | try: | ||
569 | fn() | ||
570 | except Exception, msg: | ||
571 | if self.errorsAreFatal: | ||
572 | raise | ||
573 | else: | ||
574 | print msg | ||
575 | |||
576 | def _isBlankOrComment(self, line): | ||
577 | return line.isspace() or line == "" or line.lstrip()[0] == '#' | ||
578 | |||
579 | def _stateMachine(self, lineIter): | ||
580 | # For error reporting. | ||
581 | lineno = 0 | ||
582 | |||
583 | while True: | ||
584 | # Get the next line out of the file, quitting if this is the last line. | ||
585 | try: | ||
586 | self._line = lineIter.next() | ||
587 | if self._line == "": | ||
588 | break | ||
589 | except StopIteration: | ||
590 | break | ||
591 | |||
592 | lineno += 1 | ||
593 | |||
594 | # Eliminate blank lines, whitespace-only lines, and comments. | ||
595 | if self._isBlankOrComment(self._line): | ||
596 | self._handleSpecialComments(self._line) | ||
597 | continue | ||
598 | |||
599 | # Remove any end-of-line comments. | ||
600 | sanitized = self._line.split("#")[0] | ||
601 | |||
602 | # Then split the line. | ||
603 | args = shlex.split(sanitized.rstrip()) | ||
604 | |||
605 | if args[0] == "%include": | ||
606 | # This case comes up primarily in ksvalidator. | ||
607 | if not self.followIncludes: | ||
608 | continue | ||
609 | |||
610 | if len(args) == 1 or not args[1]: | ||
611 | raise KickstartParseError, formatErrorMsg(lineno) | ||
612 | |||
613 | self._includeDepth += 1 | ||
614 | |||
615 | try: | ||
616 | self.readKickstart(args[1], reset=False) | ||
617 | except KickstartError: | ||
618 | # Handle the include file being provided over the | ||
619 | # network in a %pre script. This case comes up in the | ||
620 | # early parsing in anaconda. | ||
621 | if self.missingIncludeIsFatal: | ||
622 | raise | ||
623 | |||
624 | self._includeDepth -= 1 | ||
625 | continue | ||
626 | |||
627 | # Now on to the main event. | ||
628 | if self._state == STATE_COMMANDS: | ||
629 | if args[0] == "%ksappend": | ||
630 | # This is handled by the preprocess* functions, so continue. | ||
631 | continue | ||
632 | elif args[0][0] == '%': | ||
633 | # This is the beginning of a new section. Handle its header | ||
634 | # here. | ||
635 | newSection = args[0] | ||
636 | if not self._validState(newSection): | ||
637 | raise KickstartParseError, formatErrorMsg(lineno, msg=_("Unknown kickstart section: %s" % newSection)) | ||
638 | |||
639 | self._state = newSection | ||
640 | obj = self._sections[self._state] | ||
641 | self._tryFunc(lambda: obj.handleHeader(lineno, args)) | ||
642 | |||
643 | # This will handle all section processing, kicking us back | ||
644 | # out to STATE_COMMANDS at the end with the current line | ||
645 | # being the next section header, etc. | ||
646 | lineno = self._readSection(lineIter, lineno) | ||
647 | else: | ||
648 | # This is a command in the command section. Dispatch to it. | ||
649 | self._tryFunc(lambda: self.handleCommand(lineno, args)) | ||
650 | elif self._state == STATE_END: | ||
651 | break | ||
652 | |||
653 | def readKickstartFromString (self, s, reset=True): | ||
654 | """Process a kickstart file, provided as the string str.""" | ||
655 | if reset: | ||
656 | self._reset() | ||
657 | |||
658 | # Add a "" to the end of the list so the string reader acts like the | ||
659 | # file reader and we only get StopIteration when we're after the final | ||
660 | # line of input. | ||
661 | i = PutBackIterator(s.splitlines(True) + [""]) | ||
662 | self._stateMachine (i) | ||
663 | |||
664 | def readKickstart(self, f, reset=True): | ||
665 | """Process a kickstart file, given by the filename f.""" | ||
666 | if reset: | ||
667 | self._reset() | ||
668 | |||
669 | # an %include might not specify a full path. if we don't try to figure | ||
670 | # out what the path should have been, then we're unable to find it | ||
671 | # requiring full path specification, though, sucks. so let's make | ||
672 | # the reading "smart" by keeping track of what the path is at each | ||
673 | # include depth. | ||
674 | if not os.path.exists(f): | ||
675 | if self.currentdir.has_key(self._includeDepth - 1): | ||
676 | if os.path.exists(os.path.join(self.currentdir[self._includeDepth - 1], f)): | ||
677 | f = os.path.join(self.currentdir[self._includeDepth - 1], f) | ||
678 | |||
679 | cd = os.path.dirname(f) | ||
680 | if not cd.startswith("/"): | ||
681 | cd = os.path.abspath(cd) | ||
682 | self.currentdir[self._includeDepth] = cd | ||
683 | |||
684 | try: | ||
685 | s = urlread(f) | ||
686 | except grabber.URLGrabError, e: | ||
687 | raise KickstartError, formatErrorMsg(0, msg=_("Unable to open input kickstart file: %s") % e.strerror) | ||
688 | |||
689 | self.readKickstartFromString(s, reset=False) | ||
690 | |||
691 | def setupSections(self): | ||
692 | """Install the sections all kickstart files support. You may override | ||
693 | this method in a subclass, but should avoid doing so unless you know | ||
694 | what you're doing. | ||
695 | """ | ||
696 | self._sections = {} | ||
697 | |||
698 | # Install the sections all kickstart files support. | ||
699 | self.registerSection(PreScriptSection(self.handler, dataObj=Script)) | ||
700 | self.registerSection(PostScriptSection(self.handler, dataObj=Script)) | ||
701 | self.registerSection(TracebackScriptSection(self.handler, dataObj=Script)) | ||
702 | self.registerSection(PackageSection(self.handler)) | ||
diff --git a/scripts/lib/wic/3rdparty/pykickstart/sections.py b/scripts/lib/wic/3rdparty/pykickstart/sections.py new file mode 100644 index 0000000000..44df856b8d --- /dev/null +++ b/scripts/lib/wic/3rdparty/pykickstart/sections.py | |||
@@ -0,0 +1,244 @@ | |||
1 | # | ||
2 | # sections.py: Kickstart file sections. | ||
3 | # | ||
4 | # Chris Lumens <clumens@redhat.com> | ||
5 | # | ||
6 | # Copyright 2011 Red Hat, Inc. | ||
7 | # | ||
8 | # This copyrighted material is made available to anyone wishing to use, modify, | ||
9 | # copy, or redistribute it subject to the terms and conditions of the GNU | ||
10 | # General Public License v.2. This program is distributed in the hope that it | ||
11 | # will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the | ||
12 | # implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
13 | # See the GNU General Public License for more details. | ||
14 | # | ||
15 | # You should have received a copy of the GNU General Public License along with | ||
16 | # this program; if not, write to the Free Software Foundation, Inc., 51 | ||
17 | # Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Any Red Hat | ||
18 | # trademarks that are incorporated in the source code or documentation are not | ||
19 | # subject to the GNU General Public License and may only be used or replicated | ||
20 | # with the express permission of Red Hat, Inc. | ||
21 | # | ||
22 | """ | ||
23 | This module exports the classes that define a section of a kickstart file. A | ||
24 | section is a chunk of the file starting with a %tag and ending with a %end. | ||
25 | Examples of sections include %packages, %pre, and %post. | ||
26 | |||
27 | You may use this module to define your own custom sections which will be | ||
28 | treated just the same as a predefined one by the kickstart parser. All that | ||
29 | is necessary is to create a new subclass of Section and call | ||
30 | parser.registerSection with an instance of your new class. | ||
31 | """ | ||
32 | from constants import * | ||
33 | from options import KSOptionParser | ||
34 | from version import * | ||
35 | |||
36 | class Section(object): | ||
37 | """The base class for defining kickstart sections. You are free to | ||
38 | subclass this as appropriate. | ||
39 | |||
40 | Class attributes: | ||
41 | |||
42 | allLines -- Does this section require the parser to call handleLine | ||
43 | for every line in the section, even blanks and comments? | ||
44 | sectionOpen -- The string that denotes the start of this section. You | ||
45 | must start your tag with a percent sign. | ||
46 | timesSeen -- This attribute is for informational purposes only. It is | ||
47 | incremented every time handleHeader is called to keep | ||
48 | track of the number of times a section of this type is | ||
49 | seen. | ||
50 | """ | ||
51 | allLines = False | ||
52 | sectionOpen = "" | ||
53 | timesSeen = 0 | ||
54 | |||
55 | def __init__(self, handler, **kwargs): | ||
56 | """Create a new Script instance. At the least, you must pass in an | ||
57 | instance of a baseHandler subclass. | ||
58 | |||
59 | Valid kwargs: | ||
60 | |||
61 | dataObj -- | ||
62 | """ | ||
63 | self.handler = handler | ||
64 | |||
65 | self.version = self.handler.version | ||
66 | |||
67 | self.dataObj = kwargs.get("dataObj", None) | ||
68 | |||
69 | def finalize(self): | ||
70 | """This method is called when the %end tag for a section is seen. It | ||
71 | is not required to be provided. | ||
72 | """ | ||
73 | pass | ||
74 | |||
75 | def handleLine(self, line): | ||
76 | """This method is called for every line of a section. Take whatever | ||
77 | action is appropriate. While this method is not required to be | ||
78 | provided, not providing it does not make a whole lot of sense. | ||
79 | |||
80 | Arguments: | ||
81 | |||
82 | line -- The complete line, with any trailing newline. | ||
83 | """ | ||
84 | pass | ||
85 | |||
86 | def handleHeader(self, lineno, args): | ||
87 | """This method is called when the opening tag for a section is seen. | ||
88 | Not all sections will need this method, though all provided with | ||
89 | kickstart include one. | ||
90 | |||
91 | Arguments: | ||
92 | |||
93 | args -- A list of all strings passed as arguments to the section | ||
94 | opening tag. | ||
95 | """ | ||
96 | self.timesSeen += 1 | ||
97 | |||
98 | class NullSection(Section): | ||
99 | """This defines a section that pykickstart will recognize but do nothing | ||
100 | with. If the parser runs across a %section that has no object registered, | ||
101 | it will raise an error. Sometimes, you may want to simply ignore those | ||
102 | sections instead. This class is useful for that purpose. | ||
103 | """ | ||
104 | def __init__(self, *args, **kwargs): | ||
105 | """Create a new NullSection instance. You must pass a sectionOpen | ||
106 | parameter (including a leading '%') for the section you wish to | ||
107 | ignore. | ||
108 | """ | ||
109 | Section.__init__(self, *args, **kwargs) | ||
110 | self.sectionOpen = kwargs.get("sectionOpen") | ||
111 | |||
112 | class ScriptSection(Section): | ||
113 | allLines = True | ||
114 | |||
115 | def __init__(self, *args, **kwargs): | ||
116 | Section.__init__(self, *args, **kwargs) | ||
117 | self._script = {} | ||
118 | self._resetScript() | ||
119 | |||
120 | def _getParser(self): | ||
121 | op = KSOptionParser(self.version) | ||
122 | op.add_option("--erroronfail", dest="errorOnFail", action="store_true", | ||
123 | default=False) | ||
124 | op.add_option("--interpreter", dest="interpreter", default="/bin/sh") | ||
125 | op.add_option("--log", "--logfile", dest="log") | ||
126 | return op | ||
127 | |||
128 | def _resetScript(self): | ||
129 | self._script = {"interp": "/bin/sh", "log": None, "errorOnFail": False, | ||
130 | "lineno": None, "chroot": False, "body": []} | ||
131 | |||
132 | def handleLine(self, line): | ||
133 | self._script["body"].append(line) | ||
134 | |||
135 | def finalize(self): | ||
136 | if " ".join(self._script["body"]).strip() == "": | ||
137 | return | ||
138 | |||
139 | kwargs = {"interp": self._script["interp"], | ||
140 | "inChroot": self._script["chroot"], | ||
141 | "lineno": self._script["lineno"], | ||
142 | "logfile": self._script["log"], | ||
143 | "errorOnFail": self._script["errorOnFail"], | ||
144 | "type": self._script["type"]} | ||
145 | |||
146 | s = self.dataObj (self._script["body"], **kwargs) | ||
147 | self._resetScript() | ||
148 | |||
149 | if self.handler: | ||
150 | self.handler.scripts.append(s) | ||
151 | |||
152 | def handleHeader(self, lineno, args): | ||
153 | """Process the arguments to a %pre/%post/%traceback header for later | ||
154 | setting on a Script instance once the end of the script is found. | ||
155 | This method may be overridden in a subclass if necessary. | ||
156 | """ | ||
157 | Section.handleHeader(self, lineno, args) | ||
158 | op = self._getParser() | ||
159 | |||
160 | (opts, extra) = op.parse_args(args=args[1:], lineno=lineno) | ||
161 | |||
162 | self._script["interp"] = opts.interpreter | ||
163 | self._script["lineno"] = lineno | ||
164 | self._script["log"] = opts.log | ||
165 | self._script["errorOnFail"] = opts.errorOnFail | ||
166 | if hasattr(opts, "nochroot"): | ||
167 | self._script["chroot"] = not opts.nochroot | ||
168 | |||
169 | class PreScriptSection(ScriptSection): | ||
170 | sectionOpen = "%pre" | ||
171 | |||
172 | def _resetScript(self): | ||
173 | ScriptSection._resetScript(self) | ||
174 | self._script["type"] = KS_SCRIPT_PRE | ||
175 | |||
176 | class PostScriptSection(ScriptSection): | ||
177 | sectionOpen = "%post" | ||
178 | |||
179 | def _getParser(self): | ||
180 | op = ScriptSection._getParser(self) | ||
181 | op.add_option("--nochroot", dest="nochroot", action="store_true", | ||
182 | default=False) | ||
183 | return op | ||
184 | |||
185 | def _resetScript(self): | ||
186 | ScriptSection._resetScript(self) | ||
187 | self._script["chroot"] = True | ||
188 | self._script["type"] = KS_SCRIPT_POST | ||
189 | |||
190 | class TracebackScriptSection(ScriptSection): | ||
191 | sectionOpen = "%traceback" | ||
192 | |||
193 | def _resetScript(self): | ||
194 | ScriptSection._resetScript(self) | ||
195 | self._script["type"] = KS_SCRIPT_TRACEBACK | ||
196 | |||
197 | class PackageSection(Section): | ||
198 | sectionOpen = "%packages" | ||
199 | |||
200 | def handleLine(self, line): | ||
201 | if not self.handler: | ||
202 | return | ||
203 | |||
204 | (h, s, t) = line.partition('#') | ||
205 | line = h.rstrip() | ||
206 | |||
207 | self.handler.packages.add([line]) | ||
208 | |||
209 | def handleHeader(self, lineno, args): | ||
210 | """Process the arguments to the %packages header and set attributes | ||
211 | on the Version's Packages instance appropriate. This method may be | ||
212 | overridden in a subclass if necessary. | ||
213 | """ | ||
214 | Section.handleHeader(self, lineno, args) | ||
215 | op = KSOptionParser(version=self.version) | ||
216 | op.add_option("--excludedocs", dest="excludedocs", action="store_true", | ||
217 | default=False) | ||
218 | op.add_option("--ignoremissing", dest="ignoremissing", | ||
219 | action="store_true", default=False) | ||
220 | op.add_option("--nobase", dest="nobase", action="store_true", | ||
221 | default=False) | ||
222 | op.add_option("--ignoredeps", dest="resolveDeps", action="store_false", | ||
223 | deprecated=FC4, removed=F9) | ||
224 | op.add_option("--resolvedeps", dest="resolveDeps", action="store_true", | ||
225 | deprecated=FC4, removed=F9) | ||
226 | op.add_option("--default", dest="defaultPackages", action="store_true", | ||
227 | default=False, introduced=F7) | ||
228 | op.add_option("--instLangs", dest="instLangs", type="string", | ||
229 | default="", introduced=F9) | ||
230 | |||
231 | (opts, extra) = op.parse_args(args=args[1:], lineno=lineno) | ||
232 | |||
233 | self.handler.packages.excludeDocs = opts.excludedocs | ||
234 | self.handler.packages.addBase = not opts.nobase | ||
235 | if opts.ignoremissing: | ||
236 | self.handler.packages.handleMissing = KS_MISSING_IGNORE | ||
237 | else: | ||
238 | self.handler.packages.handleMissing = KS_MISSING_PROMPT | ||
239 | |||
240 | if opts.defaultPackages: | ||
241 | self.handler.packages.default = True | ||
242 | |||
243 | if opts.instLangs: | ||
244 | self.handler.packages.instLangs = opts.instLangs | ||
diff --git a/scripts/lib/wic/3rdparty/pykickstart/version.py b/scripts/lib/wic/3rdparty/pykickstart/version.py new file mode 100644 index 0000000000..102cc37d80 --- /dev/null +++ b/scripts/lib/wic/3rdparty/pykickstart/version.py | |||
@@ -0,0 +1,197 @@ | |||
1 | # | ||
2 | # Chris Lumens <clumens@redhat.com> | ||
3 | # | ||
4 | # Copyright 2006, 2007, 2008, 2009, 2010 Red Hat, Inc. | ||
5 | # | ||
6 | # This copyrighted material is made available to anyone wishing to use, modify, | ||
7 | # copy, or redistribute it subject to the terms and conditions of the GNU | ||
8 | # General Public License v.2. This program is distributed in the hope that it | ||
9 | # will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the | ||
10 | # implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
11 | # See the GNU General Public License for more details. | ||
12 | # | ||
13 | # You should have received a copy of the GNU General Public License along with | ||
14 | # this program; if not, write to the Free Software Foundation, Inc., 51 | ||
15 | # Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Any Red Hat | ||
16 | # trademarks that are incorporated in the source code or documentation are not | ||
17 | # subject to the GNU General Public License and may only be used or replicated | ||
18 | # with the express permission of Red Hat, Inc. | ||
19 | # | ||
20 | """ | ||
21 | Methods for working with kickstart versions. | ||
22 | |||
23 | This module defines several symbolic constants that specify kickstart syntax | ||
24 | versions. Each version corresponds roughly to one release of Red Hat Linux, | ||
25 | Red Hat Enterprise Linux, or Fedora Core as these are where most syntax | ||
26 | changes take place. | ||
27 | |||
28 | This module also exports several functions: | ||
29 | |||
30 | makeVersion - Given a version number, return an instance of the | ||
31 | matching handler class. | ||
32 | |||
33 | returnClassForVersion - Given a version number, return the matching | ||
34 | handler class. This does not return an | ||
35 | instance of that class, however. | ||
36 | |||
37 | stringToVersion - Convert a string representation of a version number | ||
38 | into the symbolic constant. | ||
39 | |||
40 | versionToString - Perform the reverse mapping. | ||
41 | |||
42 | versionFromFile - Read a kickstart file and determine the version of | ||
43 | syntax it uses. This requires the kickstart file to | ||
44 | have a version= comment in it. | ||
45 | """ | ||
46 | import imputil, re, sys | ||
47 | from urlgrabber import urlopen | ||
48 | |||
49 | import gettext | ||
50 | _ = lambda x: gettext.ldgettext("pykickstart", x) | ||
51 | |||
52 | from pykickstart.errors import KickstartVersionError | ||
53 | |||
54 | # Symbolic names for internal version numbers. | ||
55 | RHEL3 = 900 | ||
56 | FC3 = 1000 | ||
57 | RHEL4 = 1100 | ||
58 | FC4 = 2000 | ||
59 | FC5 = 3000 | ||
60 | FC6 = 4000 | ||
61 | RHEL5 = 4100 | ||
62 | F7 = 5000 | ||
63 | F8 = 6000 | ||
64 | F9 = 7000 | ||
65 | F10 = 8000 | ||
66 | F11 = 9000 | ||
67 | F12 = 10000 | ||
68 | F13 = 11000 | ||
69 | RHEL6 = 11100 | ||
70 | F14 = 12000 | ||
71 | F15 = 13000 | ||
72 | F16 = 14000 | ||
73 | |||
74 | # This always points at the latest version and is the default. | ||
75 | DEVEL = F16 | ||
76 | |||
77 | # A one-to-one mapping from string representations to version numbers. | ||
78 | versionMap = { | ||
79 | "DEVEL": DEVEL, | ||
80 | "FC3": FC3, "FC4": FC4, "FC5": FC5, "FC6": FC6, "F7": F7, "F8": F8, | ||
81 | "F9": F9, "F10": F10, "F11": F11, "F12": F12, "F13": F13, | ||
82 | "F14": F14, "F15": F15, "F16": F16, | ||
83 | "RHEL3": RHEL3, "RHEL4": RHEL4, "RHEL5": RHEL5, "RHEL6": RHEL6 | ||
84 | } | ||
85 | |||
86 | def stringToVersion(s): | ||
87 | """Convert string into one of the provided version constants. Raises | ||
88 | KickstartVersionError if string does not match anything. | ||
89 | """ | ||
90 | # First try these short forms. | ||
91 | try: | ||
92 | return versionMap[s.upper()] | ||
93 | except KeyError: | ||
94 | pass | ||
95 | |||
96 | # Now try the Fedora versions. | ||
97 | m = re.match("^fedora.* (\d+)$", s, re.I) | ||
98 | |||
99 | if m and m.group(1): | ||
100 | if versionMap.has_key("FC" + m.group(1)): | ||
101 | return versionMap["FC" + m.group(1)] | ||
102 | elif versionMap.has_key("F" + m.group(1)): | ||
103 | return versionMap["F" + m.group(1)] | ||
104 | else: | ||
105 | raise KickstartVersionError(_("Unsupported version specified: %s") % s) | ||
106 | |||
107 | # Now try the RHEL versions. | ||
108 | m = re.match("^red hat enterprise linux.* (\d+)([\.\d]*)$", s, re.I) | ||
109 | |||
110 | if m and m.group(1): | ||
111 | if versionMap.has_key("RHEL" + m.group(1)): | ||
112 | return versionMap["RHEL" + m.group(1)] | ||
113 | else: | ||
114 | raise KickstartVersionError(_("Unsupported version specified: %s") % s) | ||
115 | |||
116 | # If nothing else worked, we're out of options. | ||
117 | raise KickstartVersionError(_("Unsupported version specified: %s") % s) | ||
118 | |||
119 | def versionToString(version, skipDevel=False): | ||
120 | """Convert version into a string representation of the version number. | ||
121 | This is the reverse operation of stringToVersion. Raises | ||
122 | KickstartVersionError if version does not match anything. | ||
123 | """ | ||
124 | if not skipDevel and version == versionMap["DEVEL"]: | ||
125 | return "DEVEL" | ||
126 | |||
127 | for (key, val) in versionMap.iteritems(): | ||
128 | if key == "DEVEL": | ||
129 | continue | ||
130 | elif val == version: | ||
131 | return key | ||
132 | |||
133 | raise KickstartVersionError(_("Unsupported version specified: %s") % version) | ||
134 | |||
135 | def versionFromFile(f): | ||
136 | """Given a file or URL, look for a line starting with #version= and | ||
137 | return the version number. If no version is found, return DEVEL. | ||
138 | """ | ||
139 | v = DEVEL | ||
140 | |||
141 | fh = urlopen(f) | ||
142 | |||
143 | while True: | ||
144 | try: | ||
145 | l = fh.readline() | ||
146 | except StopIteration: | ||
147 | break | ||
148 | |||
149 | # At the end of the file? | ||
150 | if l == "": | ||
151 | break | ||
152 | |||
153 | if l.isspace() or l.strip() == "": | ||
154 | continue | ||
155 | |||
156 | if l[:9] == "#version=": | ||
157 | v = stringToVersion(l[9:].rstrip()) | ||
158 | break | ||
159 | |||
160 | fh.close() | ||
161 | return v | ||
162 | |||
163 | def returnClassForVersion(version=DEVEL): | ||
164 | """Return the class of the syntax handler for version. version can be | ||
165 | either a string or the matching constant. Raises KickstartValueError | ||
166 | if version does not match anything. | ||
167 | """ | ||
168 | try: | ||
169 | version = int(version) | ||
170 | module = "%s" % versionToString(version, skipDevel=True) | ||
171 | except ValueError: | ||
172 | module = "%s" % version | ||
173 | version = stringToVersion(version) | ||
174 | |||
175 | module = module.lower() | ||
176 | |||
177 | try: | ||
178 | import pykickstart.handlers | ||
179 | sys.path.extend(pykickstart.handlers.__path__) | ||
180 | found = imputil.imp.find_module(module) | ||
181 | loaded = imputil.imp.load_module(module, found[0], found[1], found[2]) | ||
182 | |||
183 | for (k, v) in loaded.__dict__.iteritems(): | ||
184 | if k.lower().endswith("%shandler" % module): | ||
185 | return v | ||
186 | except: | ||
187 | raise KickstartVersionError(_("Unsupported version specified: %s") % version) | ||
188 | |||
189 | def makeVersion(version=DEVEL): | ||
190 | """Return a new instance of the syntax handler for version. version can be | ||
191 | either a string or the matching constant. This function is useful for | ||
192 | standalone programs which just need to handle a specific version of | ||
193 | kickstart syntax (as provided by a command line argument, for example) | ||
194 | and need to instantiate the correct object. | ||
195 | """ | ||
196 | cl = returnClassForVersion(version) | ||
197 | return cl() | ||