本文整理汇总了Python中mic.utils.runner.runtool函数的典型用法代码示例。如果您正苦于以下问题:Python runtool函数的具体用法?Python runtool怎么用?Python runtool使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了runtool函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:01org,项目名称:mic,代码行数:7,代码来源:test_runner.py
示例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)
开发者ID:arris69,项目名称:OESamyGO,代码行数:26,代码来源:misc.py
示例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)
开发者ID:01org,项目名称:mic,代码行数:7,代码来源:test_runner.py
示例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)
开发者ID:Javoe,项目名称:splicer_poky,代码行数:15,代码来源:misc.py
示例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']))
开发者ID:xiaoqiang0,项目名称:mic,代码行数:29,代码来源:zypppkgmgr.py
示例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()
开发者ID:saukko,项目名称:mic,代码行数:33,代码来源:partitionedfs.py
示例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
开发者ID:saukko,项目名称:mic,代码行数:60,代码来源:partitionedfs.py
示例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
开发者ID:tizenorg,项目名称:tools.mic,代码行数:8,代码来源:fs_related.py
示例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
开发者ID:tizenorg,项目名称:tools.mic,代码行数:10,代码来源:fs_related.py
示例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)
开发者ID:xiaoqiang0,项目名称:mic,代码行数:54,代码来源:baseimager.py
示例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
开发者ID:01org,项目名称:mic,代码行数:14,代码来源:partitionedfs.py
示例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
开发者ID:saukko,项目名称:mic,代码行数:15,代码来源:partitionedfs.py
示例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")
开发者ID:xiaoqiang0,项目名称:mic,代码行数:16,代码来源:baseimager.py
示例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)
开发者ID:Javoe,项目名称:splicer_poky,代码行数:17,代码来源:partitionedfs.py
示例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])
开发者ID:tizenorg,项目名称:tools.mic,代码行数:20,代码来源:fs_related.py
示例16: __get_subvolume_id
def __get_subvolume_id(self, rootpath, subvol):
if not self.btrfscmd:
self.btrfscmd=find_binary_path("btrfs")
argv = [ self.btrfscmd, "subvolume", "list", rootpath ]
rc, out = runner.runtool(argv)
msger.debug(out)
if rc != 0:
raise MountError("Failed to get subvolume id from %s', return code: %d." % (rootpath, rc))
subvolid = -1
for line in out.splitlines():
if line.endswith(" path %s" % subvol):
subvolid = line.split()[1]
if not subvolid.isdigit():
raise MountError("Invalid subvolume id: %s" % subvolid)
subvolid = int(subvolid)
break
return subvolid
开发者ID:saukko,项目名称:mic,代码行数:20,代码来源:partitionedfs.py
示例17: get_loop_device
def get_loop_device(losetupcmd, lofile):
global DEVICE_PIDFILE_DIR
global DEVICE_LOCKFILE
import fcntl
makedirs(os.path.dirname(DEVICE_LOCKFILE))
fp = open(DEVICE_LOCKFILE, 'w')
fcntl.flock(fp, fcntl.LOCK_EX)
try:
loopdev = None
devinst = LoopDevice()
# clean up left loop device first
clean_loop_devices()
# provide an avaible loop device
rc, out = runner.runtool([losetupcmd, "--find"])
if rc == 0 and out:
loopdev = out.split()[0]
devinst.register(loopdev)
if not loopdev or not os.path.exists(loopdev):
devinst.create()
loopdev = devinst.device
# setup a loop device for image file
rc = runner.show([losetupcmd, loopdev, lofile])
if rc != 0:
raise MountError("Failed to setup loop device for '%s'" % lofile)
devinst.reg_atexit()
# try to save device and pid
makedirs(DEVICE_PIDFILE_DIR)
pidfile = os.path.join(DEVICE_PIDFILE_DIR, os.path.basename(loopdev))
if os.path.exists(pidfile):
os.unlink(pidfile)
with open(pidfile, 'w') as wf:
wf.write(str(os.getpid()))
except MountError, err:
raise CreatorError("%s" % str(err))
开发者ID:tizenorg,项目名称:tools.mic,代码行数:41,代码来源:fs_related.py
示例18: testRuntoolCatch1
def testRuntoolCatch1(self):
(rc, out) = runner.runtool("echo hello", catch=1)
self.assertEqual(0, rc)
self.assertEqual("hello\n", out)
开发者ID:01org,项目名称:mic,代码行数:4,代码来源:test_runner.py
示例19: __format_disks
def __format_disks(self):
msger.debug("Assigning partitions to disks")
mbr_sector_skipped = False
# Go through partitions in the order they are added in .ks file
for n in range(len(self.partitions)):
p = self.partitions[n]
if not self.disks.has_key(p['disk']):
raise MountError("No disk %s for partition %s" % (p['disk'], p['mountpoint']))
if not mbr_sector_skipped:
# This hack is used to remove one sector from the first partition,
# that is the used to the MBR.
p['size'] -= 1
mbr_sector_skipped = True
# Get the disk where the partition is located
d = self.disks[p['disk']]
d['numpart'] += 1
# alignment in sectors
align_sectors = None
# if first partition then we need to skip the first sector
# where the MBR is located, if the alignment isn't set
# See: https://wiki.linaro.org/WorkingGroups/Kernel/Projects/FlashCardSurvey
if d['numpart'] == 1:
if p['align'] and p['align'] > 0:
align_sectors = p['align'] * 1024 / self.sector_size
else:
align_sectors = MBR_SECTOR_LEN
elif p['align']:
# If not first partition and we do have alignment set we need
# to align the partition.
# FIXME: This leaves a empty spaces to the disk. To fill the
# gaps we could enlargea the previous partition?
# Calc how much the alignment is off.
align_sectors = d['offset'] % (p['align'] * 1024 / self.sector_size)
# We need to move forward to the next alignment point
align_sectors = (p['align'] * 1024 / self.sector_size) - align_sectors
if align_sectors:
if p['align'] and p['align'] > 0:
msger.debug("Realignment for %s%s with %s sectors, original"
" offset %s, target alignment is %sK." %
(p['disk'], d['numpart'], align_sectors,
d['offset'], p['align']))
# p['size'] already converted in secctors
if p['size'] <= align_sectors:
raise MountError("Partition for %s is too small to handle "
"the alignment change." % p['mountpoint'])
# increase the offset so we actually start the partition on right alignment
d['offset'] += align_sectors
if d['numpart'] > 3:
# Increase allocation of extended partition to hold this partition
d['extended'] += p['size']
p['type'] = 'logical'
p['num'] = d['numpart'] + 1
else:
p['type'] = 'primary'
p['num'] = d['numpart']
p['start'] = d['offset']
d['offset'] += p['size']
d['partitions'].append(n)
msger.debug("Assigned %s to %s%d at Sector %d with size %d sectors "
"/ %d bytes." % (p['mountpoint'], p['disk'], p['num'],
p['start'], p['size'],
p['size'] * self.sector_size))
if self.skipformat:
msger.debug("Skipping disk format, because skipformat flag is set.")
return
for dev in self.disks.keys():
d = self.disks[dev]
msger.debug("Initializing partition table for %s" % (d['disk'].device))
rc, out = runner.runtool([self.parted, "-s", d['disk'].device, "mklabel", "msdos"], catch=3)
out = out.strip()
if out:
msger.debug('"parted" output: %s' % out)
if rc != 0:
# NOTE: 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 when creating partition-table for disk '%s'." % (rc, d['disk'].device))
msger.debug("Creating partitions")
for p in self.partitions:
d = self.disks[p['disk']]
if p['num'] == 5:
self.__create_part_to_image(d['disk'].device,"extended",None,p['start'],d['extended'])
if p['fstype'] == "swap":
#.........这里部分代码省略.........
开发者ID:lbt,项目名称:mic,代码行数:101,代码来源:partitionedfs.py
示例20: __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:]
# Make sure kpartx reported the right count of partitions
if len(kpartxOutput) != d['numpart']:
# If this disk has more than 3 partitions, then in case of MBR
# paritions there is an extended parition. Different versions
# of kpartx behave differently WRT the extended partition -
# some map it, some ignore it. This is why we do the below hack
# - if kpartx reported one more partition and the partition
# table type is "msdos" and the amount of partitions is more
# than 3, we just assume kpartx mapped the extended parition
# and we remove it.
if len(kpartxOutput) == d['numpart'] + 1 \
and d['ptable_format'] == 'msdos' and len(kpartxOutput) > 3:
kpartxOutput.pop(3)
else:
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)
# FIXME: there is a bit delay for multipath device setup,
# wait 10ms for the setup
import time
time.sleep(10)
d['mapped'] = True
开发者ID:Javoe,项目名称:splicer_poky,代码行数:75,代码来源:partitionedfs.py
注:本文中的mic.utils.runner.runtool函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论