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

Python util.pathexists函数代码示例

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

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



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

示例1: _find_path_with_retries

    def _find_path_with_retries(self, vdi_uuid, maxretry=5, period=2.0):
        vhd_path = os.path.join(self.sr.path, "%s.%s" % \
                                (vdi_uuid, self.PARAM_VHD))
        raw_path = os.path.join(self.sr.path, "%s.%s" % \
                                (vdi_uuid, self.PARAM_RAW))
        cbt_path = os.path.join(self.sr.path, "%s.%s" %
                                (vdi_uuid, CBTLOG_TAG))
        found = False
        tries = 0
        while tries < maxretry and not found:
            tries += 1
            if util.ioretry(lambda: util.pathexists(vhd_path)):
                self.vdi_type = vhdutil.VDI_TYPE_VHD
                self.path = vhd_path
                found = True
            elif util.ioretry(lambda: util.pathexists(raw_path)):
                self.vdi_type = vhdutil.VDI_TYPE_RAW
                self.path = raw_path
                self.hidden = False
                found = True
            elif util.ioretry(lambda: util.pathexists(cbt_path)):
                self.vdi_type = CBTLOG_TAG
                self.path = cbt_path
                self.hidden = False
                found = True

            if not found:
                util.SMlog("VHD %s not found, retry %s of %s" % (vhd_path, tries, maxretry))
                time.sleep(period)

        return found
开发者ID:chandrikas,项目名称:sm,代码行数:31,代码来源:FileSR.py


示例2: _checkActive

def _checkActive(path):
    if util.pathexists(path):
        return True

    util.SMlog("_checkActive: %s does not exist!" % path)
    symlinkExists = os.path.lexists(path)
    util.SMlog("_checkActive: symlink exists: %s" % symlinkExists)

    mapperDeviceExists = False
    mapperDevice = path[5:].replace("-", "--").replace("/", "-")
    cmd = [CMD_DMSETUP, "status", mapperDevice]
    try:
        ret = util.pread2(cmd)
        mapperDeviceExists = True
        util.SMlog("_checkActive: %s: %s" % (mapperDevice, ret))
    except util.CommandException:
        util.SMlog("_checkActive: device %s does not exist" % mapperDevice)

    mapperPath = "/dev/mapper/" + mapperDevice
    mapperPathExists = util.pathexists(mapperPath)
    util.SMlog("_checkActive: path %s exists: %s" % \
            (mapperPath, mapperPathExists))

    if mapperDeviceExists and mapperPathExists and not symlinkExists:
        # we can fix this situation manually here
        try:
            util.SMlog("_checkActive: attempt to create the symlink manually.")
            os.symlink(mapperPath, path)
        except OSError, e:
            util.SMlog("ERROR: failed to symlink!")
            if e.errno != errno.EEXIST:
                raise
        if util.pathexists(path):
            util.SMlog("_checkActive: created the symlink manually")
            return True
开发者ID:MarkSymsCtx,项目名称:sm,代码行数:35,代码来源:lvutil.py


示例3: _checkmount

    def _checkmount(self):
        mount_path = self.path
        if self.handles("cifs"):
            mount_path = self.mountpoint

        return util.ioretry(lambda: util.pathexists(mount_path) and \
                                (util.ismount(mount_path) or \
                                 util.pathexists(self.remotepath) and self._isbind()))
开发者ID:falaa,项目名称:sm,代码行数:8,代码来源:FileSR.py


示例4: __init__

 def __init__(self, ns):
     self.ns = ns
     self.nsDir = os.path.join(self.BASE_DIR, self.ns)
     if not util.pathexists(self.nsDir):
         try:
             os.makedirs(self.nsDir)
         except OSError:
             pass
     if not util.pathexists(self.nsDir):
         raise IPCFlagException("failed to create %s" % self.nsDir)
开发者ID:BobBall,项目名称:sm,代码行数:10,代码来源:ipc.py


示例5: createJournalDir

def createJournalDir():
    if util.pathexists(VHD_JOURNAL_LOCATION):
        return
    try:
        os.makedirs(VHD_JOURNAL_LOCATION)
    except OSError:
        pass
    if not util.pathexists(VHD_JOURNAL_LOCATION):
        raise util.SMException("Failed to create dirs %s" % \
                VHD_JOURNAL_LOCATION)
