示例#1
0
文件: __init__.py 项目: shenki/poky
def read_kickstart(path):
    """Parse a kickstart file and return a KickstartParser instance.

    This is a simple utility function which takes a path to a kickstart file,
    parses it and returns a pykickstart KickstartParser instance which can
    be then passed to an ImageCreator constructor.

    If an error occurs, a CreatorError exception is thrown.
    """

    # version = ksversion.makeVersion()
    # ks = ksparser.KickstartParser(version)

    using_version = ksversion.DEVEL
    commandMap[using_version]["bootloader"] = wicboot.Wic_Bootloader
    commandMap[using_version]["part"] = partition.Wic_Partition
    commandMap[using_version]["partition"] = partition.Wic_Partition
    dataMap[using_version]["PartData"] = partition.Wic_PartData
    superclass = ksversion.returnClassForVersion(version=using_version)

    class KSHandlers(superclass):
        def __init__(self):
            superclass.__init__(self, mapping=commandMap[using_version])

    kickstart = ksparser.KickstartParser(KSHandlers(), errorsAreFatal=True)

    try:
        kickstart.readKickstart(path)
    except (kserrors.KickstartParseError, kserrors.KickstartError), err:
        msger.warning("Errors occurred when parsing kickstart file: %s\n" % path)
        msger.error("%s" % err)
示例#2
0
    def prepare_empty_partition_squashfs(self, cr_workdir, oe_builddir,
                                         native_sysroot):
        """
        Prepare an empty squashfs partition.
        """
        msger.warning("Creating of an empty squashfs %s partition was attempted. " \
                      "Proceeding as requested." % self.mountpoint)

        path = "%s/fs_%s.%s" % (cr_workdir, self.label, self.fstype)
        if os.path.isfile(path):
            os.remove(path)

        # it is not possible to create a squashfs without source data,
        # thus prepare an empty temp dir that is used as source
        tmpdir = tempfile.mkdtemp()

        squashfs_cmd = "mksquashfs %s %s -noappend" % \
                       (tmpdir, path)
        exec_native_cmd(squashfs_cmd, native_sysroot)

        os.rmdir(tmpdir)

        # get the rootfs size in the right units for kickstart (kB)
        du_cmd = "du -Lbks %s" % path
        out = exec_cmd(du_cmd)
        fs_size = out.split()[0]

        self.size = int(fs_size)
示例#3
0
文件: __init__.py 项目: vmoesker/poky
def read_kickstart(path):
    """Parse a kickstart file and return a KickstartParser instance.

    This is a simple utility function which takes a path to a kickstart file,
    parses it and returns a pykickstart KickstartParser instance which can
    be then passed to an ImageCreator constructor.

    If an error occurs, a CreatorError exception is thrown.
    """

    #version = ksversion.makeVersion()
    #ks = ksparser.KickstartParser(version)

    using_version = ksversion.DEVEL
    commandMap[using_version]["bootloader"] = wicboot.Wic_Bootloader
    commandMap[using_version]["part"] = partition.Wic_Partition
    commandMap[using_version]["partition"] = partition.Wic_Partition
    dataMap[using_version]["PartData"] = partition.Wic_PartData
    superclass = ksversion.returnClassForVersion(version=using_version)

    class KSHandlers(superclass):
        def __init__(self):
            superclass.__init__(self, mapping=commandMap[using_version])

    kickstart = ksparser.KickstartParser(KSHandlers(), errorsAreFatal=True)

    try:
        kickstart.readKickstart(path)
    except (kserrors.KickstartParseError, kserrors.KickstartError), err:
        msger.warning("Errors occurred when parsing kickstart file: %s\n" %
                      path)
        msger.error("%s" % err)
