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

Python util.listdir函数代码示例

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

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



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

示例1: get_lun_scsiid_devicename_mapping

def get_lun_scsiid_devicename_mapping(targetIQN, portal):
    iscsilib.refresh_luns(targetIQN, portal)
    lunToScsiId={}
    path = os.path.join("/dev/iscsi",targetIQN,portal)
    try:
	deviceToLun = {}
	deviceToScsiId = {}
        for file in util.listdir(path):
	    realPath = os.path.realpath(os.path.join(path, file))
	    if file.find("LUN") == 0 and file.find("_") == -1:		
                lun=file.replace("LUN","")
		if deviceToScsiId.has_key(realPath):
		    lunToScsiId[lun] = (deviceToScsiId[realPath], realPath) 
		else:
		    deviceToLun[realPath] = lun
	        continue
		
	    if file.find("SERIAL-") == 0:
		scsiid = file.replace("SERIAL-", "")
		# found the SCSI ID, check if LUN has already been seen for this SCSI ID.
		if deviceToLun.has_key(realPath):
		    # add this to the map
		    lunId = deviceToLun[realPath]
                    lunToScsiId[lunId] = (scsiid, realPath)
                else:
		    # The SCSI ID was seen first so add this to the map
		    deviceToScsiId[realPath] = scsiid

        return lunToScsiId
    except util.CommandException, inst:
        XenCertPrint("Failed to find any LUNs for IQN: %s and portal: %s" % targetIQN, portal)
        return {}
开发者ID:siddharthv,项目名称:xencert,代码行数:32,代码来源:StorageHandlerUtil.py


示例2: get_conferences

def get_conferences():
    files = util.listdir(CONFERENCE_FOLDER)
    util.mkdir(CONFERENCE_CRALWED_FOLDER)
    cnt = 0
    conf = util.load_json('conf_name.json')
    for file_name in files:
        save_path = os.path.join(CONFERENCE_CRALWED_FOLDER, file_name)
        if util.exists(save_path):
            continue
        data = util.load_json(os.path.join(CONFERENCE_FOLDER, file_name))
        if data['short'] not in conf.keys():
            continue
        html = util.get_page(data['url'])
        subs = get_subs(data['short'], html)
        data['name'] = conf[data['short']]
        data['sub'] = {}
        for sub in subs:
            if sub not in conf.keys():
                continue
            html = util.get_page('http://dblp.uni-trier.de/db/conf/' + sub)
            data['sub'][sub] = {}
            data['sub'][sub]['pub'] = get_publications(html)
            data['sub'][sub]['name'] = conf[sub]
        cnt += 1
        print cnt, len(files), data['short']
        util.save_json(save_path, data)
开发者ID:sdq11111,项目名称:ShEngine,代码行数:26,代码来源:get_publications.py


示例3: print_LUNs

    def print_LUNs(self):
        self.LUNs = {}
        if os.path.exists(self.path):
            for file in util.listdir(self.path):
                if file.find("LUN") != -1 and file.find("_") == -1:
                    vdi_path = os.path.join(self.path,file)
                    LUNid = file.replace("LUN","")
                    obj = self.vdi(self.uuid)
                    obj._query(vdi_path, LUNid)
                    self.LUNs[obj.uuid] = obj

        dom = xml.dom.minidom.Document()
        element = dom.createElement("iscsi-target")
        dom.appendChild(element)
        for uuid in self.LUNs:
            val = self.LUNs[uuid]
            entry = dom.createElement('LUN')
            element.appendChild(entry)
            
            for attr in ('vendor', 'serial', 'LUNid', \
                         'size', 'SCSIid'):
                try:
                    aval = getattr(val, attr)
                except AttributeError:
                    continue
                
                if aval:
                    subentry = dom.createElement(attr)
                    entry.appendChild(subentry)           
                    textnode = dom.createTextNode(str(aval))
                    subentry.appendChild(textnode)

        print >>sys.stderr,dom.toprettyxml()
开发者ID:JohnGarbutt,项目名称:xcp-storage-managers,代码行数:33,代码来源:ISCSISR.py


示例4: scan_srlist

def scan_srlist(path, dconf):
    """Scan and report SR, UUID."""
    dom = xml.dom.minidom.Document()
    element = dom.createElement("SRlist")
    dom.appendChild(element)
    for val in filter(util.match_uuid, util.ioretry(
            lambda: util.listdir(path))):
        fullpath = os.path.join(path, val)
        if not util.ioretry(lambda: util.isdir(fullpath)):
            continue

        entry = dom.createElement('SR')
        element.appendChild(entry)

        subentry = dom.createElement("UUID")
        entry.appendChild(subentry)
        textnode = dom.createTextNode(val)
        subentry.appendChild(textnode)

    from NFSSR import PROBEVERSION
    if dconf.has_key(PROBEVERSION):
        util.SMlog("Add supported nfs versions to sr-probe")
        supported_versions = get_supported_nfs_versions(dconf.get('server'))
        supp_ver = dom.createElement("SupportedVersions")
        element.appendChild(supp_ver)

        for ver in supported_versions:
            version = dom.createElement('Version')
            supp_ver.appendChild(version)
            textnode = dom.createTextNode(ver)
            version.appendChild(textnode)

    return dom.toprettyxml()
