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


Python dircache.listdir方法代码示例

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


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

示例1: get_all_lexicons_from_directory

# 需要导入模块: import dircache [as 别名]
# 或者: from dircache import listdir [as 别名]
def get_all_lexicons_from_directory(self):
        """ Getting list of lexicon file names from chosen directory, directory can be set up in init.

        Returns
        ----------
            List of lexicon files paths.
        """
        return listdir(self.lexicons_path) 
开发者ID:laugustyniak,项目名称:textlytics,代码行数:10,代码来源:lexicons.py

示例2: purgeEmptyDirs

# 需要导入模块: import dircache [as 别名]
# 或者: from dircache import listdir [as 别名]
def purgeEmptyDirs(path):
        """ locate and remove empty lingering dirs """

        all_dirs = glob("%s/Panda_Pilot_*" % (path))
        max_dirs = 50
        purged_nr = 0
        dir_nr = 0

        for _dir in all_dirs:
            if dir_nr >= max_dirs:
                break
            # when was the dir last modified?
            current_time = int(time.time())
            try:
                file_modification_time = os.path.getmtime(_dir)
            except:
                # skip this dir since it was not possible to read the modification time
                pass
            else:
                mod_time = current_time - file_modification_time
                if mod_time > 12*3600:
                    try:
                        ls = listdir(_dir)
                    except Exception, e:
                        tolog("!!WARNING!!2999!! Exception caught: %s" % str(e))
                    else:
                        if len(ls) == 0 or len(ls) == 1:
                            if len(ls) == 0:
                                tolog("Found empty dir: %s (last modified %d s ago, will now purge it)" % (_dir, mod_time))
                            else:
                                tolog("Found empty dir: %s (last modified %d s ago, will now purge it, 1 sub dir: %s)" % (_dir, mod_time, ls[0]))

                            ec, rs = commands.getstatusoutput("rm -rf %s" % (_dir))
                            if ec != 0:
                                tolog("Failed to remove dir: %d, %s (belonging to user %d, pilot is run by user %d)" %\
                                      (ec, rs, os.stat(_dir)[4], os.getuid()))
                            else:
                                purged_nr += 1
            dir_nr += 1 
开发者ID:PanDAWMS,项目名称:pilot,代码行数:41,代码来源:Cleaner.py

示例3: purgeWorkDirs

# 需要导入模块: import dircache [as 别名]
# 或者: from dircache import listdir [as 别名]
def purgeWorkDirs(path):
        """ locate and remove lingering athena workDirs """

        all_dirs = glob("%s/Panda_Pilot_*/PandaJob*" % (path))
        max_dirs = 50
        purged_nr = 0
        dir_nr = 0

        for _dir in all_dirs:
            if dir_nr >= max_dirs:
                break
            # when was the dir last modified?
            current_time = int(time.time())
            try:
                file_modification_time = os.path.getmtime(_dir)
            except:
                # skip this dir since it was not possible to read the modification time
                pass
            else:
                mod_time = current_time - file_modification_time
                if mod_time > 12*3600:
                    try:
                        ls = listdir(_dir)
                    except Exception, e:
                        tolog("!!WARNING!!2999!! Exception caught: %s" % str(e))
                    else:
                        if len(ls) == 1:
                            if "workDir" in ls:
                                ec, rs = commands.getstatusoutput("ls -lF %s" % (_dir))
                                tolog("ls: %s" % str(rs))
                                tolog("Found single workDir: %s (will now purge it)" % (_dir))
                                ec, rs = commands.getstatusoutput("rm -rf %s" % (_dir))
                                if ec != 0:
                                    tolog("Failed to remove dir: %s" % (rs))
                                else:
                                    purged_nr += 1
            dir_nr += 1 
开发者ID:PanDAWMS,项目名称:pilot,代码行数:39,代码来源:Cleaner.py

示例4: purgeMaxedoutDirs