开发者ID:redivy,项目名称:xe-storage-plugins,代码行数:10,代码来源:vhdutil.py


示例6: _reset

 def _reset(ns, obj = None):
     nsDir = os.path.join(RefCounter.BASE_DIR, ns)
     if not util.pathexists(nsDir):
         return
     if obj:
         if not util.pathexists(os.path.join(nsDir, obj)):
             return
         objList = [obj]
     else:
         try:
             objList = os.listdir(nsDir)
         except OSError:
             raise RefCounterException("failed to list '%s'" % ns)
     for obj in objList:
         RefCounter._removeObject(ns, obj)
开发者ID:GaryKirkpatrick,项目名称:sm,代码行数:15,代码来源:refcounter.py


示例7: _get

 def _get(ns, obj):
     """Get the ref count values for 'obj' in namespace 'ns'"""
     objFile = os.path.join(RefCounter.BASE_DIR, ns, obj)
     (count, binaryCount) = (0, 0)
     if util.pathexists(objFile):
         (count, binaryCount) = RefCounter._readCount(objFile)
     return (count, binaryCount)
开发者ID:GaryKirkpatrick,项目名称:sm,代码行数:7,代码来源:refcounter.py


示例8: delete

    def delete(self, sr_uuid):
        if not self._checkpath(self.path):
            raise xs_errors.XenError("SRUnavailable", opterr="no such directory %s" % self.path)
        cleanup.gc_force(self.session, self.uuid)

        # check to make sure no VDIs are present; then remove old
        # files that are non VDI's
        try:
            if util.ioretry(lambda: util.pathexists(self.path)):
                # Load the VDI list
                self._loadvdis()
                for uuid in self.vdis:
                    if not self.vdis[uuid].deleted:
                        raise xs_errors.XenError("SRNotEmpty", opterr="VDIs still exist in SR")

                # remove everything else, there are no vdi's
                for name in util.ioretry(lambda: util.listdir(self.path)):
                    fullpath = os.path.join(self.path, name)
                    try:
                        util.ioretry(lambda: os.unlink(fullpath))
                    except util.CommandException, inst:
                        if inst.code != errno.ENOENT and inst.code != errno.EISDIR:
                            raise xs_errors.XenError(
                                "FileSRDelete", opterr="failed to remove %s error %d" % (fullpath, inst.code)
                            )
        except util.CommandException, inst:
            raise xs_errors.XenError("FileSRDelete", opterr="error %d" % inst.code)
开发者ID:rdobson,项目名称:sm,代码行数:27,代码来源:FileSR.py


示例9: load

    def load(self, vdi_uuid):
        self.vdi_type = SR.DEFAULT_TAP
        self.path = os.path.join(self.sr.path, "%s.%s" % \
                                (vdi_uuid,self.vdi_type))
        if util.ioretry(lambda: util.pathexists(self.path)):
            try:
                st = util.ioretry(lambda: os.stat(self.path))
                self.utilisation = long(st.st_size)
            except util.CommandException, inst:
                if inst.code == errno.EIO:
                    raise xs_errors.XenError('VDILoad', \
                          opterr='Failed load VDI information %s' % self.path)
                else:
                    raise xs_errors.XenError('VDIType', \
                          opterr='Invalid VDI type %s' % self.vdi_type)

            try:
                diskinfo = util.ioretry(lambda: self._query_info(self.path))
                if diskinfo.has_key('parent'):
                    self.parent = diskinfo['parent']
                else:
                    self.parent = ''
                self.size = long(diskinfo['size']) * 1024 * 1024
                self.hidden = long(diskinfo['hidden'])
            except util.CommandException, inst:
                raise xs_errors.XenError('VDILoad', \
                      opterr='Failed load VDI information %s' % self.path)
开发者ID:BobBall,项目名称:sm,代码行数:27,代码来源:FileSR.py


