def setupSections(self): """Install the sections all kickstart files support. You may override this method in a subclass, but should avoid doing so unless you know what you're doing. """ self._sections = {} # Install the sections all kickstart files support. self.registerSection(PreScriptSection(self.handler, dataObj=Script)) self.registerSection(PreInstallScriptSection(self.handler, dataObj=Script)) self.registerSection(PostScriptSection(self.handler, dataObj=Script)) self.registerSection(TracebackScriptSection(self.handler, dataObj=Script)) self.registerSection(PackageSection(self.handler)) # Whitelist well-known sections that pykickstart does not understand, # but shouldn't error on. self.registerSection(NullSection(self.handler, sectionOpen="%addon")) self.registerSection(NullSection(self.handler, sectionOpen="%anaconda"))
def setupSections(self): self.registerSection(PreScriptSection(self.handler, dataObj=AnacondaKSScript)) self.registerSection(NullSection(self.handler, sectionOpen="%pre-install")) self.registerSection(NullSection(self.handler, sectionOpen="%post")) self.registerSection(NullSection(self.handler, sectionOpen="%onerror")) self.registerSection(NullSection(self.handler, sectionOpen="%traceback")) self.registerSection(NullSection(self.handler, sectionOpen="%packages")) self.registerSection(NullSection(self.handler, sectionOpen="%addon")) self.registerSection(NullSection(self.handler.anaconda, sectionOpen="%anaconda"))
def _stateMachine(self, lineIter): # For error reporting. lineno = 0 while True: # Get the next line out of the file, quitting if this is the last line. try: self._line = next(lineIter) if self._line == "": break except StopIteration: break lineno += 1 # Eliminate blank lines, whitespace-only lines, and comments. if self._isBlankOrComment(self._line): self._handleSpecialComments(self._line) continue # Split the line, discarding comments. args = shlex.split(self._line, comments=True) if args[0] == "%include": if len(args) == 1 or not args[1]: raise KickstartParseError(formatErrorMsg(lineno)) self._handleInclude(args[1]) continue # Now on to the main event. if self._state == STATE_COMMANDS: if args[0] == "%ksappend": # This is handled by the preprocess* functions, so continue. continue elif args[0][0] == '%': # This is the beginning of a new section. Handle its header # here. newSection = args[0] if not self._validState(newSection): if self.unknownSectionIsFatal: raise KickstartParseError(formatErrorMsg(lineno, msg=_("Unknown kickstart section: %s") % newSection)) else: # If we are ignoring unknown section errors, just create a new # NullSection for the header we just saw. Then nothing else # needs to change. You can turn this warning into an error via # ksvalidator, or the warnings module. warnings.warn(_("Potentially unknown section seen at line %(lineno)s: %(sectionName)s") % {"lineno": lineno, "sectionName": newSection}) self.registerSection(NullSection(self.handler, sectionOpen=newSection)) self._state = newSection obj = self._sections[self._state] self._tryFunc(lambda: obj.handleHeader(lineno, args)) # This will handle all section processing, kicking us back # out to STATE_COMMANDS at the end with the current line # being the next section header, etc. lineno = self._readSection(lineIter, lineno) else: # This is a command in the command section. Dispatch to it. self._tryFunc(lambda: self.handleCommand(lineno, args)) elif self._state == STATE_END: break elif self._includeDepth > 0: lineIter.put(self._line) lineno -= 1 lineno = self._readSection(lineIter, lineno)