当前位置: 首页>>代码示例>>Python>>正文


Python util.pathexists函数代码示例

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


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


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