• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python iutil.execWithCapture函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pyanaconda.iutil.execWithCapture函数的典型用法代码示例。如果您正苦于以下问题:Python execWithCapture函数的具体用法?Python execWithCapture怎么用?Python execWithCapture使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了execWithCapture函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: _build_mpath_topology

    def _build_mpath_topology(self):
        with open("/etc/multipath.conf") as conf:
            log.debug("/etc/multipath.conf contents:")
            map(lambda line: log.debug(line.rstrip()), conf)
            log.debug("(end of /etc/multipath.conf)")
        self._mpath_topology = parseMultipathOutput(
            iutil.execWithCapture("multipath", ["-d",]))
        self._mpath_topology.update(parseMultipathOutput(
                iutil.execWithCapture("multipath", ["-ll",])))

        delete_keys = []
        for (mp, disks) in self._mpath_topology.items():
            # single device mpath is not really an mpath, eliminate them:
            if len(disks) < 2:
                log.info("MultipathTopology: not a multipath: %s" % disks)
                delete_keys.append(mp)
                continue
            # some usb cardreaders use multiple lun's (for different slots) and
            # report a fake disk serial which is the same for all the lun's
            # (#517603). find those mpaths and eliminate them:
            only_non_usbs = [d for d in disks if
                             self._devmap[d].get("ID_USB_DRIVER") != "usb-storage"]
            if len(only_non_usbs) == 0:
                log.info("DeviceToppology: found multi lun usb "
                         "mass storage device: %s" % disks)
                delete_keys.append(mp)
        map(lambda key: self._mpath_topology.pop(key), delete_keys)
开发者ID:masami256,项目名称:Anaconda-for-ore-ore-kernel,代码行数:27,代码来源:mpath.py


示例2: testExecCaptureNonZeroFatal

    def testExecCaptureNonZeroFatal(self):
        import iutil

        try:
            argv = ["-c", "import sys; sys.exit(3);"]
            iutil.execWithCapture(sys.executable, argv, root=None, fatal=True)
        except RuntimeError, ex:
            self.assertIn("return code: 3", str(ex))
开发者ID:uofis,项目名称:qubes-installer-qubes-os,代码行数:8,代码来源:iutil_test.py


示例3: exec_with_capture_test

    def exec_with_capture_test(self):
        """Test execWithCapture."""

        # check some output is returned
        self.assertGreater(len(iutil.execWithCapture("ls", ["--help"])), 0)

        # check no output is returned
        self.assertEqual(len(iutil.execWithCapture("true", [])), 0)
开发者ID:nandakishore1006,项目名称:anaconda,代码行数:8,代码来源:iutil_test.py


示例4: shutdownServer

def shutdownServer():
    """Try to shutdown any running XVNC server

    Why is this function on the module level and not in the VncServer class ?

    As the server needs to be killed from the exit handler, it would have
    to somehow get to the VncServer instance. Like this, it can just kill
    it by calling a function of the vnc module.
    """
    try:
        iutil.execWithCapture("killall", [XVNC_BINARY_NAME])
        log.info("The XVNC server has been shut down.")
    except OSError as e:
        log.error("Shutdown of the XVNC server failed with exception:\n%s", e)
开发者ID:bwann,项目名称:anaconda,代码行数:14,代码来源:vnc.py


示例5: exec_with_capture_empty_test

    def exec_with_capture_empty_test(self):
        """Test execWithCapture with no output"""

        # check that the output is an empty string
        self.assertEqual(
                iutil.execWithCapture("/bin/sh", ["-c", "exit 0"]),
                "")
开发者ID:jaymzh,项目名称:anaconda,代码行数:7,代码来源:iutil_test.py


示例6: pvinfo

def pvinfo(device):
    """
        If the PV was created with '--metadacopies 0', lvm will do some
        scanning of devices to determine from their metadata which VG
        this PV belongs to.

        pvs -o pv_name,pv_mda_count,vg_name,vg_uuid --config \
            'devices { scan = "/dev" filter = ["a/loop0/", "r/.*/"] }'
    """
    #cfg = "'devices { scan = \"/dev\" filter = [\"a/%s/\", \"r/.*/\"] }'" 
    args = ["pvs", "--noheadings"] + \
            ["--units", "m"] + \
            ["-o", "pv_name,pv_mda_count,vg_name,vg_uuid"] + \
            config_args + \
            [device]

    rc = iutil.execWithCapture("lvm", args,
                                stderr = "/dev/tty5")
    vals = rc.split()
    if not vals:
        raise LVMError("pvinfo failed for %s" % device)

    # don't raise an exception if pv is not a part of any vg
    pv_name = vals[0]
    try:
        vg_name, vg_uuid = vals[2], vals[3]
    except IndexError:
        vg_name, vg_uuid = "", ""
    
    info = {'pv_name': pv_name,
            'vg_name': vg_name,
            'vg_uuid': vg_uuid}

    return info
