Пример #1
0
    def set_from_line(self, line, replace=None):
        (com, arg) = GrubConf.grub_exact_split(line, 2)
        com = com.lower()

        # Special handling for mboot.c32
        if com.lower() == "append" and self.kernel is not None:
            (_, kernel) = self.kernel
            if kernel.endswith("mboot.c32"):
                kernel = None
                args = None
                initrd = None
                modules = arg.split("---")

                if len(modules) == 3:  # Assume Xen + Kernel + Initrd
                    (_, kernel, initrd) = modules
                elif len(modules) == 2:  # Assume Kernel + Initrd
                    (kernel, initrd) = modules

                if kernel:
                    setattr(self, "kernel", kernel.strip())
                if initrd:
                    setattr(self, "initrd", initrd.strip())

                # Bypass regular self.commands handling
                com = None
            elif arg.find("initrd="):
                # find initrd image in append line
                args = arg.strip().split(" ")
                for a in args:
                    if a.lower().startswith("initrd="):
                        setattr(self, "initrd", a.replace("initrd=", ""))
                        arg = arg.replace(a, "")

        if com is not None and self.commands.has_key(com):
            if self.commands[com] is not None:
                setattr(self, self.commands[com],
                        re.sub('^"(.+)"$', r"\1", arg.strip()))
            else:
                logging.info("Ignored image directive %s" % (com, ))
        elif com is not None:
            logging.warning("Unknown image directive %s" % (com, ))

        # now put the line in the list of lines
        if replace is None:
            self.lines.append(line)
        else:
            self.lines.pop(replace)
            self.lines.insert(replace, line)
Пример #2
0
    def set_from_line(self, line, replace = None):
        (com, arg) = GrubConf.grub_exact_split(line, 2)
        com = com.lower()

        # Special handling for mboot.c32
        if com.lower() == "append" and self.kernel is not None:
            (_,kernel) = self.kernel
            if kernel.endswith("mboot.c32"):
                kernel = None
                args = None
                initrd = None
                modules = arg.split("---")

                if len(modules) == 3: # Assume Xen + Kernel + Initrd
                    (_,kernel,initrd) = modules
                elif len(modules) == 2: # Assume Kernel + Initrd
                    (kernel,initrd) = modules

                if kernel:
                    setattr(self, "kernel", kernel.strip())
                if initrd:
                    setattr(self, "initrd", initrd.strip())

                # Bypass regular self.commands handling
                com = None
            elif "initrd=" in arg:
                # find initrd image in append line
                args = arg.strip().split(" ")
                for a in args:
                    if a.lower().startswith("initrd="):
                        setattr(self, "initrd", a.replace("initrd=", ""))
                        arg = arg.replace(a, "")

        if com is not None and self.commands.has_key(com):
            if self.commands[com] is not None:
                setattr(self, self.commands[com], re.sub('^"(.+)"$', r"\1", arg.strip()))
            else:
                logging.info("Ignored image directive %s" %(com,))
        elif com is not None:
            logging.warning("Unknown image directive %s" %(com,))

        # now put the line in the list of lines
        if replace is None:
            self.lines.append(line)
        else:
            self.lines.pop(replace)
            self.lines.insert(replace, line)
Пример #3
0
    def set_from_line(self, line, replace = None):
        (com, arg) = GrubConf.grub_exact_split(line, 2)

        if self.commands.has_key(com):
            if self.commands[com] is not None:
                setattr(self, self.commands[com], re.sub('^"(.+)"$', r"\1", arg.strip()))
            else:
                logging.info("Ignored image directive %s" %(com,))
        else:
            logging.warning("Unknown image directive %s" %(com,))

        # now put the line in the list of lines
        if replace is None:
            self.lines.append(line)
        else:
            self.lines.pop(replace)
            self.lines.insert(replace, line)
Пример #4
0
    def set_from_line(self, line, replace=None):
        (com, arg) = GrubConf.grub_exact_split(line, 2)

        if self.commands.has_key(com):
            if self.commands[com] is not None:
                setattr(self, self.commands[com],
                        re.sub('^"(.+)"$', r"\1", arg.strip()))
            else:
                logging.info("Ignored image directive %s" % (com, ))
        else:
            logging.warning("Unknown image directive %s" % (com, ))

        # now put the line in the list of lines
        if replace is None:
            self.lines.append(line)
        else:
            self.lines.pop(replace)
            self.lines.insert(replace, line)
Пример #5
0
    def parse(self, buf=None):
        if buf is None:
            if self.filename is None:
                raise ValueError, "No config file defined to parse!"

            f = open(self.filename, 'r')
            lines = f.readlines()
            f.close()
        else:
            lines = buf.split("\n")

        path = os.path.dirname(self.filename)
        img = []
        for l in lines:
            l = l.strip()
            # skip blank lines
            if len(l) == 0:
                continue
            # skip comments
            if l.startswith('#'):
                continue
            # new image
            if l.lower().startswith("label"):
                if len(img) > 0:
                    self.add_image(ExtLinuxImage(img, path))
                img = [l]
                continue

            if len(img) > 0:
                img.append(l)
                continue

            (com, arg) = GrubConf.grub_exact_split(l, 2)
            com = com.lower()
            if self.commands.has_key(com):
                if self.commands[com] is not None:
                    setattr(self, self.commands[com], arg.strip())
                else:
                    logging.info("Ignored directive %s" % (com, ))
            else:
                logging.warning("Unknown directive %s" % (com, ))

        if len(img) > 0:
            self.add_image(ExtLinuxImage(img, path))
Пример #6
0
    def parse(self, buf = None):
        if buf is None:
            if self.filename is None:
                raise ValueError, "No config file defined to parse!"

            f = open(self.filename, 'r')
            lines = f.readlines()
            f.close()
        else:
            lines = buf.split("\n")

        path = os.path.dirname(self.filename)
        img = []
        for l in lines:
            l = l.strip()
            # skip blank lines
            if len(l) == 0:
                continue
            # skip comments
            if l.startswith('#'):
                continue
            # new image
            if l.lower().startswith("label"):
                if len(img) > 0:
                    self.add_image(ExtLinuxImage(img, path))
                img = [l]
                continue

            if len(img) > 0:
                img.append(l)
                continue

            (com, arg) = GrubConf.grub_exact_split(l, 2)
            com = com.lower()
            if self.commands.has_key(com):
                if self.commands[com] is not None:
                    setattr(self, self.commands[com], arg.strip())
                else:
                    logging.info("Ignored directive %s" %(com,))
            else:
                logging.warning("Unknown directive %s" %(com,))

        if len(img) > 0:
            self.add_image(ExtLinuxImage(img, path))