开发者ID:Zaitypola,项目名称:sm,代码行数:33,代码来源:nfs.py


示例5: disk_info

def disk_info():
    logdir = dsz.lp.GetLogsDirectory()
    projectdir = os.path.split(logdir)[0]
    infofile = os.path.join(projectdir, 'disk-version.txt')
    if os.path.exists(infofile):
        dsz.ui.Echo(('Disk version already logged; if you switched disks for some reason, rename %s and restart the LP please.' % infofile), dsz.GOOD)
        return True
    opsdisk_root = os.path.normpath((dsz.lp.GetResourcesDirectory() + '/..'))
    dszfiles = util.listdir(opsdisk_root, '^DSZOpsDisk-.+\\.zip$')
    disk = None
    if (len(dszfiles) == 1):
        disk = dszfiles[0]
    elif (len(dszfiles) > 1):
        menu = util.menu.Menu('Found mulitple DSZOpsDisk zips:', dszfiles, None, 'Which one are you executing? ')
        index = (menu.show()[0] - 1)
        if ((index > 0) and (index < len(dszfiles))):
            disk = dszfiles[index]
        else:
            dsz.ui.Echo('Could not determine which opsdisk is running. Version NOT recorded.', dsz.ERROR)
            return False
    else:
        dsz.ui.Echo('Could not find DSZOpsDisk zip. Disk version NOT recorded.', dsz.ERROR)
        return False
    with open(infofile, 'w') as output:
        output.write(('%s\n' % disk))
    dsz.ui.Echo(('Disk version %s recorded to %s.' % (disk, infofile)), dsz.GOOD)
    return True
开发者ID:M31MOTH,项目名称:fuzzbunch,代码行数:27,代码来源:Startup.py


示例6: 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


示例7: 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


示例8: listDir

 def listDir(self, filesyspath, urlpath, outputStream):
     f = outputStream
     filelist, dirlist = util.listdir(filesyspath)
     filelist.sort(lambda a, b: cmp(a.lower(), b.lower()))
     dirlist.sort(lambda a, b: cmp(a.lower(), b.lower()))
     f.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">\n')
     f.write("<html>\n")
     f.write(
         ("<head><title>Directory listing for %s</title></head>\n" % urlpath)
         + ("<body>\n<h2>Directory listing for %s</h2>\n<hr>\n" % urlpath)
     )
     if urlpath:
         f.write('<p><a href="..">&uarr; parent directory</a>')
     if dirlist:
         f.write("<h4>Directories</h4>\n<ul>\n")
         f.write("\n".join(['<li><a href="%s/">%s</a>' % (urllib.quote(name), name) for name in dirlist]))
         f.write("</ul>\n")
     if filelist:
         f.write("<h4>Files</h4>\n<ul>\n")
         f.write("\n".join(['<li><a href="%s">%s</a>' % (urllib.quote(name), name) for name in filelist]))
         f.write("</ul>\n")
     else:
         f.write("<p>There are no files in this location.\n")
     f.write("<hr>\n\n<address>Served by Snakelets</address>")
     f.write("\n</body></html>")
开发者ID:rcarmo,项目名称:Yaki,代码行数:25,代码来源:server_ssl.py


示例9: 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


