本文整理汇总了Python中mic.utils.runner.runtool函数的典型用法代码示例。如果您正苦于以下问题:Python runtool函数的具体用法?Python runtool怎么用?Python runtool使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了runtool函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testRuntoolCatch3
def testRuntoolCatch3(self):
(rc, out) = runner.runtool("echo hello", catch=3)
self.assertEqual(0, rc)
self.assertEqual("hello\n", out)
(rc, out) = runner.runtool("echo hello >&2", catch=2)
self.assertEqual(0, rc)
self.assertEqual("hello\n", out)
示例2: exec_cmd
def exec_cmd(cmd_and_args, as_shell = False, catch = 3):
"""
Execute command, catching stderr, stdout
Need to execute as_shell if the command uses wildcards
"""
msger.debug("exec_cmd: %s" % cmd_and_args)
args = cmd_and_args.split()
msger.debug(args)
if (as_shell):
rc, out = runner.runtool(cmd_and_args, catch)
else:
rc, out = runner.runtool(args, catch)
out = out.strip()
msger.debug("exec_cmd: output for %s (rc = %d): %s" % \
(cmd_and_args, rc, out))
if rc != 0:
# We don't throw exception when return code is not 0, because
# parted always fails to reload part table with loop devices. This
# prevents us from distinguishing real errors based on return
# code.
msger.debug("WARNING: %s returned '%s' instead of 0" % (args[0], rc))
return (rc, out)
示例3: testRuntoolCatch0
def testRuntoolCatch0(self):
(rc, out) = runner.runtool("echo hello", catch=0)
self.assertEqual(0, rc)
self.assertEqual('', out)
(rc, out) = runner.runtool("echo hello >&2", catch=0)
self.assertEqual(0, rc)
self.assertEqual('', out)
示例4: get_file_size
def get_file_size(filename):
""" Return size in MB unit """
cmd = ['du', "-s", "-b", "-B", "1M", filename]
rc, duOutput = runner.runtool(cmd)
if rc != 0:
raise CreatorError("Failed to run: %s" % ' '.join(cmd))
size1 = int(duOutput.split()[0])
cmd = ['du', "-s", "-B", "1M", filename]
rc, duOutput = runner.runtool(cmd)
if rc != 0:
raise CreatorError("Failed to run: %s" % ' '.join(cmd))
size2 = int(duOutput.split()[0])
return max(size1, size2)
示例5: 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']))
示例6: __create_subvolume_metadata
def __create_subvolume_metadata(self, p, pdisk):
if len(self.subvolumes) == 0:
return
argv = [ self.btrfscmd, "subvolume", "list", pdisk.mountdir ]
rc, out = runner.runtool(argv)
msger.debug(out)
if rc != 0:
raise MountError("Failed to get subvolume id from %s', return code: %d." % (pdisk.mountdir, rc))
subvolid_items = out.splitlines()
subvolume_metadata = ""
for subvol in self.subvolumes:
for line in subvolid_items:
if line.endswith(" path %s" % subvol["subvol"]):
subvolid = line.split()[1]
if not subvolid.isdigit():
raise MountError("Invalid subvolume id: %s" % subvolid)
subvolid = int(subvolid)
opts = subvol["fsopts"].split(",")
for opt in opts:
if opt.strip().startswith("subvol="):
opts.remove(opt)
break
fsopts = ",".join(opts)
subvolume_metadata += "%d\t%s\t%s\t%s\n" % (subvolid, subvol["subvol"], subvol['mountpoint'], fsopts)
if subvolume_metadata:
fd = open("%s/.subvolume_metadata" % pdisk.mountdir, "w")
fd.write(subvolume_metadata)
fd.close()
示例7: __map_partitions
def __map_partitions(self):
"""Load it if dm_snapshot isn't loaded"""
load_module("dm_snapshot")
for dev in self.disks.keys():
d = self.disks[dev]
if d['mapped']:
continue
msger.debug("Running kpartx on %s" % d['disk'].device )
rc, kpartxOutput = runner.runtool([self.kpartx, "-l", "-v", d['disk'].device])
kpartxOutput = kpartxOutput.splitlines()
if rc != 0:
raise MountError("Failed to query partition mapping for '%s'" %
d['disk'].device)
# Strip trailing blank and mask verbose output
i = 0
while i < len(kpartxOutput) and kpartxOutput[i][0:4] != "loop":
i = i + 1
kpartxOutput = kpartxOutput[i:]
# Quick sanity check that the number of partitions matches
# our expectation. If it doesn't, someone broke the code
# further up
if len(kpartxOutput) != d['numpart']:
raise MountError("Unexpected number of partitions from kpartx: %d != %d" %
(len(kpartxOutput), d['numpart']))
for i in range(len(kpartxOutput)):
line = kpartxOutput[i]
newdev = line.split()[0]
mapperdev = "/dev/mapper/" + newdev
loopdev = d['disk'].device + newdev[-1]
msger.debug("Dev %s: %s -> %s" % (newdev, loopdev, mapperdev))
pnum = d['partitions'][i]
self.partitions[pnum]['device'] = loopdev
# grub's install wants partitions to be named
# to match their parent device + partition num
# kpartx doesn't work like this, so we add compat
# symlinks to point to /dev/mapper
if os.path.lexists(loopdev):
os.unlink(loopdev)
os.symlink(mapperdev, loopdev)
msger.debug("Adding partx mapping for %s" % d['disk'].device)
rc = runner.show([self.kpartx, "-v", "-a", d['disk'].device])
if rc != 0:
# Make sure that the device maps are also removed on error case.
# The d['mapped'] isn't set to True if the kpartx fails so
# failed mapping will not be cleaned on cleanup either.
runner.quiet([self.kpartx, "-d", d['disk'].device])
raise MountError("Failed to map partitions for '%s'" %
d['disk'].device)
d['mapped'] = True
示例8: _kpseek
def _kpseek(self, device):
rc, out = runner.runtool([self.kpartxcmd, '-l', '-v', device])
if rc != 0:
raise MountError("Can't query dm snapshot on %s" % device)
for line in out.splitlines():
if line and line.startswith("loop"):
return True
return False
示例9: _loseek
def _loseek(self, device):
import re
rc, out = runner.runtool([self.losetupcmd, '-a'])
if rc != 0:
raise MountError("Failed to run 'losetup -a'")
for line in out.splitlines():
m = re.match("([^:]+): .*", line)
if m and m.group(1) == device:
return True
return False
示例10: release_output
def release_output(self, config, destdir, release):
""" Create release directory and files
"""
def _rpath(fn):
""" release path """
return os.path.join(destdir, fn)
outimages = self.outimage
# new ks
new_kspath = _rpath(self.name + ".ks")
with open(config) as fr:
with open(new_kspath, "w") as wf:
# When building a release we want to make sure the .ks
# file generates the same build even when --release= is not used.
wf.write(fr.read().replace("@[email protected]", release))
outimages.append(new_kspath)
# rename iso and usbimg
for f in os.listdir(destdir):
if f.endswith(".iso"):
newf = f[:-4] + ".img"
elif f.endswith(".usbimg"):
newf = f[:-7] + ".img"
else:
continue
os.rename(_rpath(f), _rpath(newf))
outimages.append(_rpath(newf))
# generate MANIFEST
with open(_rpath("MANIFEST"), "w") as wf:
if os.path.exists("/usr/bin/md5sum"):
for f in os.listdir(destdir):
if f == "MANIFEST":
continue
if os.path.isdir(os.path.join(destdir, f)):
continue
rc, md5sum = runner.runtool(["/usr/bin/md5sum", "-b", _rpath(f)])
if rc != 0:
msger.warning("Failed to generate md5sum for file %s" % _rpath(f))
else:
md5sum = md5sum.lstrip().split()[0]
wf.write(md5sum + " " + f + "\n")
else:
msger.warning("no md5sum tool found, no checksum string in MANIFEST")
wf.writelines(os.listdir(destdir))
outimages.append("%s/MANIFEST" % destdir)
# Filter out the nonexist file
for fp in outimages[:]:
if not os.path.exists("%s" % fp):
outimages.remove(fp)
示例11: __run_parted
def __run_parted(self, args):
""" Run parted with arguments specified in the 'args' list. """
args.insert(0, self.parted)
msger.debug(args)
rc, out = runner.runtool(args, catch = 3)
out = out.strip()
msger.debug("'parted': exitcode: %d, output: %s" % (rc, out))
# We don't throw exception when return code is not 0, because
# parted always fails to reload part table with loop devices. This
# prevents us from distinguishing real errors based on return
# code.
return rc, out
示例12: __create_part_to_image
def __create_part_to_image(self,device, parttype, fstype, start, size):
# Start is included to the size so we need to substract one from the end.
end = start+size-1
msger.debug("Added '%s' part at %d of size %d" % (parttype,start,end))
part_cmd = [self.parted, "-s", device, "unit", "s", "mkpart", parttype]
if fstype:
part_cmd.extend([fstype])
part_cmd.extend(["%d" % start, "%d" % end])
msger.debug(part_cmd)
rc, out = runner.runtool(part_cmd, catch=3)
out = out.strip()
if out:
msger.debug('"parted" output: %s' % out)
return rc
示例13: do_genchecksum
def do_genchecksum(self, image_name):
if not self._genchecksum:
return
""" Generate md5sum if /usr/bin/md5sum is available """
if os.path.exists("/usr/bin/md5sum"):
(rc, md5sum) = runner.runtool(["/usr/bin/md5sum", "-b", image_name])
if rc != 0:
msger.warning("Can't generate md5sum for image %s" % image_name)
else:
pattern = re.compile("\*.*$")
md5sum = pattern.sub("*" + os.path.basename(image_name), md5sum)
fd = open(image_name + ".md5sum", "w")
fd.write(md5sum)
fd.close()
self.outimage.append(image_name + ".md5sum")
示例14: __run_parted
def __run_parted(self, args):
""" Run parted with arguments specified in the 'args' list. """
args.insert(0, self.parted)
msger.debug(args)
rc, out = runner.runtool(args, catch = 3)
out = out.strip()
if out:
msger.debug('"parted" output: %s' % out)
if rc != 0:
# We don't throw exception when return code is not 0, because
# parted always fails to reload part table with loop devices. This
# prevents us from distinguishing real errors based on return
# code.
msger.debug("WARNING: parted returned '%s' instead of 0" % rc)
示例15: __format_filesystem
def __format_filesystem(self):
if self.skipformat:
msger.debug("Skip filesystem format.")
return
msger.verbose("Formating %s filesystem on %s" % (self.fstype, self.disk.device))
cmdlist = [self.mkfscmd, "-F", "-L", self.fslabel, "-m", "1", "-b",
str(self.blocksize), "-U", self.uuid]
if self.extopts:
cmdlist.extend(self.extopts.split())
cmdlist.extend([self.disk.device])
rc, errout = runner.runtool(cmdlist, catch=2)
if rc != 0:
raise MountError("Error creating %s filesystem on disk %s:\n%s" %
(self.fstype, self.disk.device, errout))
if not self.extopts:
msger.debug("Tuning filesystem on %s" % self.disk.device)
runner.show([self.tune2fs, "-c0", "-i0", "-Odir_index", "-ouser_xattr,acl", self.disk.device])