本文整理汇总了Python中mic.utils.partitionedfs.PartitionedMount.cleanup方法的典型用法代码示例。如果您正苦于以下问题:Python PartitionedMount.cleanup方法的具体用法?Python PartitionedMount.cleanup怎么用?Python PartitionedMount.cleanup使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mic.utils.partitionedfs.PartitionedMount
的用法示例。
在下文中一共展示了PartitionedMount.cleanup方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: do_unpack
# 需要导入模块: from mic.utils.partitionedfs import PartitionedMount [as 别名]
# 或者: from mic.utils.partitionedfs.PartitionedMount import cleanup [as 别名]
def do_unpack(cls, srcimg):
srcimgsize = (misc.get_file_size(srcimg)) * 1024L * 1024L
srcmnt = misc.mkdtemp("srcmnt")
disk = fs_related.SparseLoopbackDisk(srcimg, srcimgsize)
srcloop = PartitionedMount(srcmnt, skipformat = True)
srcloop.add_disk('/dev/sdb', disk)
srcloop.add_partition(srcimgsize/1024/1024, "/dev/sdb", "/", "ext3", boot=False)
try:
srcloop.mount()
except errors.MountError:
srcloop.cleanup()
raise
image = os.path.join(tempfile.mkdtemp(dir = "/var/tmp", prefix = "tmp"), "target.img")
args = ['dd', "if=%s" % srcloop.partitions[0]['device'], "of=%s" % image]
msger.info("`dd` image ...")
rc = runner.show(args)
srcloop.cleanup()
shutil.rmtree(os.path.dirname(srcmnt), ignore_errors = True)
if rc != 0:
raise errors.CreatorError("Failed to dd")
else:
return image
示例2: do_unpack
# 需要导入模块: from mic.utils.partitionedfs import PartitionedMount [as 别名]
# 或者: from mic.utils.partitionedfs.PartitionedMount import cleanup [as 别名]
def do_unpack(cls, srcimg):
img = srcimg
imgsize = misc.get_file_size(img) * 1024L * 1024L
imgmnt = misc.mkdtemp()
disk = fs_related.SparseLoopbackDisk(img, imgsize)
imgloop = PartitionedMount(imgmnt, skipformat = True)
imgloop.add_disk('/dev/sdb', disk)
imgloop.add_partition(imgsize/1024/1024, "/dev/sdb", "/", "vfat", boot=False)
try:
imgloop.mount()
except errors.MountError:
imgloop.cleanup()
raise
# legacy LiveOS filesystem layout support, remove for F9 or F10
if os.path.exists(imgmnt + "/squashfs.img"):
squashimg = imgmnt + "/squashfs.img"
else:
squashimg = imgmnt + "/LiveOS/squashfs.img"
tmpoutdir = misc.mkdtemp()
# unsquashfs requires outdir mustn't exist
shutil.rmtree(tmpoutdir, ignore_errors = True)
misc.uncompress_squashfs(squashimg, tmpoutdir)
try:
# legacy LiveOS filesystem layout support, remove for F9 or F10
if os.path.exists(tmpoutdir + "/os.img"):
os_image = tmpoutdir + "/os.img"
else:
os_image = tmpoutdir + "/LiveOS/ext3fs.img"
if not os.path.exists(os_image):
raise errors.CreatorError("'%s' is not a valid live CD ISO : neither "
"LiveOS/ext3fs.img nor os.img exist" %img)
imgname = os.path.basename(srcimg)
imgname = os.path.splitext(imgname)[0] + ".img"
rtimage = os.path.join(tempfile.mkdtemp(dir = "/var/tmp", prefix = "tmp"), imgname)
shutil.copyfile(os_image, rtimage)
finally:
imgloop.cleanup()
shutil.rmtree(tmpoutdir, ignore_errors = True)
shutil.rmtree(imgmnt, ignore_errors = True)
return rtimage
示例3: _create_usbimg
# 需要导入模块: from mic.utils.partitionedfs import PartitionedMount [as 别名]
# 或者: from mic.utils.partitionedfs.PartitionedMount import cleanup [as 别名]
#.........这里部分代码省略.........
"of=" + swapfile,
"count=%d" % swapsizemb,
"bs=1M"]
rc = runner.show(args)
if rc:
raise CreatorError("Can't create swap file")
args = ["mkswap", "-f", swapfile]
rc = runner.show(args)
if rc:
raise CreatorError("Can't mkswap on swap file")
if homesizemb > 0:
msger.info("Initializing persistent /home")
homefile = usbmnt + "/LiveOS/" + homefile
if fstype == "vfat":
args = ['dd',
"if=/dev/zero",
"of=" + homefile,
"count=%d" % homesizemb,
"bs=1M"]
else:
args = ['dd',
"if=/dev/null",
"of=" + homefile,
"count=1",
"bs=1M",
"seek=%d" % homesizemb]
rc = runner.show(args)
if rc:
raise CreatorError("Can't create home file")
mkfscmd = fs_related.find_binary_path("/sbin/mkfs." + fstype)
if fstype == "ext2" or fstype == "ext3":
args = [mkfscmd, "-F", "-j", homefile]
else:
args = [mkfscmd, homefile]
rc = runner.show(args)
if rc:
raise CreatorError("Can't mke2fs home file")
if fstype == "ext2" or fstype == "ext3":
tune2fs = fs_related.find_binary_path("tune2fs")
args = [tune2fs,
"-c0",
"-i0",
"-ouser_xattr,acl",
homefile]
rc = runner.show(args)
if rc:
raise CreatorError("Can't tune2fs home file")
if fstype == "vfat" or fstype == "msdos":
syslinuxcmd = fs_related.find_binary_path("syslinux")
syslinuxcfg = usbmnt + "/syslinux/syslinux.cfg"
args = [syslinuxcmd,
"-d",
"syslinux",
usbloop.partitions[0]["device"]]
elif fstype == "ext2" or fstype == "ext3":
extlinuxcmd = fs_related.find_binary_path("extlinux")
syslinuxcfg = usbmnt + "/syslinux/extlinux.conf"
args = [extlinuxcmd,
"-i",
usbmnt + "/syslinux"]
else:
raise CreatorError("Invalid file system type: %s" % (fstype))
os.unlink(usbmnt + "/syslinux/isolinux.cfg")
fd = open(syslinuxcfg, "w")
fd.write(text)
fd.close()
rc = runner.show(args)
if rc:
raise CreatorError("Can't install boot loader.")
finally:
usbloop.unmount()
usbloop.cleanup()
# Need to do this after image is unmounted and device mapper is closed
msger.info("set MBR")
mbrfile = "/usr/lib/syslinux/mbr.bin"
if not os.path.exists(mbrfile):
mbrfile = "/usr/share/syslinux/mbr.bin"
if not os.path.exists(mbrfile):
raise CreatorError("mbr.bin file didn't exist.")
mbrsize = os.path.getsize(mbrfile)
outimg = "%s/%s.usbimg" % (self._outdir, self.name)
args = ['dd',
"if=" + mbrfile,
"of=" + outimg,
"seek=0",
"conv=notrunc",
"bs=1",
"count=%d" % (mbrsize)]
rc = runner.show(args)
if rc:
raise CreatorError("Can't set MBR.")
示例4: DirectImageCreator
# 需要导入模块: from mic.utils.partitionedfs import PartitionedMount [as 别名]
# 或者: from mic.utils.partitionedfs.PartitionedMount import cleanup [as 别名]
#.........这里部分代码省略.........
self.__instimage.layout_partitions(self._ptable_format)
self.__imgdir = self.workdir
for disk_name, disk in self.__instimage.disks.items():
full_path = self._full_path(self.__imgdir, disk_name, "direct")
msger.debug("Adding disk %s as %s with size %s bytes" \
% (disk_name, full_path, disk['min_size']))
disk_obj = fs_related.DiskImage(full_path, disk['min_size'])
self.__disks[disk_name] = disk_obj
self.__instimage.add_disk(disk_name, disk_obj)
self.__instimage.mount()
def install(self, repo_urls=None):
"""
Install fs images into partitions
"""
for disk_name, disk in self.__instimage.disks.items():
full_path = self._full_path(self.__imgdir, disk_name, "direct")
msger.debug("Installing disk %s as %s with size %s bytes" \
% (disk_name, full_path, disk['min_size']))
self.__instimage.install(full_path)
def configure(self, repodata = None):
"""
Configure the system image according to kickstart.
For now, it just prepares the image to be bootable by e.g.
creating and installing a bootloader configuration.
"""
source_plugin = self.get_default_source_plugin()
if source_plugin:
self._source_methods = pluginmgr.get_source_plugin_methods(source_plugin, disk_methods)
for disk_name, disk in self.__instimage.disks.items():
self._source_methods["do_install_disk"](disk, disk_name, self,
self.workdir,
self.oe_builddir,
self.bootimg_dir,
self.kernel_dir,
self.native_sysroot)
def print_outimage_info(self):
"""
Print the image(s) and artifacts used, for the user.
"""
msg = "The new image(s) can be found here:\n"
parts = self._get_parts()
for disk_name, disk in self.__instimage.disks.items():
full_path = self._full_path(self.__imgdir, disk_name, "direct")
msg += ' %s\n\n' % full_path
msg += 'The following build artifacts were used to create the image(s):\n'
for p in parts:
if p.get_rootfs() is None:
continue
if p.mountpoint == '/':
str = ':'
else:
str = '["%s"]:' % p.label
msg += ' ROOTFS_DIR%s%s\n' % (str.ljust(20), p.get_rootfs())
msg += ' BOOTIMG_DIR: %s\n' % self.bootimg_dir
msg += ' KERNEL_DIR: %s\n' % self.kernel_dir
msg += ' NATIVE_SYSROOT: %s\n' % self.native_sysroot
msger.info(msg)
def _get_boot_config(self):
"""
Return the rootdev/root_part_uuid (if specified by
--part-type)
Assume partition order same as in wks
"""
rootdev = None
root_part_uuid = None
parts = self._get_parts()
for num, p in enumerate(parts, 1):
if p.mountpoint == "/":
part = ''
if p.disk.startswith('mmcblk'):
part = 'p'
if self._ptable_format == 'msdos' and num > 3:
rootdev = "/dev/%s%s%-d" % (p.disk, part, num + 1)
else:
rootdev = "/dev/%s%s%-d" % (p.disk, part, num)
root_part_uuid = p.part_type
return (rootdev, root_part_uuid)
def _unmount_instroot(self):
if not self.__instimage is None:
try:
self.__instimage.cleanup()
except MountError, err:
msger.warning("%s" % err)
示例5: do_chroot
# 需要导入模块: from mic.utils.partitionedfs import PartitionedMount [as 别名]
# 或者: from mic.utils.partitionedfs.PartitionedMount import cleanup [as 别名]
def do_chroot(cls, target, cmd=[]):
img = target
imgsize = misc.get_file_size(img) * 1024L * 1024L
partedcmd = fs_related.find_binary_path("parted")
disk = fs_related.SparseLoopbackDisk(img, imgsize)
imgmnt = misc.mkdtemp()
imgloop = PartitionedMount(imgmnt, skipformat = True)
imgloop.add_disk('/dev/sdb', disk)
img_fstype = "ext3"
msger.info("Partition Table:")
partnum = []
for line in runner.outs([partedcmd, "-s", img, "print"]).splitlines():
# no use strip to keep line output here
if "Number" in line:
msger.raw(line)
if line.strip() and line.strip()[0].isdigit():
partnum.append(line.strip()[0])
msger.raw(line)
rootpart = None
if len(partnum) > 1:
rootpart = msger.choice("please choose root partition", partnum)
# Check the partitions from raw disk.
# if choose root part, the mark it as mounted
if rootpart:
root_mounted = True
else:
root_mounted = False
partition_mounts = 0
for line in runner.outs([partedcmd,"-s",img,"unit","B","print"]).splitlines():
line = line.strip()
# Lines that start with number are the partitions,
# because parted can be translated we can't refer to any text lines.
if not line or not line[0].isdigit():
continue
# Some vars have extra , as list seperator.
line = line.replace(",","")
# Example of parted output lines that are handled:
# Number Start End Size Type File system Flags
# 1 512B 3400000511B 3400000000B primary
# 2 3400531968B 3656384511B 255852544B primary linux-swap(v1)
# 3 3656384512B 3720347647B 63963136B primary fat16 boot, lba
partition_info = re.split("\s+",line)
size = partition_info[3].split("B")[0]
if len(partition_info) < 6 or partition_info[5] in ["boot"]:
# No filesystem can be found from partition line. Assuming
# btrfs, because that is the only MeeGo fs that parted does
# not recognize properly.
# TODO: Can we make better assumption?
fstype = "btrfs"
elif partition_info[5] in ["ext2","ext3","ext4","btrfs"]:
fstype = partition_info[5]
elif partition_info[5] in ["fat16","fat32"]:
fstype = "vfat"
elif "swap" in partition_info[5]:
fstype = "swap"
else:
raise errors.CreatorError("Could not recognize partition fs type '%s'." % partition_info[5])
if rootpart and rootpart == line[0]:
mountpoint = '/'
elif not root_mounted and fstype in ["ext2","ext3","ext4","btrfs"]:
# TODO: Check that this is actually the valid root partition from /etc/fstab
mountpoint = "/"
root_mounted = True
elif fstype == "swap":
mountpoint = "swap"
else:
# TODO: Assing better mount points for the rest of the partitions.
partition_mounts += 1
mountpoint = "/media/partition_%d" % partition_mounts
if "boot" in partition_info:
boot = True
else:
boot = False
msger.verbose("Size: %s Bytes, fstype: %s, mountpoint: %s, boot: %s" % (size, fstype, mountpoint, boot))
# TODO: add_partition should take bytes as size parameter.
imgloop.add_partition((int)(size)/1024/1024, "/dev/sdb", mountpoint, fstype = fstype, boot = boot)
try:
imgloop.mount()
except errors.MountError:
imgloop.cleanup()
raise
try:
if len(cmd) != 0:
cmdline = ' '.join(cmd)
else:
#.........这里部分代码省略.........
示例6: RawImageCreator
# 需要导入模块: from mic.utils.partitionedfs import PartitionedMount [as 别名]
# 或者: from mic.utils.partitionedfs.PartitionedMount import cleanup [as 别名]
#.........这里部分代码省略.........
"-s",
loopdev,
"set",
"%d" % (bootdevnum + 1),
"boot",
"on"])
#XXX disabled return code check because parted always fails to
#reload part table with loop devices. Annoying because we can't
#distinguish this failure from real partition failures :-(
if rc != 0 and 1 == 0:
raise MountError("Unable to set bootable flag to %sp%d" \
% (loopdev, (bootdevnum + 1)))
#Ensure all data is flushed to disk before doing syslinux install
runner.quiet('sync')
fullpathsyslinux = fs_related.find_binary_path("extlinux")
rc = runner.show([fullpathsyslinux,
"-i",
"%s/boot/extlinux" % self._instroot])
if rc != 0:
raise MountError("Unable to install syslinux bootloader to %sp%d" \
% (loopdev, (bootdevnum + 1)))
def _create_bootconfig(self):
#If syslinux is available do the required configurations.
if os.path.exists("%s/usr/share/syslinux/" % (self._instroot)) \
and os.path.exists("%s/boot/extlinux/" % (self._instroot)):
self._create_syslinux_config()
self._install_syslinux()
def _unmount_instroot(self):
if not self.__instloop is None:
self.__instloop.cleanup()
def _resparse(self, size = None):
return self.__instloop.resparse(size)
def _stage_final_image(self):
"""Stage the final system image in _outdir.
write meta data
"""
self._resparse()
if self.compress_image:
for imgfile in os.listdir(self.__imgdir):
if imgfile.endswith('.raw') or imgfile.endswith('bin'):
imgpath = os.path.join(self.__imgdir, imgfile)
misc.compressing(imgpath, self.compress_image)
if self.pack_to:
dst = os.path.join(self._outdir, self.pack_to)
msger.info("Pack all raw images to %s" % dst)
misc.packing(dst, self.__imgdir)
else:
msger.debug("moving disks to stage location")
for imgfile in os.listdir(self.__imgdir):
src = os.path.join(self.__imgdir, imgfile)
dst = os.path.join(self._outdir, imgfile)
msger.debug("moving %s to %s" % (src,dst))
shutil.move(src,dst)
self._write_image_xml()
def _write_image_xml(self):
imgarch = "i686"
if self.target_arch and self.target_arch.startswith("arm"):
示例7: RawImageCreator
# 需要导入模块: from mic.utils.partitionedfs import PartitionedMount [as 别名]
# 或者: from mic.utils.partitionedfs.PartitionedMount import cleanup [as 别名]
#.........这里部分代码省略.........
syslinux_conf += "menu autoboot Starting %s...\n" % self.distro_name
syslinux_conf += "menu hidden\n"
syslinux_conf += "\n"
syslinux_conf += "%s\n" % splashline
syslinux_conf += "menu title Welcome to %s!\n" % self.distro_name
syslinux_conf += "menu color border 0 #ffffffff #00000000\n"
syslinux_conf += "menu color sel 7 #ffffffff #ff000000\n"
syslinux_conf += "menu color title 0 #ffffffff #00000000\n"
syslinux_conf += "menu color tabmsg 0 #ffffffff #00000000\n"
syslinux_conf += "menu color unsel 0 #ffffffff #00000000\n"
syslinux_conf += "menu color hotsel 0 #ff000000 #ffffffff\n"
syslinux_conf += "menu color hotkey 7 #ffffffff #ff000000\n"
syslinux_conf += "menu color timeout_msg 0 #ffffffff #00000000\n"
syslinux_conf += "menu color timeout 0 #ffffffff #00000000\n"
syslinux_conf += "menu color cmdline 0 #ffffffff #00000000\n"
versions = []
kernels = self._get_kernel_versions()
symkern = "%s/boot/vmlinuz" % self._instroot
if os.path.lexists(symkern):
v = os.path.realpath(symkern).replace('%s-' % symkern, "")
syslinux_conf += "label %s\n" % self.distro_name.lower()
syslinux_conf += "\tmenu label %s (%s)\n" % (self.distro_name, v)
syslinux_conf += "\tlinux ../vmlinuz\n"
if self._ptable_format == 'msdos':
rootstr = rootdev
else:
if not root_part_uuid:
raise MountError("Cannot find the root GPT partition UUID")
rootstr = "PARTUUID=%s" % root_part_uuid
syslinux_conf += "\tappend ro root=%s %s\n" % (rootstr, options)
syslinux_conf += "\tmenu default\n"
else:
for kernel in kernels:
for version in kernels[kernel]:
versions.append(version)
footlabel = 0
for v in versions:
syslinux_conf += "label %s%d\n" \
% (self.distro_name.lower(), footlabel)
syslinux_conf += "\tmenu label %s (%s)\n" % (self.distro_name, v)
syslinux_conf += "\tlinux ../vmlinuz-%s\n" % v
syslinux_conf += "\tappend ro root=%s %s\n" \
% (rootdev, options)
if footlabel == 0:
syslinux_conf += "\tmenu default\n"
footlabel += 1;
msger.debug("Writing syslinux config %s/boot/extlinux/extlinux.conf" \
% self._instroot)
cfg = open(self._instroot + "/boot/extlinux/extlinux.conf", "w")
cfg.write(syslinux_conf)
cfg.close()
def _install_syslinux(self):
for name in self.__disks.keys():
loopdev = self.__disks[name].device
# Set MBR
mbrfile = "%s/usr/share/syslinux/" % self._instroot
if self._ptable_format == 'gpt':
mbrfile += "gptmbr.bin"
else:
mbrfile += "mbr.bin"
msger.debug("Installing syslinux bootloader '%s' to %s" % \
(mbrfile, loopdev))
rc = runner.show(['dd', 'if=%s' % mbrfile, 'of=' + loopdev])
if rc != 0:
raise MountError("Unable to set MBR to %s" % loopdev)
# Ensure all data is flushed to disk before doing syslinux install
runner.quiet('sync')
fullpathsyslinux = fs_related.find_binary_path("extlinux")
rc = runner.show([fullpathsyslinux,
"-i",
"%s/boot/extlinux" % self._instroot])
if rc != 0:
raise MountError("Unable to install syslinux bootloader to %s" \
% loopdev)
def _create_bootconfig(self):
#If syslinux is available do the required configurations.
if self._need_extlinux \
and os.path.exists("%s/usr/share/syslinux/" % (self._instroot)) \
and os.path.exists("%s/boot/extlinux/" % (self._instroot)):
self._create_syslinux_config()
self._install_syslinux()
def _unmount_instroot(self):
if not self.__instloop is None:
try:
self.__instloop.cleanup()
except MountError, err:
msger.warning("%s" % err)
示例8: DirectImageCreator
# 需要导入模块: from mic.utils.partitionedfs import PartitionedMount [as 别名]
# 或者: from mic.utils.partitionedfs.PartitionedMount import cleanup [as 别名]
#.........这里部分代码省略.........
syslinux_conf += "\n"
syslinux_conf += "ALLOWOPTIONS 1\n"
syslinux_conf += "SERIAL 0 115200\n"
syslinux_conf += "\n"
if splashline:
syslinux_conf += "%s\n" % splashline
syslinux_conf += "DEFAULT boot\n"
syslinux_conf += "LABEL boot\n"
kernel = "/vmlinuz"
syslinux_conf += "KERNEL " + kernel + "\n"
if self._ptable_format == 'msdos':
rootstr = rootdev
else:
if not root_part_uuid:
raise MountError("Cannot find the root GPT partition UUID")
rootstr = "PARTUUID=%s" % root_part_uuid
syslinux_conf += "APPEND label=boot root=%s %s\n" % (rootstr, options)
msger.debug("Writing syslinux config %s/hdd/boot/syslinux.cfg" \
% self.workdir)
cfg = open("%s/hdd/boot/syslinux.cfg" % self.workdir, "w")
cfg.write(syslinux_conf)
cfg.close()
def _create_grubefi_config(self):
hdddir = "%s/hdd/boot" % self.workdir
rm_cmd = "rm -rf %s" % self.workdir
exec_cmd(rm_cmd)
install_cmd = "install -d %s/EFI/BOOT" % hdddir
tmp = exec_cmd(install_cmd)
splash = os.path.join(self.workdir, "/EFI/boot/splash.jpg")
if os.path.exists(splash):
splashline = "menu background splash.jpg"
else:
splashline = ""
(rootdev, root_part_uuid) = self._get_boot_config()
options = self.ks.handler.bootloader.appendLine
grubefi_conf = ""
grubefi_conf += "serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1\n"
grubefi_conf += "default=boot\n"
timeout = kickstart.get_timeout(self.ks)
if not timeout:
timeout = 0
grubefi_conf += "timeout=%s\n" % timeout
grubefi_conf += "menuentry 'boot'{\n"
kernel = "/vmlinuz"
if self._ptable_format == 'msdos':
rootstr = rootdev
else:
if not root_part_uuid:
raise MountError("Cannot find the root GPT partition UUID")
rootstr = "PARTUUID=%s" % root_part_uuid
grubefi_conf += "linux %s root=%s rootwait %s\n" \
% (kernel, rootstr, options)
grubefi_conf += "}\n"
if splashline:
syslinux_conf += "%s\n" % splashline
msger.debug("Writing grubefi config %s/hdd/boot/EFI/BOOT/grub.cfg" \
% self.workdir)
cfg = open("%s/hdd/boot/EFI/BOOT/grub.cfg" % self.workdir, "w")
cfg.write(grubefi_conf)
cfg.close()
def _install_syslinux(self):
mbrfile = "%s/syslinux/" % self.bootimg_dir
if self._ptable_format == 'gpt':
mbrfile += "gptmbr.bin"
else:
mbrfile += "mbr.bin"
if not os.path.exists(mbrfile):
msger.error("Couldn't find %s. If using the -e option, do you have the right MACHINE set in local.conf? If not, is the bootimg_dir path correct?" % mbrfile)
for disk_name, disk in self.__instimage.disks.items():
full_path = self._full_path(self.__imgdir, disk_name, "direct")
msger.debug("Installing MBR on disk %s as %s with size %s bytes" \
% (disk_name, full_path, disk['min_size']))
rc = runner.show(['dd', 'if=%s' % mbrfile,
'of=%s' % full_path, 'conv=notrunc'])
if rc != 0:
raise MountError("Unable to set MBR to %s" % full_path)
def _unmount_instroot(self):
if not self.__instimage is None:
try:
self.__instimage.cleanup()
except MountError, err:
msger.warning("%s" % err)