示例10: _probe_hba

    def _probe_hba(self):
        try:
            # use sysfs tree to gather FC data

            dom = xml.dom.minidom.Document()
            hbalist = dom.createElement("HBAInfoList")
            dom.appendChild(hbalist)

            hostlist = util.listdir("/sys/class/fc_host")
            for host in hostlist: 

                hbainfo = dom.createElement("HBAInfo")
                hbalist.appendChild(hbainfo)

                cmd = ["cat", "/sys/class/fc_host/%s/symbolic_name" % host]
                sname = util.pread(cmd)[:-1]
                entry = dom.createElement("model")
                hbainfo.appendChild(entry)
                textnode = dom.createTextNode(sname)
                entry.appendChild(textnode)

                cmd = ["cat", "/sys/class/fc_host/%s/node_name" % host]
                nname = util.pread(cmd)[:-1]
                nname = util.make_WWN(nname)
                entry = dom.createElement("nodeWWN")
                hbainfo.appendChild(entry)
                # adjust nodename to look like expected string
                textnode = dom.createTextNode(nname)
                entry.appendChild(textnode)

                port = dom.createElement("Port")
                hbainfo.appendChild(port)

                cmd = ["cat", "/sys/class/fc_host/%s/port_name" % host]
                pname = util.pread(cmd)[:-1]
                pname = util.make_WWN(pname)
                entry = dom.createElement("portWWN")
                port.appendChild(entry)
                # adjust nodename to look like expected string
                textnode = dom.createTextNode(pname)
                entry.appendChild(textnode)

                cmd = ["cat", "/sys/class/fc_host/%s/port_state" % host]
                state = util.pread(cmd)[:-1]
                entry = dom.createElement("state")
                port.appendChild(entry)
                # adjust nodename to look like expected string
                textnode = dom.createTextNode(state)
                entry.appendChild(textnode)

                entry = dom.createElement("deviceName")
                port.appendChild(entry)
                # adjust nodename to look like expected string
                textnode = dom.createTextNode("/sys/class/scsi_host/%s" % host)
                entry.appendChild(textnode)

            return dom.toxml()
        except:
            raise xs_errors.XenError('CSLGXMLParse', \
                                     opterr='HBA probe failed')
开发者ID:JohnGarbutt,项目名称:xcp-storage-managers,代码行数:60,代码来源:HBASR.py


示例11: probe

 def probe(self):
     try:
         err = "CIFSMount"
         self.mount(PROBE_MOUNTPOINT)
         sr_list = filter(util.match_uuid, util.listdir(PROBE_MOUNTPOINT))
         err = "CIFSUnMount"
         self.unmount(PROBE_MOUNTPOINT, True)
     except CifsException, inst:
         raise xs_errors.XenError(err, opterr=inst.errstr)
开发者ID:davidcunado,项目名称:sm,代码行数:9,代码来源:CIFSSR.py


示例12: print_LUNs

 def print_LUNs(self):
     self.LUNs = {}
     if os.path.exists(self.path):
         for file in util.listdir(self.path):
             if file.find("LUN") != -1 and file.find("_") == -1:
                 vdi_path = os.path.join(self.path,file)
                 LUNid = file.replace("LUN","")
                 obj = self.vdi(self.uuid)
                 obj._query(vdi_path, LUNid)
                 self.LUNs[obj.uuid] = obj
开发者ID:fudong1127,项目名称:sm,代码行数:10,代码来源:ISCSISR.py


示例13: _loadvdis

    def _loadvdis(self):
        """Scan the location directory."""
        if self.vdis:
            return

        try:
            for name in util.listdir(self.dconf['location']):
                if name != "":
                    self.vdis[name] = SHMVDI(self, util.gen_uuid(), name)
        except:
            pass
开发者ID:rdobson,项目名称:sm,代码行数:11,代码来源:SHMSR.py


示例14: get_luns

def get_luns(targetIQN, portal):
    refresh_luns(targetIQN, portal)
    luns=[]
    path = os.path.join("/dev/iscsi",targetIQN,portal)
    try:
        for file in util.listdir(path):
            if file.find("LUN") == 0 and file.find("_") == -1:
                lun=file.replace("LUN","")
                luns.append(lun)
        return luns
    except util.CommandException, inst:
        raise xs_errors.XenError('ISCSIDevice', opterr='Failed to find any LUNs')
开发者ID:BobBall,项目名称:sm,代码行数:12,代码来源:iscsilib.py


示例15: locate_files

def locate_files(file, subdir=None):
    if (subdir is None):
        subdir = '.'
    resdirs = util.listdir(ops.RESDIR, includeFiles=False)
    files = []
    for resdir in resdirs:
        if ((resdir.lower() == 'ops') or (resdir.lower() == 'dsz')):
            continue
        fullpath = os.path.normpath(os.path.join(ops.RESDIR, resdir, subdir, file))
        if os.path.exists(fullpath):
            files.append((resdir, fullpath))
    files.sort(cmp=(lambda x, y: cmp(x[0].lower(), y[0].lower())))
    return files
开发者ID:M31MOTH,项目名称:fuzzbunch,代码行数:13,代码来源:__init__.py


示例16: get_journals

def get_journals():
	files = util.listdir(JOURNAL_FOLDER)
	util.mkdir(JOURNAL_CRALWED_FOLDER)
	cnt = 0
	for file_name in files:
		save_path = os.path.join(JOURNAL_CRALWED_FOLDER, file_name)
		data = util.load_json(os.path.join(JOURNAL_FOLDER, file_name))
		html = util.get_page(data['url'])
		full_name = get_full_name(html)
		data['name'] = full_name
		cnt += 1
		print cnt, len(files), data['short']
		data['links'] = get_links(data['short'], html)