# 需要导入模块: import dircache [as 别名]
# 或者: from dircache import listdir [as 别名]
def purgeMaxedoutDirs(path):
        """ locate and remove maxedout lingering dirs """

        all_dirs = glob("%s/Panda_Pilot_*" % (path))
        max_dirs = 50
        purged_nr = 0
        dir_nr = 0

        for _dir in all_dirs:
            if dir_nr >= max_dirs:
                break
            # when was the dir last modified?
            current_time = int(time.time())
            try:
                file_modification_time = os.path.getmtime(_dir)
            except:
                # skip this dir since it was not possible to read the modification time
                pass
            else:
                mod_time = current_time - file_modification_time
                if mod_time > 12*3600:
                    try:
                        ls = listdir(_dir)
                    except Exception, e:
                        tolog("!!WARNING!!2999!! Exception caught: %s" % str(e))
                    else:
                        if len(ls) > 0:
                            purge = False
                            for f in ls:
                                if ".MAXEDOUT" in f:
                                    tolog("Found MAXEDOUT job state file: %s (will now purge the work dir: %s)" % (f, _dir))
                                    purge = True
                                    break
                            if purge:
                                ec, rs = commands.getstatusoutput("rm -rf %s" % (_dir))
                                if ec != 0:
                                    tolog("Failed to remove dir: %d, (belonging to user %d, pilot is run by user %d)" %\
                                          (ec, os.stat(_dir)[4], os.getuid()))
                                else:
                                    purged_nr += 1
            dir_nr += 1 
开发者ID:PanDAWMS,项目名称:pilot,代码行数:43,代码来源:Cleaner.py

示例5: tearDown

# 需要导入模块: import dircache [as 别名]
# 或者: from dircache import listdir [as 别名]
def tearDown(self):
        for fname in os.listdir(self.tempdir):
            self.delTemp(fname)
        os.rmdir(self.tempdir) 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:6,代码来源:test_dircache.py

示例6: test_listdir

# 需要导入模块: import dircache [as 别名]
# 或者: from dircache import listdir [as 别名]
def test_listdir(self):
        ## SUCCESSFUL CASES
        entries = dircache.listdir(self.tempdir)
        self.assertEquals(entries, [])

        # Check that cache is actually caching, not just passing through.
        self.assert_(dircache.listdir(self.tempdir) is entries)

        # Directories aren't "files" on Windows, and directory mtime has
        # nothing to do with when files under a directory get created.
        # That is, this test can't possibly work under Windows -- dircache
        # is only good for capturing a one-shot snapshot there.

        if (sys.platform[:3] not in ('win', 'os2') and
            (not is_jython or os._name != 'nt')):
            # Sadly, dircache has the same granularity as stat.mtime, and so
            # can't notice any changes that occurred within 1 sec of the last
            # time it examined a directory.
            time.sleep(1)
            self.writeTemp("test1")
            entries = dircache.listdir(self.tempdir)
            self.assertEquals(entries, ['test1'])
            self.assert_(dircache.listdir(self.tempdir) is entries)

        ## UNSUCCESSFUL CASES
        self.assertRaises(OSError, dircache.listdir, self.tempdir+"_nonexistent") 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:28,代码来源:test_dircache.py

示例7: test_nilsimsa

# 需要导入模块: import dircache [as 别名]
# 或者: from dircache import listdir [as 别名]
def test_nilsimsa():
    """
    tests the nilsimsa hash by choosing a random test file
    computes the nilsimsa digest and compares to the true
    value stored in the pickled sid_to_nil dictionary
    """
    fname = random.choice(listdir(test_data_dir))
    f = open(os.path.join(test_data_dir, fname), "rb")
    nil = Nilsimsa(f.read())
    f.close()
    assert nil.hexdigest() == sid_to_nil[fname.split(".")[0]] 
开发者ID:diffeo,项目名称:py-nilsimsa,代码行数:13,代码来源:test.py

