示例#1
0
    def _stage_final_image(self):

        if self.pack_to or self.shrink_image:
            self._resparse(0)
        else:
            self._resparse()

        for item in self._instloops:
            imgfile = os.path.join(self.__imgdir, item['name'])
            if item['fstype'] == "ext4":
                runner.show('/sbin/tune2fs -O ^huge_file,extents,uninit_bg %s '
                            % imgfile)
            if self.compress_image:
                misc.compressing(imgfile, self.compress_image)

        if not self.pack_to:
            for item in os.listdir(self.__imgdir):
                shutil.move(os.path.join(self.__imgdir, item),
                            os.path.join(self._outdir, item))
        else:
            msger.info("Pack all loop images together to %s" % self.pack_to)
            dstfile = os.path.join(self._outdir, self.pack_to)
            misc.packing(dstfile, self.__imgdir)

        if self.pack_to:
            mountfp_xml = os.path.splitext(self.pack_to)[0]
            mountfp_xml = misc.strip_end(mountfp_xml, '.tar') + ".xml"
        else:
            mountfp_xml = self.name + ".xml"
        # save mount points mapping file to xml
        save_mountpoints(os.path.join(self._outdir, mountfp_xml),
                         self._instloops,
                         self.target_arch)
示例#2
0
文件: loop.py 项目: 117111302/poky
    def _stage_final_image(self):

        if self.pack_to or self.shrink_image:
            self._resparse(0)
        else:
            self._resparse()

        for item in self._instloops:
            imgfile = os.path.join(self.__imgdir, item['name'])
            if item['fstype'] == "ext4":
                runner.show('/sbin/tune2fs -O ^huge_file,extents,uninit_bg %s '
                            % imgfile)
            if self.compress_image:
                misc.compressing(imgfile, self.compress_image)

        if not self.pack_to:
            for item in os.listdir(self.__imgdir):
                shutil.move(os.path.join(self.__imgdir, item),
                            os.path.join(self._outdir, item))
        else:
            msger.info("Pack all loop images together to %s" % self.pack_to)
            dstfile = os.path.join(self._outdir, self.pack_to)
            misc.packing(dstfile, self.__imgdir)

        if self.pack_to:
            mountfp_xml = os.path.splitext(self.pack_to)[0]
            mountfp_xml = misc.strip_end(mountfp_xml, '.tar') + ".xml"
        else:
            mountfp_xml = self.name + ".xml"
        # save mount points mapping file to xml
        save_mountpoints(os.path.join(self._outdir, mountfp_xml),
                         self._instloops,
                         self.target_arch)
示例#3
0
文件: loop.py 项目: 01org/mic
    def _stage_final_image(self):

        if self.pack_to or self.shrink_image:
            self._resparse(0)
        else:
            self._resparse()

        for item in self._instloops:
            imgfile = os.path.join(self._imgdir, item['name'])
            if item['fstype'] == "ext4":
                runner.show('/sbin/tune2fs -O ^huge_file,extents,uninit_bg %s '
                            % imgfile)
            self.image_files.setdefault('partitions', {}).update(
                    {item['mountpoint']: item['label']})
            if self.compress_image:
                compressing(imgfile, self.compress_image)
                self.image_files.setdefault('image_files', []).append(
                                '.'.join([item['name'], self.compress_image]))
            else:
                self.image_files.setdefault('image_files', []).append(item['name'])

        if not self.pack_to:
            for item in os.listdir(self._imgdir):
                shutil.move(os.path.join(self._imgdir, item),
                            os.path.join(self._outdir, item))
        else:
            msger.info("Pack all loop images together to %s" % self.pack_to)
            dstfile = os.path.join(self._outdir, self.pack_to)
            packing(dstfile, self._imgdir)
            self.image_files['image_files'] = [self.pack_to]


        if self.pack_to:
            mountfp_xml = os.path.splitext(self.pack_to)[0]
            mountfp_xml = misc.strip_end(mountfp_xml, '.tar') + ".xml"
        else:
            mountfp_xml = self.name + ".xml"
        # save mount points mapping file to xml
        save_mountpoints(os.path.join(self._outdir, mountfp_xml),
                         self._instloops,
                         self.target_arch)
