sync-cards.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:dixit-online 作者: jminuscula 项目源码 文件源码
def handle(self, *args, **options):
        path = options.get('path') or settings.CARD_IMAGES_PATH
        path = os.path.realpath(path)

        if not os.path.exists(path):
            raise CommandError('Image path does not exist')

        def check_extension(f):
            f = f.lower()
            return f[f.rfind('.'):] in SUPPORTED_FORMATS

        for *_, files in os.walk(path):
            available = set(filter(check_extension, files))
            registered = {c.path for c in Card.objects.all()}

            Card.objects.exclude(path__in=available).delete()
            for path in available.difference(registered):
                Card(path=path).save()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号