示例#4
0
    def prepare_rootfs(self, cr_workdir, oe_builddir, rootfs_dir,
                       native_sysroot):
        """
        Prepare content for a rootfs partition i.e. create a partition
        and fill it from a /rootfs dir.

        Currently handles ext2/3/4, btrfs and vfat.
        """
        p_prefix = os.environ.get("PSEUDO_PREFIX", "%s/usr" % native_sysroot)
        p_localstatedir = os.environ.get("PSEUDO_LOCALSTATEDIR",
                                         "%s/../pseudo" % rootfs_dir)
        p_passwd = os.environ.get("PSEUDO_PASSWD", rootfs_dir)
        p_nosymlinkexp = os.environ.get("PSEUDO_NOSYMLINKEXP", "1")
        pseudo = "export PSEUDO_PREFIX=%s;" % p_prefix
        pseudo += "export PSEUDO_LOCALSTATEDIR=%s;" % p_localstatedir
        pseudo += "export PSEUDO_PASSWD=%s;" % p_passwd
        pseudo += "export PSEUDO_NOSYMLINKEXP=%s;" % p_nosymlinkexp
        pseudo += "%s " % get_bitbake_var("FAKEROOTCMD")

        rootfs = "%s/rootfs_%s.%s.%s" % (cr_workdir, self.label, self.lineno,
                                         self.fstype)
        if os.path.isfile(rootfs):
            os.remove(rootfs)

        if not self.fstype:
            msger.error("File system for partition %s not specified in kickstart, " \
                        "use --fstype option" % (self.mountpoint))

        # Get rootfs size from bitbake variable if it's not set in .ks file
        if not self.size:
            # Bitbake variable ROOTFS_SIZE is calculated in
            # Image._get_rootfs_size method from meta/lib/oe/image.py
            # using IMAGE_ROOTFS_SIZE, IMAGE_ROOTFS_ALIGNMENT,
            # IMAGE_OVERHEAD_FACTOR and IMAGE_ROOTFS_EXTRA_SPACE
            rsize_bb = get_bitbake_var('ROOTFS_SIZE')
            if rsize_bb:
                msger.warning(
                    'overhead-factor was specified, but size was not,'
                    ' so bitbake variables will be used for the size.'
                    ' In this case both IMAGE_OVERHEAD_FACTOR and '
                    '--overhead-factor will be applied')
                self.size = int(round(float(rsize_bb)))

        for prefix in ("ext", "btrfs", "vfat", "squashfs"):
            if self.fstype.startswith(prefix):
                method = getattr(self, "prepare_rootfs_" + prefix)
                method(rootfs, oe_builddir, rootfs_dir, native_sysroot, pseudo)

                self.source_file = rootfs

                # get the rootfs size in the right units for kickstart (kB)
                du_cmd = "du -Lbks %s" % rootfs
                out = exec_cmd(du_cmd)
                self.size = int(out.split()[0])

                break
示例#5
0
文件: ksparser.py 项目: sstiller/poky
    def __init__(self, confpath):

        self.partitions = []
        self.bootloader = None
        self.lineno = 0
        self.partnum = 0

        parser = KickStartParser()
        subparsers = parser.add_subparsers()

        part = subparsers.add_parser('part')
        part.add_argument('mountpoint', nargs='?')
        part.add_argument('--active', action='store_true')
        part.add_argument('--align', type=int)
        part.add_argument('--exclude-path', nargs='+')
        part.add_argument("--extra-space", type=sizetype)
        part.add_argument('--fsoptions', dest='fsopts')
        part.add_argument('--fstype')
        part.add_argument('--label')
        part.add_argument('--no-table', action='store_true')
        part.add_argument('--ondisk', '--ondrive', dest='disk', default='sda')
        part.add_argument("--overhead-factor", type=overheadtype)
        part.add_argument('--part-type')
        part.add_argument('--rootfs-dir')

        # --size and --fixed-size cannot be specified together; options
        # ----extra-space and --overhead-factor should also raise a parser
        # --error, but since nesting mutually exclusive groups does not work,
        # ----extra-space/--overhead-factor are handled later
        sizeexcl = part.add_mutually_exclusive_group()
        sizeexcl.add_argument('--size', type=sizetype, default=0)
        sizeexcl.add_argument('--fixed-size', type=sizetype, default=0)

        part.add_argument('--source')
        part.add_argument('--sourceparams')
        part.add_argument('--system-id', type=systemidtype)
        part.add_argument('--use-uuid', action='store_true')
        part.add_argument('--uuid')

        bootloader = subparsers.add_parser('bootloader')
        bootloader.add_argument('--append')
        bootloader.add_argument('--configfile')
        bootloader.add_argument('--ptable',
                                choices=('msdos', 'gpt'),
                                default='msdos')
        bootloader.add_argument('--timeout', type=int)
        bootloader.add_argument('--source')

        include = subparsers.add_parser('include')
        include.add_argument('path', type=cannedpathtype)

        self._parse(parser, confpath)
        if not self.bootloader:
            msger.warning('bootloader config not specified, using defaults')
            self.bootloader = bootloader.parse_args([])
