Machina preview.
[wolnelektury.git] / src / search / management / commands / snippets.py
1 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
3 #
4 from glob import glob
5 from os import path
6 from django.conf import settings
7 from django.core.management.base import BaseCommand
8
9
10 class Command(BaseCommand):
11     help = 'Check snippets.'
12
13     def handle(self, *args, **opts):
14         sfn = glob(settings.SEARCH_INDEX+'snippets/*')
15         for fn in sfn:
16             print(fn)
17             bkid = path.basename(fn)
18             with open(fn) as f:
19                 cont = f.read()
20                 try:
21                     cont.decode('utf-8')
22                 except UnicodeDecodeError:
23                     print("error in snippets %s" % bkid)