def parse_boot_cmdline(self, cmdline, values=None): """ Parse the boot cmdline and set appropriate values according to the options set by add_option. cmdline can be given as a string (to be parsed by BootArgs), or a dict (or any object with .iteritems()) of {bootarg:value} pairs. If cmdline is None, the cmdline data will be whatever BootArgs reads by default (/proc/cmdline, /run/initramfs/etc/cmdline, /etc/cmdline). If an option requires a value but the boot arg doesn't provide one, we'll quietly not set anything. """ if cmdline is None or type(cmdline) is str: bootargs = BootArgs(cmdline) else: bootargs = cmdline self.deprecated_bootargs = [] for arg, val in bootargs.iteritems(): option = self._get_bootarg_option(arg) if option is None: continue if option.takes_value() and val is None: continue # TODO: emit a warning or something there? if option.action == "store_true" and val in ("0", "no", "off"): # special case: "mpath=0" would otherwise set mpath to True setattr(values, option.dest, False) continue option.process(arg, val, values, self) return values
def parse_boot_cmdline(self, boot_cmdline): """ Parse the boot cmdline and create an appropriate Namespace instance according to the option definitions set by add_argument. boot_cmdline can be given as a string (to be parsed by BootArgs), or a dict (or any object with .iteritems()) of {bootarg:value} pairs. If boot_cmdline is None, the boot_cmdline data will be whatever BootArgs reads by default (/proc/cmdline, /run/initramfs/etc/cmdline, /etc/cmdline). If an option requires a value but the boot arg doesn't provide one, we'll quietly not set anything in the Namespace. We also skip any boot options that were not specified by add_argument as we don't care about them (there will usually be quite a lot of them (rd.*, etc.). :param boot_cmdline: the Anaconda boot command line arguments :type boot_cmdline: string, dict or None :returns: an argparse Namespace instance :rtype: Namespace """ namespace = Namespace() if boot_cmdline is None or type(boot_cmdline) is str: bootargs = BootArgs(boot_cmdline) else: bootargs = boot_cmdline self.deprecated_bootargs = [] # go over all options corresponding to current boot cmdline # and do any modifications necessary # NOTE: program cmdline overrides boot cmdline for arg, val in bootargs.iteritems(): option = self._get_bootarg_option(arg) if option is None: # this boot option is unknown to Anaconda, skip it continue if option.nargs != 0 and val is None: # nargs == 0 -> the option expects one or more arguments but the # boot option was not given any, so we skip it log.warning( "boot option specified without expected number of " "arguments and will be ignored: %s", arg) continue if option.nargs == 0 and option.const is not None: # nargs == 0 & constr == True -> store_true # (we could also check the class, but it begins with an # underscore, so it would be ugly) # special case: "mpath=0" would otherwise set mpath to True if option.const is True and val in ("0", "no", "off"): setattr(namespace, option.dest, False) # Set all other set_const cases to the const specified else: setattr(namespace, option.dest, option.const) # anaconda considers cases such as noselinux=off to be a negative # concord, which is to say that selinux will be set to False and # we hate you. continue option(self, namespace, val) return namespace