示例#4
0
    def _stage_final_image(self):

        if self.pack_to or self.shrink_image:
            self._resparse(0)
        else:
            self._resparse()

        for item in self._instloops:
            imgfile = os.path.join(self._imgdir, item['name'])
            if item['fstype'] == "ext4":
                runner.show(
                    '/sbin/tune2fs -O ^huge_file,extents,uninit_bg %s ' %
                    imgfile)
            self.image_files.setdefault('partitions', {}).update(
                {item['mountpoint']: item['label']})
            if self.compress_image:
                compressing(imgfile, self.compress_image)
                self.image_files.setdefault('image_files', []).append('.'.join(
                    [item['name'], self.compress_image]))
            else:
                self.image_files.setdefault('image_files',
                                            []).append(item['name'])

        if not self.pack_to:
            for item in os.listdir(self._imgdir):
                shutil.move(os.path.join(self._imgdir, item),
                            os.path.join(self._outdir, item))
        else:
            msger.info("Pack all loop images together to %s" % self.pack_to)
            dstfile = os.path.join(self._outdir, self.pack_to)
            packing(dstfile, self._imgdir)
            self.image_files['image_files'] = [self.pack_to]

        if self.pack_to:
            mountfp_xml = os.path.splitext(self.pack_to)[0]
            mountfp_xml = misc.strip_end(mountfp_xml, '.tar') + ".xml"
        else:
            mountfp_xml = self.name + ".xml"
        # save mount points mapping file to xml
        save_mountpoints(os.path.join(self._outdir, mountfp_xml),
                         self._instloops, self.target_arch)
示例#5
0
文件: loop.py 项目: 117111302/poky
    def __init__(self, creatoropts=None, pkgmgr=None,
                 compress_image=None,
                 shrink_image=False):
        """Initialize a LoopImageCreator instance.

        This method takes the same arguments as ImageCreator.__init__()
        with the addition of:

        fslabel -- A string used as a label for any filesystems created.
        """

        BaseImageCreator.__init__(self, creatoropts, pkgmgr)

        self.compress_image = compress_image
        self.shrink_image = shrink_image

        self.__fslabel = None
        self.fslabel = self.name

        self.__blocksize = 4096
        if self.ks:
            self.__fstype = kickstart.get_image_fstype(self.ks,
                                                       "ext3")
            self.__fsopts = kickstart.get_image_fsopts(self.ks,
                                                       "defaults,noatime")

            allloops = []
            for part in sorted(kickstart.get_partitions(self.ks),
                               key=lambda p: p.mountpoint):
                if part.fstype == "swap":
                    continue

                label = part.label
                mp = part.mountpoint
                if mp == '/':
                    # the base image
                    if not label:
                        label = self.name
                else:
                    mp = mp.rstrip('/')
                    if not label:
                        msger.warning('no "label" specified for loop img at %s'
                                      ', use the mountpoint as the name' % mp)
                        label = mp.split('/')[-1]

                imgname = misc.strip_end(label, '.img') + '.img'
                allloops.append({
                    'mountpoint': mp,
                    'label': label,
                    'name': imgname,
                    'size': part.size or 4096L * 1024 * 1024,
                    'fstype': part.fstype or 'ext3',
                    'extopts': part.extopts or None,
                    'loop': None,  # to be created in _mount_instroot
                    })
            self._instloops = allloops

        else:
            self.__fstype = None
            self.__fsopts = None
            self._instloops = []

        self.__imgdir = None

        if self.ks:
            self.__image_size = kickstart.get_image_size(self.ks,
                                                         4096L * 1024 * 1024)
        else:
            self.__image_size = 0

        self._img_name = self.name + ".img"