示例10: create

    def create(self, sr_uuid, vdi_uuid, size):
        if util.ioretry(lambda: util.pathexists(self.path)):
            raise xs_errors.XenError('VDIExists')

        overhead = 0
        if self.vdi_type == vhdutil.VDI_TYPE_VHD:
            overhead = vhdutil.calcOverheadFull(long(size))

        # Test the amount of actual disk space
        if ENFORCE_VIRT_ALLOC:
            self.sr._loadvdis()
            reserved = self.sr.virtual_allocation
            sr_size = self.sr._getsize()
            if (sr_size - reserved) < (long(size) + overhead):
                raise xs_errors.XenError('SRNoSpace')

        if self.vdi_type == vhdutil.VDI_TYPE_VHD:
            try:
                mb = 1024L * 1024L
                size_mb = util.roundup(VHD_SIZE_INC, long(size)) / mb
                if size_mb < 1 or (size_mb + (overhead / mb)) >= MAX_DISK_MB:
                    raise xs_errors.XenError('VDISize', opterr='VDI size ' + \
                            'must be between 1 MB and %d MB' % \
                            ((MAX_DISK_MB - MAX_DISK_METADATA) - 1))
                util.ioretry(lambda: self._create(str(size_mb), self.path))
                self.size = util.ioretry(lambda: self._query_v(self.path))
            except util.CommandException, inst:
                raise xs_errors.XenError('VDICreate',
                        opterr='error %d' % inst.code)
开发者ID:falaa,项目名称:sm,代码行数:29,代码来源:FileSR.py


示例11: _createNamespace

 def _createNamespace(ns):
     nsDir = os.path.join(RefCounter.BASE_DIR, ns)
     if not util.pathexists(nsDir):
         try:
             os.makedirs(nsDir)
         except OSError:
             raise RefCounterException("failed to makedirs '%s'" % nsDir)
开发者ID:redivy,项目名称:xe-storage-plugins,代码行数:7,代码来源:refcounter.py


示例12: _checkpath

 def _checkpath(self, path):
     try:
         if not util.ioretry(lambda: util.pathexists(path)):
             return False
         return True
     except util.CommandException, inst:
         raise xs_errors.XenError("EIO", opterr="IO error checking path %s" % path)
开发者ID:MarkSymsCtx,项目名称:sm,代码行数:7,代码来源:FileSR.py


示例13: delete

    def delete(self, sr_uuid):
        self.attach(sr_uuid)
        cleanup.gc_force(self.session, self.uuid)

        # check to make sure no VDIs are present; then remove old 
        # files that are non VDI's
        try:
            if util.ioretry(lambda: util.pathexists(self.path)):
                #Load the VDI list
                self._loadvdis()
                for uuid in self.vdis:
                    if not self.vdis[uuid].deleted:
                        raise xs_errors.XenError('SRNotEmpty', \
                              opterr='VDIs still exist in SR')

                # remove everything else, there are no vdi's
                for name in util.ioretry(lambda: util.listdir(self.path)):
                    fullpath =  os.path.join(self.path,name)
                    try:
                        util.ioretry(lambda: os.unlink(fullpath))
                    except util.CommandException, inst:
                        if inst.code != errno.ENOENT and \
                           inst.code != errno.EISDIR:
                            raise xs_errors.XenError('FileSRDelete', \
                                  opterr='failed to remove %s error %d' \
                                  % (fullpath, inst.code))
            self.detach(sr_uuid)
开发者ID:falaa,项目名称:sm,代码行数:27,代码来源:FileSR.py


示例14: create

    def create(self, sr_uuid, vdi_uuid, size):
        if util.ioretry(lambda: util.pathexists(self.path)):
            raise xs_errors.XenError('VDIExists')

        overhead = 0
        if self.vdi_type == vhdutil.VDI_TYPE_VHD:
            overhead = vhdutil.calcOverheadFull(long(size))

        # Test the amount of actual disk space
        if ENFORCE_VIRT_ALLOC:
            self.sr._loadvdis()
            reserved = self.sr.virtual_allocation
            sr_size = self.sr._getsize()
            if (sr_size - reserved) < (long(size) + overhead):
                raise xs_errors.XenError('SRNoSpace')

        if self.vdi_type == vhdutil.VDI_TYPE_VHD:
            try:
                size = vhdutil.validate_and_round_vhd_size(long(size))
                mb = 1024L * 1024L
                size_mb = long(size) / mb
                util.ioretry(lambda: self._create(str(size_mb), self.path))
                self.size = util.ioretry(lambda: self._query_v(self.path))
            except util.CommandException, inst:
                raise xs_errors.XenError('VDICreate',
                        opterr='error %d' % inst.code)
开发者ID:chandrikas,项目名称:sm,代码行数:26,代码来源:FileSR.py


