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


Python DefaultStorage.listdir方法代码示例

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


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

示例1: get_dirnames

# 需要导入模块: from django.core.files.storage import DefaultStorage [as 别名]
# 或者: from django.core.files.storage.DefaultStorage import listdir [as 别名]
def get_dirnames(path):
    """ Get all directory names in path as list of strings
            
    Raises: OSError if directory can not be found
    """
    storage = DefaultStorage()
    dirnames = storage.listdir(path)[0]
    dirnames.sort()
    return dirnames
开发者ID:comic,项目名称:comic-django,代码行数:11,代码来源:views.py

示例2: cleanup_screenshot_files

# 需要导入模块: from django.core.files.storage import DefaultStorage [as 别名]
# 或者: from django.core.files.storage.DefaultStorage import listdir [as 别名]
def cleanup_screenshot_files():
    """Remove stale screenshots"""
    storage = DefaultStorage()
    try:
        files = storage.listdir('screenshots')[1]
    except OSError:
        return
    for name in files:
        fullname = os.path.join('screenshots', name)
        if not Screenshot.objects.filter(image=fullname).exists():
            storage.delete(fullname)
开发者ID:nijel,项目名称:weblate,代码行数:13,代码来源:tasks.py

示例3: render

# 需要导入模块: from django.core.files.storage import DefaultStorage [as 别名]
# 或者: from django.core.files.storage.DefaultStorage import listdir [as 别名]
    def render(self, context):
        challenge: Challenge = context["currentpage"].challenge

        try:
            projectpath = safe_join(
                challenge.get_project_data_folder(), self.path
            )
        except SuspiciousFileOperation:
            return self.make_dataset_error_msg(
                "path is outside the challenge folder."
            )

        storage = DefaultStorage()
        try:
            filenames = storage.listdir(projectpath)[1]
        except OSError as e:
            return self.make_dataset_error_msg(str(e))

        filenames.sort()
        # if extensionsFilter is given,  show only filenames with those extensions
        if "extensionFilter" in self.args.keys():
            extensions = self.args["extensionFilter"].split(",")
            filenames = filter_by_extension(filenames, extensions)
        links = []
        for filename in filenames:
            downloadlink = reverse(
                "root-serving:challenge-file",
                kwargs={
                    "challenge_name": challenge.short_name,
                    "path": f"{self.path}/{filename}",
                },
            )
            links.append(
                '<li><a href="' + downloadlink + '">' + filename + " </a></li>"
            )
        htmlOut = '<ul class="dataset">' + "".join(links) + "</ul>"
        return htmlOut
开发者ID:comic,项目名称:comic-django,代码行数:39,代码来源:grandchallenge_tags.py


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