示例#6
0
    def __init__(self, *args, **kwargs):
        self._subcmds = {}

        # get cmds from pluginmgr
        # mix-in do_subcmd interface
        for subcmd, klass in pluginmgr.get_plugins('imager').iteritems():
            if not hasattr(klass, 'do_create'):
                msger.warning("Unsupported subcmd: %s" % subcmd)
                continue

            func = getattr(klass, 'do_create')
            self._subcmds[subcmd] = func
示例#7
0
    def __init__(self, *args, **kwargs):
        self._subcmds = {}

        # get cmds from pluginmgr
        # mix-in do_subcmd interface
        for subcmd, klass in pluginmgr.get_plugins('imager').items():
            if not hasattr(klass, 'do_create'):
                msger.warning("Unsupported subcmd: %s" % subcmd)
                continue

            func = getattr(klass, 'do_create')
            self._subcmds[subcmd] = func
    def __init__(self, *args, **kwargs):
        cmdln.Cmdln.__init__(self, *args, **kwargs)
        self._subcmds = []

        # get cmds from pluginmgr
        # mix-in do_subcmd interface
        for subcmd, klass in pluginmgr.get_plugins('imager').iteritems():
            if not hasattr(klass, 'do_create'):
                msger.warning("Unsupported subcmd: %s" % subcmd)
                continue

            func = getattr(klass, 'do_create')
            setattr(self.__class__, "do_"+subcmd, func)
            self._subcmds.append(subcmd)
示例#9
0
    def __init__(self, *args, **kwargs):
        cmdln.Cmdln.__init__(self, *args, **kwargs)
        self._subcmds = []

        # get cmds from pluginmgr
        # mix-in do_subcmd interface
        for subcmd, klass in pluginmgr.get_plugins('imager').iteritems():
            if not hasattr(klass, 'do_create'):
                msger.warning("Unsupported subcmd: %s" % subcmd)
                continue

            func = getattr(klass, 'do_create')
            setattr(self.__class__, "do_" + subcmd, func)
            self._subcmds.append(subcmd)
示例#10
0
    def __init__(self, confpath):

        self.partitions = []
        self.bootloader = None
        self.lineno = 0
        self.partnum = 0

        parser = KickStartParser()
        subparsers = parser.add_subparsers()

        part = subparsers.add_parser('part')
        part.add_argument('mountpoint', nargs='?')
        part.add_argument('--active', action='store_true')
        part.add_argument('--align', type=int)
        part.add_argument("--extra-space", type=sizetype, default=10 * 1024)
        part.add_argument('--fsoptions', dest='fsopts')
        part.add_argument('--fstype')
        part.add_argument('--label')
        part.add_argument('--no-table', action='store_true')
        part.add_argument('--ondisk', '--ondrive', dest='disk')
        part.add_argument("--overhead-factor", type=overheadtype, default=1.3)
        part.add_argument('--part-type')
        part.add_argument('--rootfs-dir')
        part.add_argument('--size', type=sizetype, default=0)
        part.add_argument('--source')
        part.add_argument('--sourceparams')
        part.add_argument('--system-id', type=systemidtype)
        part.add_argument('--use-uuid', action='store_true')
        part.add_argument('--uuid')

        bootloader = subparsers.add_parser('bootloader')
        bootloader.add_argument('--append')
        bootloader.add_argument('--configfile')
        bootloader.add_argument('--ptable',
                                choices=('msdos', 'gpt'),
                                default='msdos')
        bootloader.add_argument('--timeout', type=int)
        bootloader.add_argument('--source')

        include = subparsers.add_parser('include')
        include.add_argument('path', type=cannedpathtype)

        self._parse(parser, confpath)
        if not self.bootloader:
            msger.warning('bootloader config not specified, using defaults')
            self.bootloader = bootloader.parse_args([])