示例8: test_nilsimsa_speed

# 需要导入模块: import dircache [as 别名]
# 或者: from dircache import listdir [as 别名]
def test_nilsimsa_speed():
    """
    computes nilsimsa hash for all test files and prints speed
    """
    corpus = []
    for fname in listdir(test_data_dir):
        f = open(os.path.join(test_data_dir, fname), "rb")
        corpus.append(f.read())
        f.close()
    start = time.time()
    for text in corpus:
        Nilsimsa(text)
    elapsed = time.time() - start
    print("%d in %f --> %f per second" % (
        len(corpus), elapsed, len(corpus)/elapsed)) 
开发者ID:diffeo,项目名称:py-nilsimsa,代码行数:17,代码来源:test.py

示例9: test_compatability

# 需要导入模块: import dircache [as 别名]
# 或者: from dircache import listdir [as 别名]
def test_compatability():
    """
    testing compat with deprecated version by comparing nilsimsa
    scores of 5 randomly selected documents from the test corpus
    and asserting that both give the same hexdigest
    """
    names = listdir(test_data_dir)
    fnames = set([random.choice(names) for i in range(5)])
    for fname in fnames:
        f = open(os.path.join(test_data_dir, fname), "rb")
        text = f.read()
        f.close()
        if not(Nilsimsa(text).hexdigest() == orig_Nilsimsa(text).hexdigest()):
            assert False
    assert True 
开发者ID:diffeo,项目名称:py-nilsimsa,代码行数:17,代码来源:test.py

示例10: glob

# 需要导入模块: import dircache [as 别名]
# 或者: from dircache import listdir [as 别名]
def glob(dir_path,
         includes = '**/*',
         excludes = default_excludes,
         entry_type = FILE,
         prune_dirs = prune_dirs,
         max_depth = 25):
    include_filter = [ant_pattern_to_re(p) for p in _as_list(includes)]
    exclude_filter = [ant_pattern_to_re(p) for p in _as_list(excludes)]
    prune_dirs = [p.replace('/',os.path.sep) for p in _as_list(prune_dirs)]
    dir_path = dir_path.replace('/',os.path.sep)
    entry_type_filter = entry_type

    def is_pruned_dir(dir_name):
        for pattern in prune_dirs:
            if fnmatch.fnmatch(dir_name, pattern):
                return True
        return False

    def apply_filter(full_path, filter_rexs):
        """Return True if at least one of the filter regular expression match full_path."""
        for rex in filter_rexs:
            if rex.match(full_path):
                return True
        return False

    def glob_impl(root_dir_path):
        child_dirs = [root_dir_path]
        while child_dirs:
            dir_path = child_dirs.pop()
            for entry in listdir(dir_path):
                full_path = os.path.join(dir_path, entry)
##                print 'Testing:', full_path,
                is_dir = os.path.isdir(full_path)
                if is_dir and not is_pruned_dir(entry): # explore child directory ?
##                    print '===> marked for recursion',
                    child_dirs.append(full_path)
                included = apply_filter(full_path, include_filter)
                rejected = apply_filter(full_path, exclude_filter)
                if not included or rejected: # do not include entry ?
##                    print '=> not included or rejected'
                    continue
                link = os.path.islink(full_path)
                is_file = os.path.isfile(full_path)
                if not is_file and not is_dir:
##                    print '=> unknown entry type'
                    continue
                if link:
                    entry_type = is_file and FILE_LINK or DIR_LINK
                else:
                    entry_type = is_file and FILE or DIR
##                print '=> type: %d' % entry_type, 
                if (entry_type & entry_type_filter) != 0:
##                    print ' => KEEP'
                    yield os.path.join(dir_path, entry)
##                else:
##                    print ' => TYPE REJECTED'
    return list(glob_impl(dir_path)) 
开发者ID:KhronosGroup,项目名称:OpenXR-SDK-Source,代码行数:59,代码来源:antglob.py


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