开发者ID:sdq11111,项目名称:ShEngine,代码行数:13,代码来源:crawl_info.py


示例17: create

    def create(self, sr_uuid, size):
        # Check SCSIid not already in use by other PBDs
        if util.test_SCSIid(self.session, sr_uuid, self.SCSIid):
            raise xs_errors.XenError('SRInUse')

        self.iscsi.attach(sr_uuid)
        try:
            if not self.iscsi._attach_LUN_bySCSIid(self.SCSIid):
                # UPGRADE FROM GEORGE: take care of ill-formed SCSIid
                upgraded = False
                matchSCSIid = False
                for file in filter(self.iscsi.match_lun, util.listdir(self.iscsi.path)):
                    path = os.path.join(self.iscsi.path,file)
                    if not util.wait_for_path(path, ISCSISR.MAX_TIMEOUT):
                        util.SMlog("Unable to detect LUN attached to host [%s]" % path)
                        continue
                    try:
                        SCSIid = scsiutil.getSCSIid(path)
                    except:
                        continue
                    try:
                        matchSCSIid = scsiutil.compareSCSIid_2_6_18(self.SCSIid, path)
                    except:
                        continue
                    if (matchSCSIid):
                        util.SMlog("Performing upgrade from George")
                        try:
                            pbd = util.find_my_pbd(self.session, self.host_ref, self.sr_ref)
                            device_config = self.session.xenapi.PBD.get_device_config(pbd)
                            device_config['SCSIid'] = SCSIid
                            self.session.xenapi.PBD.set_device_config(pbd, device_config)

                            self.dconf['SCSIid'] = SCSIid            
                            self.SCSIid = self.dconf['SCSIid']
                        except:
                            continue
                        if not self.iscsi._attach_LUN_bySCSIid(self.SCSIid):
                            raise xs_errors.XenError('InvalidDev')
                        else:
                            upgraded = True
                            break
                    else:
                        util.SMlog("Not a matching LUN, skip ... scsi_id is: %s" % SCSIid)
                        continue
                if not upgraded:
                    raise xs_errors.XenError('InvalidDev')
            self._pathrefresh(LVHDoISCSISR)
            LVHDSR.LVHDSR.create(self, sr_uuid, size)
        except Exception, inst:
            self.iscsi.detach(sr_uuid)
            raise xs_errors.XenError("SRUnavailable", opterr=inst)
开发者ID:pritha-srivastava,项目名称:sm,代码行数:51,代码来源:LVHDoISCSISR.py


示例18: _genHostList

def _genHostList(procname):
    # loop through and check all adapters
    ids = []
    try:
        for dir in util.listdir('/sys/class/scsi_host'):
            filename = os.path.join('/sys/class/scsi_host',dir,'proc_name')
            if os.path.exists(filename):
                f = open(filename, 'r')
                if f.readline().find(procname) != -1:
                    ids.append(dir.replace("host",""))
                f.close()
    except:
        pass
    return ids
开发者ID:billysuh,项目名称:CloudStack,代码行数:14,代码来源:scsiutil.py


示例19: print_LUNs

 def print_LUNs(self):
     self.LUNs = {}
     if os.path.exists(self.path):
         dom0_disks = util.dom0_disks()
         for file in util.listdir(self.path):
             if file.find("LUN") != -1 and file.find("_") == -1:
                 vdi_path = os.path.join(self.path,file)
                 if os.path.realpath(vdi_path) in dom0_disks:
                     util.SMlog("Hide dom0 boot disk LUN")
                 else:
                     LUNid = file.replace("LUN","")
                     obj = self.vdi(self.uuid)
                     obj._query(vdi_path, LUNid)
                     self.LUNs[obj.uuid] = obj
开发者ID:MarkSymsCtx,项目名称:sm,代码行数:14,代码来源:BaseISCSI.py


示例20: _loadvdis

 def _loadvdis(self):
     count = 0
     if not os.path.exists(self.path):
         return 0
     for file in filter(self.match_lun, util.listdir(self.path)):
         vdi_path = os.path.join(self.path,file)
         LUNid = file.replace("LUN","")
         uuid = scsiutil.gen_uuid_from_string(scsiutil.getuniqueserial(vdi_path))
         obj = self.vdi(uuid)
         obj._query(vdi_path, LUNid)
         self.vdis[uuid] = obj
         self.physical_size += obj.size
         count += 1
     return count
开发者ID:JohnGarbutt,项目名称:xcp-storage-managers,代码行数:14,代码来源:ISCSISR.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python util.load函数代码示例发布时间:2022-05-26
下一篇:
Python util.launchCommand函数代码示例发布时间: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