示例#6
0
文件: loop.py 项目: tizenpdk/mic
    def _stage_final_image(self):

        if self.pack_to or self.shrink_image:
            self._resparse(0)
        else:
            self._resparse()

        for item in self._instloops:
            imgfile = os.path.join(self._imgdir, item['name'])

            if item['aft_fstype'] in AFTER_MNT_FS.keys():
                mountpoint = misc.mkdtemp()
                ext4img = os.path.join(self._imgdir, item['name'])
                runner.show('mount -t ext4 %s %s' % (ext4img, mountpoint))
                runner.show('ls -al %s' % (mountpoint))
#                item['loop'].mount(None, 'not_create')
#                point_mnt = os.path.join(self._instroot, item['mountpoint'].lstrip('/'))

                fs_suffix = AFTER_MNT_FS[item['aft_fstype']]
                if item['aft_fstype'] == "squashfs":
#                    fs.mksquashfs(mountpoint, self._outdir+"/"+item['label']+fs_suffix)
                    args = "mksquashfs " + mountpoint + " " + self._imgdir+"/"+item['label']+fs_suffix
                    if item['squashfsopts']:
                        squashfsopts=item['squashfsopts'].replace(',', ' ')
                        runner.show("mksquashfs --help")
                        runner.show("%s %s" % (args, squashfsopts))
                    else:
                        runner.show("%s " % args)

                if item['aft_fstype'] == "vdfs":
                    ##FIXME temporary code - replace this with fs.mkvdfs()
                    if item['vdfsopts']:
                        vdfsopts=item['vdfsopts'].replace(',', ' ')
                    else:
                        vdfsopts="-i -z 1024M"

                    fullpathmkvdfs = "mkfs.vdfs" #find_binary_path("mkfs.vdfs")
                    runner.show("%s --help" % fullpathmkvdfs)
#                    fs.mkvdfs(mountpoint, self._outdir+"/"+item['label']+fs_suffix, vdfsopts)
                    runner.show('%s %s -r %s %s' % (fullpathmkvdfs, vdfsopts, mountpoint, self._imgdir+"/"+item['label']+fs_suffix))

                runner.show('umount %s' % mountpoint)
#               os.unlink(mountpoint)
                runner.show('mv %s %s' % (self._imgdir+"/"+item['label']+fs_suffix, self._imgdir+"/"+item['label']+".img") )
                runner.show('ls -al %s' % self._imgdir)

            if item['fstype'] == "ext4":
                if not item['cpioopts']:
                    runner.show('/sbin/tune2fs -O ^huge_file,extents,uninit_bg %s '
                            % imgfile)
                    runner.quiet(["/sbin/e2fsck", "-f", "-y", imgfile])
            self.image_files.setdefault('partitions', {}).update(
                    {item['mountpoint']: item['label']})
            if self.compress_image:
                compressing(imgfile, self.compress_image)
                self.image_files.setdefault('image_files', []).append(
                                '.'.join([item['name'], self.compress_image]))
            else:
                self.image_files.setdefault('image_files', []).append(item['name'])

        for item in os.listdir(self._imgdir):
            imgfile = os.path.join(self._imgdir, item)
            imgsize = os.path.getsize(imgfile)
            msger.info("filesystem size of %s : %s bytes" % (item, imgsize))

        self.run_sign_scripts()
        if not self.pack_to:
            for item in os.listdir(self._imgdir):
                shutil.move(os.path.join(self._imgdir, item),
                            os.path.join(self._outdir, item))
        else:
            msger.info("Pack all loop images together to %s" % self.pack_to)
            dstfile = os.path.join(self._outdir, self.pack_to)
            packing(dstfile, self._imgdir)
            self.image_files['image_files'] = [self.pack_to]


        if self.pack_to:
            mountfp_xml = os.path.splitext(self.pack_to)[0]
            mountfp_xml = misc.strip_end(mountfp_xml, '.tar') + ".xml"
        else:
            mountfp_xml = self.name + ".xml"
        # save mount points mapping file to xml
        save_mountpoints(os.path.join(self._outdir, mountfp_xml),
                         self._instloops,
                         self.target_arch)
