예제 #1
0
파일: ksparser.py 프로젝트: linearlog1/poky
 def _parse(self, parser, confpath):
     """
     Parse file in .wks format using provided parser.
     """
     with open(confpath) as conf:
         lineno = 0
         for line in conf:
             line = line.strip()
             lineno += 1
             if line and line[0] != '#':
                 try:
                     parsed = parser.parse_args(shlex.split(line))
                 except ArgumentError as err:
                     raise KickStartError('%s:%d: %s' % \
                                          (confpath, lineno, err))
                 if line.startswith('part'):
                     self.partnum += 1
                     self.partitions.append(Partition(parsed, self.partnum))
                 elif line.startswith('include'):
                     self._parse(parser, parsed.path)
                 elif line.startswith('bootloader'):
                     if not self.bootloader:
                         self.bootloader = parsed
                     else:
                         err = "%s:%d: more than one bootloader specified" \
                                   % (confpath, lineno)
                         raise KickStartError(err)
예제 #2
0
    def _parse(self, parser, confpath):
        """
        Parse file in .wks format using provided parser.
        """
        with open(confpath) as conf:
            lineno = 0
            for line in conf:
                line = line.strip()
                lineno += 1
                if line and line[0] != '#':
                    try:
                        line_args = shlex.split(line)
                        parsed = parser.parse_args(line_args)
                    except ArgumentError as err:
                        raise KickStartError('%s:%d: %s' % \
                                             (confpath, lineno, err))
                    if line.startswith('part'):
                        # SquashFS does not support UUID
                        if parsed.fstype == 'squashfs' and parsed.use_uuid:
                            err = "%s:%d: SquashFS does not support UUID" \
                                  % (confpath, lineno)
                            raise KickStartError(err)
                        # using ArgumentParser one cannot easily tell if option
                        # was passed as argument, if said option has a default
                        # value; --overhead-factor/--extra-space cannot be used
                        # with --fixed-size, so at least detect when these were
                        # passed with non-0 values ...
                        if parsed.fixed_size:
                            if parsed.overhead_factor or parsed.extra_space:
                                err = "%s:%d: arguments --overhead-factor and --extra-space not "\
                                      "allowed with argument --fixed-size" \
                                      % (confpath, lineno)
                                raise KickStartError(err)
                        else:
                            # ... and provide defaults if not using
                            # --fixed-size iff given option was not used
                            # (again, one cannot tell if option was passed but
                            # with value equal to 0)
                            if '--overhead-factor' not in line_args:
                                parsed.overhead_factor = self.DEFAULT_OVERHEAD_FACTOR
                            if '--extra-space' not in line_args:
                                parsed.extra_space = self.DEFAULT_EXTRA_SPACE

                        self.partnum += 1
                        self.partitions.append(Partition(parsed, self.partnum))
                    elif line.startswith('include'):
                        self._parse(parser, parsed.path)
                    elif line.startswith('bootloader'):
                        if not self.bootloader:
                            self.bootloader = parsed
                        else:
                            err = "%s:%d: more than one bootloader specified" \
                                      % (confpath, lineno)
                            raise KickStartError(err)
예제 #3
0
    def _parse(self, parser, confpath):
        """
        Parse file in .wks format using provided parser.
        """
        with open(confpath) as conf:
            lineno = 0
            for line in conf:
                line = line.strip()
                lineno += 1
                if line and line[0] != '#':
                    line = expand_line(line)
                    try:
                        line_args = shlex.split(line)
                        parsed = parser.parse_args(line_args)
                    except ArgumentError as err:
                        raise KickStartError('%s:%d: %s' % \
                                             (confpath, lineno, err))
                    if line.startswith('part'):
                        # SquashFS does not support filesystem UUID
                        if parsed.fstype == 'squashfs':
                            if parsed.fsuuid:
                                err = "%s:%d: SquashFS does not support UUID" \
                                       % (confpath, lineno)
                                raise KickStartError(err)
                            if parsed.label:
                                err = "%s:%d: SquashFS does not support LABEL" \
                                       % (confpath, lineno)
                                raise KickStartError(err)
                        # erofs does not support filesystem labels
                        if parsed.fstype == 'erofs' and parsed.label:
                            err = "%s:%d: erofs does not support LABEL" % (confpath, lineno)
                            raise KickStartError(err)
                        if parsed.fstype == 'msdos' or parsed.fstype == 'vfat':
                            if parsed.fsuuid:
                                if parsed.fsuuid.upper().startswith('0X'):
                                    if len(parsed.fsuuid) > 10:
                                        err = "%s:%d: fsuuid %s given in wks kickstart file " \
                                              "exceeds the length limit for %s filesystem. " \
                                              "It should be in the form of a 32 bit hexadecimal" \
                                              "number (for example, 0xABCD1234)." \
                                              % (confpath, lineno, parsed.fsuuid, parsed.fstype)
                                        raise KickStartError(err)
                                elif len(parsed.fsuuid) > 8:
                                    err = "%s:%d: fsuuid %s given in wks kickstart file " \
                                          "exceeds the length limit for %s filesystem. " \
                                          "It should be in the form of a 32 bit hexadecimal" \
                                          "number (for example, 0xABCD1234)." \
                                          % (confpath, lineno, parsed.fsuuid, parsed.fstype)
                                    raise KickStartError(err)
                        if parsed.use_label and not parsed.label:
                            err = "%s:%d: Must set the label with --label" \
                                  % (confpath, lineno)
                            raise KickStartError(err)
                        # using ArgumentParser one cannot easily tell if option
                        # was passed as argument, if said option has a default
                        # value; --overhead-factor/--extra-space cannot be used
                        # with --fixed-size, so at least detect when these were
                        # passed with non-0 values ...
                        if parsed.fixed_size:
                            if parsed.overhead_factor or parsed.extra_space:
                                err = "%s:%d: arguments --overhead-factor and --extra-space not "\
                                      "allowed with argument --fixed-size" \
                                      % (confpath, lineno)
                                raise KickStartError(err)
                        else:
                            # ... and provide defaults if not using
                            # --fixed-size iff given option was not used
                            # (again, one cannot tell if option was passed but
                            # with value equal to 0)
                            if '--overhead-factor' not in line_args:
                                parsed.overhead_factor = self.DEFAULT_OVERHEAD_FACTOR
                            if '--extra-space' not in line_args:
                                parsed.extra_space = self.DEFAULT_EXTRA_SPACE

                        self.partnum += 1
                        self.partitions.append(Partition(parsed, self.partnum))
                    elif line.startswith('include'):
                        self._parse(parser, parsed.path)
                    elif line.startswith('bootloader'):
                        if not self.bootloader:
                            self.bootloader = parsed
                            # Concatenate the strings set in APPEND
                            append_var = get_bitbake_var("APPEND")
                            if append_var:
                                self.bootloader.append = ' '.join(filter(None, \
                                                         (self.bootloader.append, append_var)))
                        else:
                            err = "%s:%d: more than one bootloader specified" \
                                      % (confpath, lineno)
                            raise KickStartError(err)