开发者ID:masami256,项目名称:Anaconda-for-ore-ore-kernel,代码行数:34,代码来源:lvm.py


示例7: lvs

def lvs(vg_name):
    args = ["lvs", "--noheadings", "--nosuffix"] + \
            ["--units", "m"] + \
            ["-o", "lv_name,lv_uuid,lv_size,lv_attr"] + \
            config_args + \
            [vg_name]

    buf = iutil.execWithCapture("lvm",
                                args,
                                stderr="/dev/tty5")

    lvs = {}
    for line in buf.splitlines():
        line = line.strip()
        if not line:
            continue
        (name, uuid, size, attr) = line.split()
        lvs[name] = {"size": size,
                     "uuid": uuid,
                     "attr": attr}

    if not lvs:
        raise LVMError(_("lvs failed for %s" % vg_name))

    return lvs
开发者ID:masami256,项目名称:Anaconda-for-ore-ore-kernel,代码行数:25,代码来源:lvm.py


示例8: minSize

    def minSize(self):
        """ The minimum filesystem size in megabytes. """
        if self._minInstanceSize is None:
            # we try one time to determine the minimum size.
            size = self._minSize
            if self.exists and os.path.exists(self.device):
                minSize = None
                buf = iutil.execWithCapture(self.resizefsProg,
                                            ["-m", self.device],
                                            stderr = "/dev/tty5")
                for l in buf.split("\n"):
                    if not l.startswith("Minsize"):
                        continue
                    try:
                        min = l.split(":")[1].strip()
                        minSize = int(min) + 250
                    except Exception, e:
                        minSize = None
                        log.warning("Unable to parse output for minimum size on %s: %s" %(self.device, e))

                if minSize is None:
                    log.warning("Unable to discover minimum size of filesystem "
                                "on %s" %(self.device,))
                else:
                    size = minSize

            self._minInstanceSize = size
开发者ID:masami256,项目名称:Anaconda-for-ore-ore-kernel,代码行数:27,代码来源:fs.py


示例9: exec_with_capture_no_stderr_test

    def exec_with_capture_no_stderr_test(self):
        """Test execWithCapture with no stderr"""

        with tempfile.NamedTemporaryFile(mode="w+t") as testscript:
            testscript.write(
                """#!/bin/sh
echo "output"
echo "error" >&2
"""
            )
            testscript.flush()

            # check that only the output is captured
            self.assertEqual(iutil.execWithCapture("/bin/sh", [testscript.name], filter_stderr=True), "output\n")

            # check that both output and error are captured
            self.assertEqual(iutil.execWithCapture("/bin/sh", [testscript.name]), "output\nerror\n")
开发者ID:nandakishore1006,项目名称:anaconda,代码行数:17,代码来源:iutil_test.py


示例10: modulesWithPaths

def modulesWithPaths():
    mods = []
    for modline in open("/proc/modules", "r"):
        modName = modline.split(" ", 1)[0]
        modInfo = iutil.execWithCapture("modinfo", ["-F", "filename", modName]).splitlines()
        modPaths = [line.strip() for line in modInfo if line != ""]
        mods.extend(modPaths)
    return mods
开发者ID:masami256,项目名称:Anaconda-for-ore-ore-kernel,代码行数:8,代码来源:__init__.py


示例11: ifaceForHostIP

def ifaceForHostIP(host):
    route = iutil.execWithCapture("ip", ["route", "get", "to", host])
    if not route:
        log.error("Could not get interface for route to %s", host)
        return ""

    routeInfo = route.split()
    if routeInfo[0] != host or len(routeInfo) < 5 or "dev" not in routeInfo or routeInfo.index("dev") > 3:
        log.error('Unexpected "ip route get to %s" reply: %s', host, routeInfo)
        return ""

    return routeInfo[routeInfo.index("dev") + 1]
开发者ID:uofis,项目名称:qubes-installer-qubes-os,代码行数:12,代码来源:network.py