示例#7
0
文件: loop.py 项目: tizenpdk/mic
    def __init__(self, creatoropts=None, pkgmgr=None,
                 compress_image=None,
                 shrink_image=False):
        """Initialize a LoopImageCreator instance.

        This method takes the same arguments as ImageCreator.__init__()
        with the addition of:

        fslabel -- A string used as a label for any filesystems created.
        """

        BaseImageCreator.__init__(self, creatoropts, pkgmgr)

        self.compress_image = compress_image
        self.shrink_image = shrink_image

        self.__fslabel = None
        self.fslabel = self.name

        self.__blocksize = 4096
        if self.ks:
            self.__fstype = kickstart.get_image_fstype(self.ks,
                                                       "ext3")
            self.__fsopts = kickstart.get_image_fsopts(self.ks,
                                                       "defaults,noatime")
            if self.__fstype in AFTER_MNT_FS.keys():
                self.__fstype = "ext4"

            allloops = []
            for part in sorted(kickstart.get_partitions(self.ks),
                               key=lambda p: p.mountpoint):
                aft_fstype = None
                if part.fstype == "swap":
                    continue
                elif part.fstype in AFTER_MNT_FS.keys():
                    aft_fstype = part.fstype
                    part.fstype = "ext4"

                label = part.label
                mp = part.mountpoint
                if mp == '/':
                    # the base image
                    if not label:
                        label = self.name
                else:
                    mp = mp.rstrip('/')
                    if not label:
                        msger.warning('no "label" specified for loop img at %s'
                                      ', use the mountpoint as the name' % mp)
                        label = mp.split('/')[-1]

                imgname = misc.strip_end(label, '.img') + '.img'
                allloops.append({
                    'mountpoint': mp,
                    'label': label,
                    'name': imgname,
                    'size': part.size or 4096L * 1024 * 1024,
                    'fstype': part.fstype or 'ext3',
                    'aft_fstype': aft_fstype or None,
                    'extopts': part.extopts or None,
                    'vdfsopts': part.vdfsopts or None,
                    'squashfsopts': part.squashfsopts or None,
                    'cpioopts': part.cpioopts or None,
                    'loop': None,  # to be created in _mount_instroot
                    'uuid': part.uuid or None,
                    'kspart' : part,
                    'exclude_image' : part.exclude_image or None,
                    })
            self._instloops = allloops

        else:
            self.__fstype = None
            self.__fsopts = None
            self._instloops = []

        self._imgdir = None

        if self.ks:
            self.__image_size = kickstart.get_image_size(self.ks,
                                                         4096L * 1024 * 1024)
        else:
            self.__image_size = 0

        self._img_name = self.name + ".img"
示例#8
0
    def __init__(self, creatoropts=None, pkgmgr=None, taring_to=None):
        """Initialize a LoopImageCreator instance.

        This method takes the same arguments as ImageCreator.__init__()
        with the addition of:

        fslabel -- A string used as a label for any filesystems created.
        """

        BaseImageCreator.__init__(self, creatoropts, pkgmgr)
        self.taring_to = taring_to

        self.__fslabel = None
        self.fslabel = self.name

        self.__blocksize = 4096
        if self.ks:
            self.__fstype = kickstart.get_image_fstype(self.ks, "ext3")
            self.__fsopts = kickstart.get_image_fsopts(self.ks,
                                                       "defaults,noatime")

            allloops = []
            for part in sorted(kickstart.get_partitions(self.ks),
                               key=lambda p: p.mountpoint):
                if part.fstype == "swap":
                    continue

                label = part.label
                mp = part.mountpoint
                if mp == '/':
                    # the base image
                    if not label:
                        label = self.name
                else:
                    mp = mp.rstrip('/')
                    if not label:
                        msger.warning('no "label" specified for loop img at %s'
                                      ', use the mountpoint as the name' % mp)
                        label = mp.split('/')[-1]

                imgname = misc.strip_end(label, '.img') + '.img'
                allloops.append({
                    'mountpoint': mp,
                    'label': label,
                    'name': imgname,
                    'size': part.size or 4096L * 1024 * 1024,
                    'fstype': part.fstype or 'ext3',
                    'loop': None,  # to be created in _mount_instroot
                })
            self._instloops = allloops

        else:
            self.__fstype = None
            self.__fsopts = None
            self._instloops = []

        self.__imgdir = None

        if self.ks:
            self.__image_size = kickstart.get_image_size(
                self.ks, 4096L * 1024 * 1024)
        else:
            self.__image_size = 0

        self._img_name = self.name + ".img"
示例#9
0
文件: loop.py 项目: sailfishos/mic
    def __init__(self,
                 creatoropts=None,
                 pkgmgr=None,
                 compress_image=None,
                 shrink_image=False):
        """Initialize a LoopImageCreator instance.

        This method takes the same arguments as ImageCreator.__init__()
        with the addition of:

        fslabel -- A string used as a label for any filesystems created.
        """

        BaseImageCreator.__init__(self, creatoropts, pkgmgr)

        self.compress_image = compress_image
        self.shrink_image = shrink_image

        self.__fslabel = None
        self.fslabel = self.name

        self.__blocksize = 4096
        if self.ks:
            #self.__fstype = kickstart.get_image_fstype(self.ks,
            #                                           "ext3")
            #self.__fsopts = kickstart.get_image_fsopts(self.ks,
            #                                           "defaults,noatime")
            allloops = []
            for part in sorted(kickstart.get_partitions(self.ks),
                               key=lambda p: p.mountpoint):
                if part.fstype == "swap":
                    continue

                label = part.label
                mp = part.mountpoint
                if mp == '/':
                    # the base image
                    if not label:
                        label = self.name
                else:
                    mp = mp.rstrip('/')
                    if not label:
                        msger.warning('no "label" specified for loop img at %s'
                                      ', use the mountpoint as the name' % mp)
                        label = mp.split('/')[-1]

                imgname = misc.strip_end(label, '.img') + '.img'

                loop_data = {
                    'mountpoint': mp,
                    'label': label,
                    'name': imgname,
                    'size': part.size or 4096 * 1024 * 1024,
                    'fstype': part.fstype or 'ext3',
                    'fsopts': part.fsopts,
                    'loop': None,  # to be created in _mount_instroot
                }

                if loop_data['fstype'] == "btrfs":
                    subvols = []
                    snaps = []
                    for item in kickstart.get_btrfs_list(self.ks):
                        if item.parent == label:
                            if item.subvol:
                                subvols.append({
                                    'size':
                                    0,  # In sectors
                                    'mountpoint':
                                    item.
                                    mountpoint,  # Mount relative to chroot
                                    'fstype':
                                    "btrfs",  # Filesystem type
                                    'fsopts':
                                    "defaults,noatime,subvol=%s" %
                                    item.name,  # Filesystem mount options
                                    'device':
                                    None,  # kpartx device node for partition
                                    'mount':
                                    None,  # Mount object
                                    'subvol':
                                    item.name,  # Subvolume name
                                    'label':
                                    item.label,
                                    'boot':
                                    False,  # Bootable flag
                                    'mounted':
                                    False,  # Mount flag
                                    'quota':
                                    item.quota,
                                    'parent':
                                    item.parent,
                                })
                            if item.snapshot:
                                snaps.append({
                                    'name': item.name,
                                    'base': item.base
                                })
                    else:
                        loop_data['subvolumes'] = subvols
                        loop_data['snapshots'] = snaps

                allloops.append(loop_data)

            self._instloops = allloops

        else:
            self.__fstype = None
            self.__fsopts = None
            self._instloops = []

        if self.ks:
            self.__image_size = kickstart.get_image_size(
                self.ks, 4096 * 1024 * 1024)
        else:
            self.__image_size = 0

        self._img_name = self.name + ".img"