示例#11
0
文件: ksparser.py 项目: biannm/Poky
    def __init__(self, confpath):

        self.partitions = []
        self.bootloader = None
        self.lineno = 0
        self.partnum = 0

        parser = KickStartParser()
        subparsers = parser.add_subparsers()

        part = subparsers.add_parser('part')
        part.add_argument('mountpoint')
        part.add_argument('--active', action='store_true')
        part.add_argument('--align', type=int)
        part.add_argument("--extra-space", type=sizetype, default=10*1024L)
        part.add_argument('--fsoptions', dest='fsopts')
        part.add_argument('--fstype')
        part.add_argument('--label')
        part.add_argument('--no-table', action='store_true')
        part.add_argument('--ondisk', '--ondrive', dest='disk')
        part.add_argument("--overhead-factor", type=overheadtype, default=1.3)
        part.add_argument('--part-type')
        part.add_argument('--rootfs-dir')
        part.add_argument('--size', type=sizetype, default=0)
        part.add_argument('--source')
        part.add_argument('--sourceparams')
        part.add_argument('--system-id', type=systemidtype)
        part.add_argument('--use-uuid', action='store_true')
        part.add_argument('--uuid')

        bootloader = subparsers.add_parser('bootloader')
        bootloader.add_argument('--append')
        bootloader.add_argument('--configfile')
        bootloader.add_argument('--ptable', choices=('msdos', 'gpt'),
                                default='msdos')
        bootloader.add_argument('--timeout', type=int)
        bootloader.add_argument('--source')

        include = subparsers.add_parser('include')
        include.add_argument('path', type=cannedpathtype)

        self._parse(parser, confpath)
        if not self.bootloader:
            msger.warning('bootloader config not specified, using defaults')
            self.bootloader = bootloader.parse_args([])
示例#12
0
    def cleanup(self):
        if self._image:
            try:
                self._image.cleanup()
            except ImageError as err:
                msger.warning("%s" % err)

        # Move results to the output dir
        if not os.path.exists(self.outdir):
            os.makedirs(self.outdir)

        for fname in os.listdir(self.workdir):
            path = os.path.join(self.workdir, fname)
            if os.path.isfile(path):
                shutil.move(path, os.path.join(self.outdir, fname))

        # remove work directory
        shutil.rmtree(self.workdir, ignore_errors=True)
示例#13
0
 def get_source_plugin_methods(self, source_name, methods):
     """
     The methods param is a dict with the method names to find.  On
     return, the dict values will be filled in with pointers to the
     corresponding methods.  If one or more methods are not found,
     None is returned.
     """
     return_methods = None
     for _source_name, klass in self.get_plugins("source").iteritems():
         if _source_name == source_name:
             for _method_name in methods.keys():
                 if not hasattr(klass, _method_name):
                     msger.warning("Unimplemented %s source interface for: %s" % (_method_name, _source_name))
                     return None
                 func = getattr(klass, _method_name)
                 methods[_method_name] = func
                 return_methods = methods
     return return_methods
示例#14
0
 def get_source_plugin_methods(self, source_name, methods):
     """
     The methods param is a dict with the method names to find.  On
     return, the dict values will be filled in with pointers to the
     corresponding methods.  If one or more methods are not found,
     None is returned.
     """
     return_methods = None
     for _source_name, klass in self.get_plugins('source').iteritems():
         if _source_name == source_name:
             for _method_name in methods.keys():
                 if not hasattr(klass, _method_name):
                     msger.warning("Unimplemented %s source interface for: %s"\
                                   % (_method_name, _source_name))
                     return None
                 func = getattr(klass, _method_name)
                 methods[_method_name] = func
                 return_methods = methods
     return return_methods
示例#15
0
    def _load_all(self):
        for (pdir, loaded) in self.plugin_dirs.iteritems():
            if loaded:
                continue

            sys.path.insert(0, pdir)
            for mod in [x[:-3] for x in os.listdir(pdir) if x.endswith(".py")]:
                if mod and mod != "__init__":
                    if mod in sys.modules:
                        # self.plugin_dirs[pdir] = True
                        msger.warning("Module %s already exists, skip" % mod)
                    else:
                        try:
                            pymod = __import__(mod)
                            self.plugin_dirs[pdir] = True
                            msger.debug("Plugin module %s:%s imported" % (mod, pymod.__file__))
                        except ImportError, err:
                            msg = "Failed to load plugin %s/%s: %s" % (os.path.basename(pdir), mod, err)
                            msger.warning(msg)

            del (sys.path[0])
示例#16
0
def serial_console_form_kargs(kernel_args):
    """
    Create SERIAL... line from kernel parameters

    syslinux needs a line SERIAL port [baudrate [flowcontrol]]
    in the syslinux.cfg file. The config line is generated based
    on kernel boot parameters. The the parameters of the first
    ttyS console are considered for syslinux config.
    @param kernel_args kernel command line
    @return line for syslinux config file e.g. "SERIAL 0 115200"
    """
    syslinux_conf = ""
    for param in kernel_args.split():
        param_match = re.match("console=ttyS([0-9]+),?([0-9]*)([noe]?)([0-9]?)(r?)", param)
        if param_match:
            syslinux_conf += "SERIAL " + param_match.group(1)
            # baudrate
            if param_match.group(2):
                syslinux_conf += " " + param_match.group(2)
            # parity
            if param_match.group(3) and param_match.group(3) != 'n':
                msger.warning("syslinux does not support parity for console. {} is ignored."
                              .format(param_match.group(3)))
            # number of bits
            if param_match.group(4) and param_match.group(4) != '8':
                msger.warning("syslinux supports 8 bit console configuration only. {} is ignored."
                              .format(param_match.group(4)))
            # flow control
            if param_match.group(5) and param_match.group(5) != '':
                msger.warning("syslinux console flowcontrol configuration. {} is ignored."
                              .format(param_match.group(5)))
            break

    return syslinux_conf
示例#17
0
    def _load_all(self):
        for (pdir, loaded) in self.plugin_dirs.iteritems():
            if loaded: continue

            sys.path.insert(0, pdir)
            for mod in [x[:-3] for x in os.listdir(pdir) if x.endswith(".py")]:
                if mod and mod != '__init__':
                    if mod in sys.modules:
                        #self.plugin_dirs[pdir] = True
                        msger.warning("Module %s already exists, skip" % mod)
                    else:
                        try:
                            pymod = __import__(mod)
                            self.plugin_dirs[pdir] = True
                            msger.debug("Plugin module %s:%s imported"\
                                        % (mod, pymod.__file__))
                        except ImportError, err:
                            msg = 'Failed to load plugin %s/%s: %s' \
                                % (os.path.basename(pdir), mod, err)
                            msger.warning(msg)

            del (sys.path[0])
示例#18
0
def serial_console_form_kargs(kernel_args):
    """
    Create SERIAL... line from kernel parameters

    syslinux needs a line SERIAL port [baudrate [flowcontrol]]
    in the syslinux.cfg file. The config line is generated based
    on kernel boot parameters. The the parameters of the first
    ttyS console are considered for syslinux config.
    @param kernel_args kernel command line
    @return line for syslinux config file e.g. "SERIAL 0 115200"
    """
    syslinux_conf = ""
    for param in kernel_args.split():
        param_match = re.match(
            "console=ttyS([0-9]+),?([0-9]*)([noe]?)([0-9]?)(r?)", param)
        if param_match:
            syslinux_conf += "SERIAL " + param_match.group(1)
            # baudrate
            if param_match.group(2):
                syslinux_conf += " " + param_match.group(2)
            # parity
            if param_match.group(3) and param_match.group(3) != 'n':
                msger.warning(
                    "syslinux does not support parity for console. {} is ignored."
                    .format(param_match.group(3)))
            # number of bits
            if param_match.group(4) and param_match.group(4) != '8':
                msger.warning(
                    "syslinux supports 8 bit console configuration only. {} is ignored."
                    .format(param_match.group(4)))
            # flow control
            if param_match.group(5) and param_match.group(5) != '':
                msger.warning(
                    "syslinux console flowcontrol configuration. {} is ignored."
                    .format(param_match.group(5)))
            break

    return syslinux_conf
示例#19
0
文件: direct.py 项目: aishee/ostro-os
 def _cleanup(self):
     if not self.__image is None:
         try:
             self.__image.cleanup()
         except ImageError as err:
             msger.warning("%s" % err)
示例#20
0
文件: direct.py 项目: Technux/poky
 def _cleanup(self):
     if not self.__image is None:
         try:
             self.__image.cleanup()
         except ImageError, err:
             msger.warning("%s" % err)