示例12: writeZipl

    def writeZipl(self, instRoot, bl, kernelList, chainList,
                  defaultDev, justConfigFile):
        rootDev = self.storage.rootDevice
        
        cf = '/etc/zipl.conf'
        self.perms = 0600
        if os.access (instRoot + cf, os.R_OK):
            self.perms = os.stat(instRoot + cf)[0] & 0777
            os.rename(instRoot + cf,
                      instRoot + cf + '.rpmsave')

        f = open(instRoot + cf, "w+")        

        f.write('[defaultboot]\n')
        if self.timeout:
            f.write('timeout=%d\n' % self.timeout)
        f.write('default=' + kernelList[0][0] + '\n')
        f.write('target=%s\n' % (self.kernelLocation))

        cfPath = "/boot/"
        for (label, longlabel, version) in kernelList:
            kernelTag = "-" + version
            kernelFile = "%svmlinuz%s" % (cfPath, kernelTag)

            initrd = self.makeInitrd(kernelTag, instRoot)
            f.write('[%s]\n' % (label))
            f.write('\timage=%s\n' % (kernelFile))
            if initrd:
                f.write('\tramdisk=%s%s\n' %(self.kernelLocation, initrd))

            realroot = rootDev.fstabSpec
            f.write('\tparameters="root=%s' %(realroot,))
            if bl.args.get():
                f.write(' %s' % (bl.args.get()))
            f.write('"\n')

        f.close()

        if not justConfigFile:
            rc = iutil.execWithCapture("zipl", [], root = instRoot,
                                       stderr = "/dev/stderr")
            for line in rc.splitlines():
                if line.startswith("Preparing boot device: "):
                    # Output here may look like:
                    #     Preparing boot device: dasdb (0200).
                    #     Preparing boot device: dasdl.
                    # We want to extract the device name and pass that.

                    fields = line[23:].split()
                    self.setDevice(fields[0].replace('.', ''))

        return 0
开发者ID:masami256,项目名称:Anaconda-for-ore-ore-kernel,代码行数:52,代码来源:s390.py


示例13: _startEDD

    def _startEDD(self, intf = None):
        rc = iutil.execWithCapture("/usr/libexec/fcoe/fcoe_edd.sh", [ "-i" ],
                                   stderr="/dev/tty5")
        if not rc.startswith("NIC="):
            log.info("No FCoE EDD info found: %s" % rc.rstrip())
            return

        (key, val) = rc.strip().split("=", 1)
        if val not in isys.getDeviceProperties():
            log.error("Unknown FCoE NIC found in EDD: %s, ignoring" % val)
            return

        log.info("FCoE NIC found in EDD: %s" % val)
        self.addSan(val, dcb=True, auto_vlan=True, intf=intf)
开发者ID:mattias-ohlsson,项目名称:anaconda,代码行数:14,代码来源:fcoe.py


示例14: lvorigin

def lvorigin(vg_name, lv_name):
    args = ["lvs", "--noheadings", "-o", "origin"] + \
            config_args + \
            ["%s/%s" % (vg_name, lv_name)]

    buf = iutil.execWithCapture("lvm",
                                args,
                                stderr="/dev/tty5")

    try:
        origin = buf.splitlines()[0].strip()
    except IndexError:
        origin = ''

    return origin
开发者ID:masami256,项目名称:Anaconda-for-ore-ore-kernel,代码行数:15,代码来源:lvm.py


示例15: vginfo

def vginfo(vg_name):
    args = ["vgs", "--noheadings", "--nosuffix"] + \
            ["--units", "m"] + \
            ["-o", "uuid,size,free,extent_size,extent_count,free_count,pv_count"] + \
            config_args + \
            [vg_name]

    buf = iutil.execWithCapture("lvm",
                                args,
                                stderr="/dev/tty5")
    info = buf.split()
    if len(info) != 7:
        raise LVMError(_("vginfo failed for %s" % vg_name))

    d = {}
    (d['uuid'],d['size'],d['free'],d['pe_size'],
     d['pe_count'],d['pe_free'],d['pv_count']) = info
    return d
开发者ID:masami256,项目名称:Anaconda-for-ore-ore-kernel,代码行数:18,代码来源:lvm.py


示例16: write

    def write(self):
        if self.desktop:
            with open(ROOT_PATH + "/etc/sysconfig/desktop", "w") as f:
                f.write("DESKTOP=%s\n" % self.desktop)

        if not os.path.isdir(ROOT_PATH + '/etc/systemd/system'):
            log.warning("there is no /etc/systemd/system directory, cannot update default.target!")
            return

        default_target = ROOT_PATH + '/etc/systemd/system/default.target'
        if os.path.islink(default_target):
            os.unlink(default_target)

        sd_prefix = iutil.execWithCapture(
            "pkg-config", ["--variable=prefix", "systemd"]).strip()
        if not sd_prefix:
            sd_prefix = "/usr"  # assume /usr in Gentoo/Sabayon

        os.symlink('%s/lib/systemd/system/%s' % (
                sd_prefix, RUNLEVELS[self.runlevel]),
                   default_target)
开发者ID:Sabayon,项目名称:anaconda,代码行数:21,代码来源:desktop.py


