本文整理汇总了Python中mic.utils.fs_related.find_binary_path函数的典型用法代码示例。如果您正苦于以下问题:Python find_binary_path函数的具体用法?Python find_binary_path怎么用?Python find_binary_path使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了find_binary_path函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __create_iso
def __create_iso(self, isodir):
iso = self._outdir + "/" + self.name + ".iso"
genisoimage = fs_related.find_binary_path("genisoimage")
args = [genisoimage,
"-J", "-r",
"-hide-rr-moved", "-hide-joliet-trans-tbl",
"-V", self.fslabel,
"-o", iso]
args.extend(self._get_mkisofs_options(isodir))
args.append(isodir)
if runner.show(args) != 0:
raise CreatorError("ISO creation failed!")
""" It should be ok still even if you haven't isohybrid """
isohybrid = None
try:
isohybrid = fs_related.find_binary_path("isohybrid")
except:
pass
if isohybrid:
args = [isohybrid, "-partok", iso ]
if runner.show(args) != 0:
raise CreatorError("Hybrid ISO creation failed!")
self.__implant_md5sum(iso)
示例2: _install_syslinux
def _install_syslinux(self):
i = 0
for name in self.__disks.keys():
loopdev = self.__disks[name].device
i =i+1
msger.debug("Installing syslinux bootloader to %s" % loopdev)
(bootdevnum, rootdevnum, rootdev, prefix) = self._get_syslinux_boot_config()
#Set MBR
mbrsize = os.stat("%s/usr/share/syslinux/mbr.bin" % self._instroot)[stat.ST_SIZE]
rc = runner.show(['dd', "if=%s/usr/share/syslinux/mbr.bin" % self._instroot, "of=" + loopdev])
if rc != 0:
raise MountError("Unable to set MBR to %s" % loopdev)
#Set Bootable flag
parted = fs_related.find_binary_path("parted")
rc = runner.quiet([parted, "-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)))
示例3: setup_qemu_emulator
def setup_qemu_emulator(rootdir, arch):
# mount binfmt_misc if it doesn't exist
if not os.path.exists("/proc/sys/fs/binfmt_misc"):
modprobecmd = find_binary_path("modprobe")
runner.show([modprobecmd, "binfmt_misc"])
if not os.path.exists("/proc/sys/fs/binfmt_misc/register"):
mountcmd = find_binary_path("mount")
runner.show([mountcmd, "-t", "binfmt_misc", "none", "/proc/sys/fs/binfmt_misc"])
# qemu_emulator is a special case, we can't use find_binary_path
# qemu emulator should be a statically-linked executable file
if arch == "aarch64":
node = "/proc/sys/fs/binfmt_misc/aarch64"
if os.path.exists("/usr/bin/qemu-arm64") and is_statically_linked("/usr/bin/qemu-arm64"):
arm_binary = "qemu-arm64"
elif os.path.exists("/usr/bin/qemu-aarch64") and is_statically_linked("/usr/bin/qemu-aarch64"):
arm_binary = "qemu-aarch64"
elif os.path.exists("/usr/bin/qemu-arm64-static"):
arm_binary = "qemu-arm64-static"
elif os.path.exists("/usr/bin/qemu-aarch64-static"):
arm_binary = "qemu-aarch64-static"
else:
raise CreatorError("Please install a statically-linked %s" % arm_binary)
else:
node = "/proc/sys/fs/binfmt_misc/arm"
arm_binary = "qemu-arm"
if not os.path.exists("/usr/bin/qemu-arm") or not is_statically_linked("/usr/bin/qemu-arm"):
arm_binary = "qemu-arm-static"
if not os.path.exists("/usr/bin/%s" % arm_binary):
raise CreatorError("Please install a statically-linked %s" % arm_binary)
qemu_emulator = "/usr/bin/%s" % arm_binary
if not os.path.exists(rootdir + "/usr/bin"):
makedirs(rootdir + "/usr/bin")
shutil.copy(qemu_emulator, rootdir + qemu_emulator)
# disable selinux, selinux will block qemu emulator to run
if os.path.exists("/usr/sbin/setenforce"):
msger.info('Try to disable selinux')
runner.show(["/usr/sbin/setenforce", "0"])
# unregister it if it has been registered and is a dynamically-linked executable
if os.path.exists(node):
qemu_unregister_string = "-1\n"
with open(node, "w") as fd:
fd.write(qemu_unregister_string)
# register qemu emulator for interpreting other arch executable file
if not os.path.exists(node):
if arch == "aarch64":
qemu_arm_string = ":aarch64:M::\\x7fELF\\x02\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x02\\x00\\xb7:\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x00\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xfe\\xff\\xff:%s:\n" % qemu_emulator
else:
qemu_arm_string = ":arm:M::\\x7fELF\\x01\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x02\\x00\\x28\\x00:\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x00\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xfa\\xff\\xff\\xff:%s:\n" % qemu_emulator
with open("/proc/sys/fs/binfmt_misc/register", "w") as fd:
fd.write(qemu_arm_string)
return qemu_emulator
示例4: setup_qemu_emulator
def setup_qemu_emulator(rootdir, arch):
# mount binfmt_misc if it doesn't exist
if not os.path.exists("/proc/sys/fs/binfmt_misc"):
modprobecmd = find_binary_path("modprobe")
runner.show([modprobecmd, "binfmt_misc"])
if not os.path.exists("/proc/sys/fs/binfmt_misc/register"):
mountcmd = find_binary_path("mount")
runner.show([mountcmd, "-t", "binfmt_misc", "none", "/proc/sys/fs/binfmt_misc"])
# qemu_emulator is a special case, we can't use find_binary_path
# qemu emulator should be a statically-linked executable file
qemu_emulator = "/usr/bin/qemu-arm"
if not os.path.exists(qemu_emulator) or not is_statically_linked(qemu_emulator):
qemu_emulator = "/usr/bin/qemu-arm-static"
if not os.path.exists(qemu_emulator):
raise CreatorError("Please install a statically-linked qemu-arm")
# qemu emulator version check
armv7_list = [arch for arch in rpmmisc.archPolicies.keys() if arch.startswith('armv7')]
if arch in armv7_list: # need qemu (>=0.13.0)
qemuout = runner.outs([qemu_emulator, "-h"])
m = re.search("version\s*([.\d]+)", qemuout)
if m:
qemu_version = m.group(1)
if qemu_version < "0.13":
raise CreatorError("Requires %s version >=0.13 for %s" % (qemu_emulator, arch))
else:
msger.warning("Can't get version info of %s, please make sure it's higher than 0.13.0" % qemu_emulator)
if not os.path.exists(rootdir + "/usr/bin"):
makedirs(rootdir + "/usr/bin")
shutil.copy(qemu_emulator, rootdir + "/usr/bin/qemu-arm-static")
qemu_emulator = "/usr/bin/qemu-arm-static"
# disable selinux, selinux will block qemu emulator to run
if os.path.exists("/usr/sbin/setenforce"):
msger.info('Try to disable selinux')
runner.show(["/usr/sbin/setenforce", "0"])
# unregister it if it has been registered and is a dynamically-linked executable
node = "/proc/sys/fs/binfmt_misc/arm"
if os.path.exists(node):
qemu_unregister_string = "-1\n"
fd = open("/proc/sys/fs/binfmt_misc/arm", "w")
fd.write(qemu_unregister_string)
fd.close()
# register qemu emulator for interpreting other arch executable file
if not os.path.exists(node):
qemu_arm_string = ":arm:M::\\x7fELF\\x01\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x02\\x00\\x28\\x00:\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x00\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xfa\\xff\\xff\\xff:%s:\n" % qemu_emulator
fd = open("/proc/sys/fs/binfmt_misc/register", "w")
fd.write(qemu_arm_string)
fd.close()
return qemu_emulator
示例5: extract_rpm
def extract_rpm(rpmfile, targetdir):
rpm2cpio = find_binary_path("rpm2cpio")
cpio = find_binary_path("cpio")
olddir = os.getcwd()
os.chdir(targetdir)
msger.verbose("Extract rpm file with cpio: %s" % rpmfile)
p1 = subprocess.Popen([rpm2cpio, rpmfile], stdout=subprocess.PIPE)
p2 = subprocess.Popen([cpio, "-idv"], stdin=p1.stdout,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(sout, serr) = p2.communicate()
msger.verbose(sout or serr)
os.chdir(olddir)
示例6: _install_syslinux
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)
示例7: _stage_final_image
def _stage_final_image(self):
try:
self.cmd_qemuimg = fs_related.find_binary_path('qemu-img')
except errors.CreatorError:
return LoopImageCreator._stage_final_image(self)
self._resparse()
imgfile = None
for item in self._instloops:
if item['mountpoint'] == '/':
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']})
imgfile = os.path.join(self._imgdir, item['name'])
if imgfile:
qemuimage = imgfile + ".x86"
runner.show("%s convert -O qcow2 %s %s"
% (self.cmd_qemuimg, imgfile, qemuimage))
os.unlink(imgfile)
os.rename(qemuimage, imgfile)
for item in os.listdir(self._imgdir):
shutil.move(os.path.join(self._imgdir, item),
os.path.join(self._outdir, item))
示例8: package
def package(self, destdir = "."):
"""Prepares the created image for final delivery.
In its simplest form, this method merely copies the install root to the
supplied destination directory; other subclasses may choose to package
the image by e.g. creating a bootable ISO containing the image and
bootloader configuration.
destdir -- the directory into which the final image should be moved;
this defaults to the current directory.
"""
self._stage_final_image()
if not os.path.exists(destdir):
fs.makedirs(destdir)
if self._img_compression_method:
if not self._img_name:
raise CreatorError("Image name not set.")
rc = None
img_location = os.path.join(self._outdir,self._img_name)
if self._img_compression_method == "bz2":
bzip2 = fs.find_binary_path('bzip2')
msger.info("Compressing %s with bzip2. Please wait..." \
% img_location)
rc = runner.show([bzip2, "-f", img_location])
if rc:
raise CreatorError("Failed to compress image %s with %s." \
% (img_location, self._img_compression_method))
for bootimg in glob.glob(os.path.dirname(img_location) + \
"/*-boot.bin"):
msger.info("Compressing %s with bzip2. Please wait..." \
% bootimg)
rc = runner.show([bzip2, "-f", bootimg])
if rc:
raise CreatorError("Failed to compress image %s with "
"%s." \
% (bootimg,
self._img_compression_method))
if self._recording_pkgs:
self._save_recording_pkgs(destdir)
# For image formats with two or multiple image files, it will be
# better to put them under a directory
if self.image_format in ("raw", "vmdk", "vdi", "nand", "mrstnand"):
destdir = os.path.join(destdir, "%s-%s" \
% (self.name, self.image_format))
msger.debug("creating destination dir: %s" % destdir)
fs.makedirs(destdir)
# Ensure all data is flushed to _outdir
runner.quiet('sync')
for f in os.listdir(self._outdir):
shutil.move(os.path.join(self._outdir, f),
os.path.join(destdir, f))
self.outimage.append(os.path.join(destdir, f))
self.do_genchecksum(os.path.join(destdir, f))
示例9: uncompress_squashfs
def uncompress_squashfs(squashfsimg, outdir):
"""Uncompress file system from squshfs image"""
unsquashfs = find_binary_path("unsquashfs")
args = [ unsquashfs, "-d", outdir, squashfsimg ]
rc = runner.show(args)
if (rc != 0):
raise SquashfsError("Failed to uncompress %s." % squashfsimg)
示例10: installLocal
def installLocal(self, pkg, po=None, updateonly=False):
if not self.ts:
self.__initialize_transaction()
solvfile = "%s/.solv" % (self.creator.cachedir)
rc, out = runner.runtool([fs_related.find_binary_path("rpms2solv"), pkg])
if rc == 0:
f = open(solvfile, "w+")
f.write(out)
f.close()
warnmsg = self.repo_manager.loadSolvFile(solvfile , os.path.basename(pkg))
if warnmsg:
msger.warning(warnmsg)
os.unlink(solvfile)
else:
msger.warning('Can not get %s solv data.' % pkg)
hdr = rpmmisc.readRpmHeader(self.ts, pkg)
arch = zypp.Arch(hdr['arch'])
if self.creator.target_arch == None:
# TODO, get the default_arch from conf or detected from global settings
sysarch = zypp.Arch('i686')
else:
sysarch = zypp.Arch(self.creator.target_arch)
if arch.compatible_with (sysarch):
pkgname = hdr['name']
self.localpkgs[pkgname] = pkg
self.selectPackage(pkgname)
msger.info("Marking %s to be installed" % (pkg))
else:
msger.warning ("Cannot add package %s to transaction. Not a compatible architecture: %s" % (pkg, hdr['arch']))
示例11: convert_image
def convert_image(srcimg, srcfmt, dstimg, dstfmt):
#convert disk format
if dstfmt != "raw":
raise CreatorError("Invalid destination image format: %s" % dstfmt)
msger.debug("converting %s image to %s" % (srcimg, dstimg))
if srcfmt == "vmdk":
path = find_binary_path("qemu-img")
argv = [path, "convert", "-f", "vmdk", srcimg, "-O", dstfmt, dstimg]
elif srcfmt == "vdi":
path = find_binary_path("VBoxManage")
argv = [path, "internalcommands", "converttoraw", srcimg, dstimg]
else:
raise CreatorError("Invalid soure image format: %s" % srcfmt)
rc = runner.show(argv)
if rc == 0:
msger.debug("convert successful")
if rc != 0:
raise CreatorError("Unable to convert disk to %s" % dstfmt)
示例12: compressing
def compressing(fpath, method):
comp_map = {
"gz": "gzip",
"bz2": "bzip2"
}
if method not in comp_map:
raise CreatorError("Unsupport compress format: %s, valid values: %s"
% (method, ','.join(comp_map.keys())))
cmd = find_binary_path(comp_map[method])
rc = runner.show([cmd, "-f", fpath])
if rc:
raise CreatorError("Failed to %s file: %s" % (comp_map[method], fpath))
示例13: selinux_check
def selinux_check(arch, fstypes):
try:
getenforce = find_binary_path('getenforce')
except CreatorError:
return
selinux_status = runner.outs([getenforce])
if arch and arch.startswith("arm") and selinux_status == "Enforcing":
raise CreatorError("Can't create arm image if selinux is enabled, "
"please run 'setenforce 0' to disable selinux")
use_btrfs = filter(lambda typ: typ == 'btrfs', fstypes)
if use_btrfs and selinux_status == "Enforcing":
raise CreatorError("Can't create btrfs image if selinux is enabled,"
" please run 'setenforce 0' to disable selinux")
示例14: get_mic_binpath
def get_mic_binpath():
fp = None
try:
import pkg_resources # depends on 'setuptools'
except ImportError:
pass
else:
dist = pkg_resources.get_distribution('mic')
# the real script is under EGG_INFO/scripts
if dist.has_metadata('scripts/mic'):
fp = os.path.join(dist.egg_info, "scripts/mic")
if fp:
return fp
# not found script if 'flat' egg installed
try:
return find_binary_path('mic')
except errors.CreatorError:
raise errors.BootstrapError("Can't find mic binary in host OS")
示例15: _get_metadata_from_repo
def _get_metadata_from_repo(baseurl, proxies, cachedir, reponame, filename,
sumtype=None, checksum=None):
url = os.path.join(baseurl, filename)
filename_tmp = str("%s/%s/%s" % (cachedir, reponame, os.path.basename(filename)))
if os.path.splitext(filename_tmp)[1] in (".gz", ".bz2"):
filename = os.path.splitext(filename_tmp)[0]
else:
filename = filename_tmp
if sumtype and checksum and os.path.exists(filename):
try:
sumcmd = find_binary_path("%ssum" % sumtype)
except:
file_checksum = None
else:
file_checksum = runner.outs([sumcmd, filename]).split()[0]
if file_checksum and file_checksum == checksum:
return filename
return _get_uncompressed_data_from_url(url,filename_tmp,proxies)