示例15: create

    def create(self, sr_uuid, size):
        if util.ioretry(lambda: self._checkmount()):
            raise xs_errors.XenError('NFSAttached')

        # Set the target path temporarily to the base dir
        # so that we can create the target SR directory
        self.remotepath = self.dconf['serverpath']
        try:
            self.attach(sr_uuid)
        except:
            try:
                os.rmdir(self.path)
            except:
                pass
            raise xs_errors.XenError('NFSMount')
        newpath = os.path.join(self.path, sr_uuid)
        if util.ioretry(lambda: util.pathexists(newpath)):
            if len(util.ioretry(lambda: util.listdir(newpath))) != 0:
                self.detach(sr_uuid)
                raise xs_errors.XenError('SRExists')
        else:
            try:
                util.ioretry(lambda: util.makedirs(newpath))
            except util.CommandException, inst:
                if inst.code != errno.EEXIST:
                    self.detach(sr_uuid)
                    raise xs_errors.XenError('NFSCreate', \
                          opterr='remote directory creation error is %d' \
                          % inst.code)
开发者ID:BobBall,项目名称:sm,代码行数:29,代码来源:NFSSR.py


示例16: create

 def create(self, sr_uuid, size):
     if util.pathexists(self.blockdevice):
         util.zeroOut(self.blockdevice, 0, 1024 * 1024)
     cmd = ["mkfs", "-t", "ocfs2", "-b", "4K", "-C", "1M", "-N", "16", "-F", self.blockdevice]
     try:
         ret = util.pread(cmd)
     except util.CommandException, inst:
         raise xs_errors.XenError("OCFSFilesystem", opterr="mkfs failed error %d" % os.strerror(inst.code))
开发者ID:MarkSymsCtx,项目名称:sm,代码行数:8,代码来源:OCFSSR.py


示例17: _checkpath

 def _checkpath(self, path):
     try:
         if util.ioretry(lambda: util.pathexists(path)):
             if util.ioretry(lambda: util.isdir(path)):
                 return True
         return False
     except util.CommandException, inst:
         raise xs_errors.XenError('EIO', \
               opterr='IO error checking path %s' % path)
开发者ID:redivy,项目名称:xe-storage-plugins,代码行数:9,代码来源:FileSR.py


示例18: create

 def create(self, sr_uuid, size):
     if util.pathexists(self.blockdevice):
         util.zeroOut(self.blockdevice, 0, 1024*1024)
     cmd = ['mkfs', '-t', 'ocfs2', '-b', '4K', '-C', '1M', '-N', '16', '-F', self.blockdevice ]
     try:
         ret = util.pread(cmd)
     except util.CommandException, inst:
         raise xs_errors.XenError('OCFSFilesystem', \
               opterr='mkfs failed error %d' % os.strerror(inst.code))
开发者ID:Sisimon,项目名称:sm,代码行数:9,代码来源:OCFSSR.py


示例19: attach

 def attach(self, sr_uuid, vdi_uuid):
     self.sr._loadvdis()
     if not self.sr.vdis.has_key(vdi_uuid):
         raise xs_errors.XenError('VDIUnavailable')
     if not util.pathexists(self.path):
         self.sr.refresh()
         if not util.wait_for_path(self.path, MAX_TIMEOUT):
             util.SMlog("Unable to detect LUN attached to host [%s]" % self.sr.path)
             raise xs_errors.XenError('VDIUnavailable')
     return super(RAWVDI, self).attach(sr_uuid, vdi_uuid)
开发者ID:JohnGarbutt,项目名称:xcp-storage-managers,代码行数:10,代码来源:LUNperVDI.py


示例20: attach_from_config

 def attach_from_config(self, sr_uuid, vdi_uuid):
     """Used for HA State-file only. Will not just attach the VDI but
     also start a tapdisk on the file"""
     util.SMlog("OCFSFileVDI.attach_from_config")
     try:
         if not util.pathexists(self.sr.path):
             self.sr.attach(sr_uuid)
     except:
         util.logException("OCFSFileVDI.attach_from_config")
         raise xs_errors.XenError("SRUnavailable", opterr="Unable to attach from config")
开发者ID:MarkSymsCtx,项目名称:sm,代码行数:10,代码来源:OCFSSR.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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