示例17: mdexamine

def mdexamine(device):
    vars = iutil.execWithCapture("mdadm",
                                 ["--examine", "--brief", device],
                                 stderr="/dev/tty5").split()

    info = {}
    if vars:
        try:
            info["device"] = vars[1]
            vars = vars[2:]
        except IndexError:
            return {}

    for var in vars:
        (name, equals, value) = var.partition("=")
        if not equals:
            continue

        info[name.lower()] = value.strip()

    return info
开发者ID:masami256,项目名称:Anaconda-for-ore-ore-kernel,代码行数:21,代码来源:mdraid.py


示例18: nmcli_dev_list_callback

def nmcli_dev_list_callback():
    """Callback to get info about network devices."""

    return iutil.execWithCapture("nmcli", ["device", "show"])
开发者ID:josefbacik,项目名称:anaconda,代码行数:4,代码来源:exception.py


示例19: lsblk_callback

def lsblk_callback():
    """Callback to get info about block devices."""

    return iutil.execWithCapture("lsblk", ["--perms", "--fs", "--bytes"])
开发者ID:josefbacik,项目名称:anaconda,代码行数:4,代码来源:exception.py


示例20: startup

    def startup(self, intf, exclusiveDisks, zeroMbr):
        """ Look for any unformatted DASDs in the system and offer the user
            the option for format them with dasdfmt or exit the installer.
        """
        if self.started:
            return

        self.started = True
        out = "/dev/tty5"
        err = "/dev/tty5"

        if not iutil.isS390():
            return

        log.info("Checking for unformatted DASD devices:")

        for device in os.listdir("/sys/block"):
            if not device.startswith("dasd"):
                continue

            statusfile = "/sys/block/%s/device/status" % (device,)
            if not os.path.isfile(statusfile):
                continue

            f = open(statusfile, "r")
            status = f.read().strip()
            f.close()

            if status in ["unformatted"] and device not in exclusiveDisks:
                bypath = deviceNameToDiskByPath(device)
                if not bypath:
                    bypath = "/dev/" + device

                log.info("    %s (%s) status is %s, needs dasdfmt" % (device,
                                                                      bypath,
                                                                      status,))
                self._dasdlist.append((device, bypath))

        if not len(self._dasdlist):
            log.info("    no unformatted DASD devices found")
            return

        askUser = True

        if zeroMbr:
            askUser = False
        elif not intf and not zeroMbr:
            log.info("    non-interactive kickstart install without zerombr "
                     "command, unable to run dasdfmt, exiting installer")
            sys.exit(0)

        c = len(self._dasdlist)

        if intf and askUser:
            devs = ''
            for dasd, bypath in self._dasdlist:
                devs += "%s\n" % (bypath,)

            rc = intf.questionInitializeDASD(c, devs)
            if rc == 1:
                log.info("    not running dasdfmt, continuing installation")
                return

        # gather total cylinder count
        argv = ["-t", "-v"] + self.commonArgv
        for dasd, bypath in self._dasdlist:
            buf = iutil.execWithCapture(self.dasdfmt, argv + ["/dev/" + dasd],
                                        stderr=err)
            for line in buf.splitlines():
                if line.startswith("Drive Geometry: "):
                    # line will look like this:
                    # Drive Geometry: 3339 Cylinders * 15 Heads =  50085 Tracks
                    cyls = long(filter(lambda s: s, line.split(' '))[2])
                    self.totalCylinders += cyls
                    break

        # format DASDs
        argv = ["-P"] + self.commonArgv
        update = self._updateProgressWindow

        title = P_("Formatting DASD Device", "Formatting DASD Devices", c)
        msg = P_("Preparing %d DASD device for use with Linux..." % c,
                 "Preparing %d DASD devices for use with Linux..." % c, c)

        if intf:
            if self.totalCylinders:
                pw = intf.progressWindow(title, msg, 1.0)
            else:
                pw = intf.progressWindow(title, msg, 100, pulse=True)

        for dasd, bypath in self._dasdlist:
            log.info("Running dasdfmt on %s" % (bypath,))
            arglist = argv + ["/dev/" + dasd]

            try:
                if intf and self.totalCylinders:
                    ret = iutil.execWithCallback(self.dasdfmt, arglist,
                                                 stdout=out, stderr=err,
                                                 callback=update,
                                                 callback_data=pw,
#.........这里部分代码省略.........
开发者ID:masami256,项目名称:Anaconda-for-ore-ore-kernel,代码行数:101,代码来源:dasd.py



注:本文中的pyanaconda.iutil.execWithCapture函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python iutil.execWithRedirect函数代码示例发布时间:2022-05-25
下一篇:
Python iutil.execReadlines函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap