fnp
/
wolnelektury.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add chunk under forms.
[wolnelektury.git]
/
src
/
catalogue
/
management
/
commands
/
checkcovers.py
diff --git
a/src/catalogue/management/commands/checkcovers.py
b/src/catalogue/management/commands/checkcovers.py
index
2466728
..
db9fc4c
100644
(file)
--- a/
src/catalogue/management/commands/checkcovers.py
+++ b/
src/catalogue/management/commands/checkcovers.py
@@
-1,18
+1,16
@@
-# -*- coding: utf-8 -*-
# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
-from optparse import make_option
from django.contrib.sites.models import Site
from django.core.management.base import BaseCommand
from django.contrib.sites.models import Site
from django.core.management.base import BaseCommand
-from catalogue import app_settings
from django.utils.functional import lazy
from django.utils.functional import lazy
+from catalogue import app_settings
def ancestor_has_cover(book):
while book.parent:
book = book.parent
def ancestor_has_cover(book):
while book.parent:
book = book.parent
- if book.
extra_info
.get('cover_url'):
+ if book.
get_extra_info_json()
.get('cover_url'):
return True
return False
return True
return False
@@
-27,12
+25,13
@@
def full_url(obj):
class Command(BaseCommand):
class Command(BaseCommand):
- option_list = BaseCommand.option_list + (
- make_option('-q', '--quiet', action='store_false', dest='verbose', default=True,
- help='Suppress output'),
- )
help = 'Checks cover sources and licenses.'
help = 'Checks cover sources and licenses.'
+ def add_arguments(self, parser):
+ parser.add_argument(
+ '-q', '--quiet', action='store_false', dest='verbose',
+ default=True, help='Suppress output')
+
def handle(self, **options):
from collections import defaultdict
import re
def handle(self, **options):
from collections import defaultdict
import re
@@
-47,7
+46,7
@@
class Command(BaseCommand):
bad_license = defaultdict(list)
no_license = []
bad_license = defaultdict(list)
no_license = []
- re_license = re.compile(
u
r'.*,\s*(CC.*)')
+ re_license = re.compile(r'.*,\s*(CC.*)')
redakcja_url = app_settings.REDAKCJA_URL
good_license = re.compile("(%s)" % ")|(".join(
redakcja_url = app_settings.REDAKCJA_URL
good_license = re.compile("(%s)" % ")|(".join(
@@
-55,7
+54,7
@@
class Command(BaseCommand):
with transaction.atomic():
for book in Book.objects.all().order_by('slug').iterator():
with transaction.atomic():
for book in Book.objects.all().order_by('slug').iterator():
- extra_info = book.
extra_info
+ extra_info = book.
get_extra_info_json()
if not extra_info.get('cover_url'):
if ancestor_has_cover(book):
with_ancestral_cover.append(book)
if not extra_info.get('cover_url'):
if ancestor_has_cover(book):
with_ancestral_cover.append(book)
@@
-71,7
+70,7
@@
class Command(BaseCommand):
else:
no_license.append(book)
else:
no_license.append(book)
- print
"""%d books with no covers, %d with inherited covers.
+ print
(
"""%d books with no covers, %d with inherited covers.
Bad licenses used: %s (%d covers without license).
%d covers not from %s.
""" % (
Bad licenses used: %s (%d covers without license).
%d covers not from %s.
""" % (
@@
-81,51
+80,53
@@
Bad licenses used: %s (%d covers without license).
len(no_license),
len(not_redakcja),
redakcja_url,
len(no_license),
len(not_redakcja),
redakcja_url,
- )
+ )
)
if verbose:
if bad_license:
if verbose:
if bad_license:
- print
- print
"Bad license:"
- print
"============"
+ print
()
+ print
("Bad license:")
+ print
("============")
for lic, books in bad_license.items():
for lic, books in bad_license.items():
- print
- print
lic
+ print
()
+ print
(lic)
for book in books:
for book in books:
- print
full_url(book
)
+ print
(full_url(book)
)
if no_license:
if no_license:
- print
- print
"No license:"
- print
"==========="
+ print
()
+ print
("No license:")
+ print
("===========")
for book in no_license:
for book in no_license:
- print
- print full_url(book)
- print book.extra_info.get('cover_by')
- print book.extra_info.get('cover_source')
- print book.extra_info.get('cover_url')
+ print()
+ print(full_url(book))
+ extra_info = book.get_extra_info_json()
+ print(extra_info.get('cover_by'))
+ print(extra_info.get('cover_source'))
+ print(extra_info.get('cover_url'))
if not_redakcja:
if not_redakcja:
- print
- print
"Not from Redakcja or source missing:"
- print
"===================================="
+ print
()
+ print
("Not from Redakcja or source missing:")
+ print
("====================================")
for book in not_redakcja:
for book in not_redakcja:
- print
- print full_url(book)
- print book.extra_info.get('cover_by')
- print book.extra_info.get('cover_source')
- print book.extra_info.get('cover_url')
+ print()
+ print(full_url(book))
+ extra_info = book.get_extra_info_json()
+ print(extra_info.get('cover_by'))
+ print(extra_info.get('cover_source'))
+ print(extra_info.get('cover_url'))
if without_cover:
if without_cover:
- print
- print
"No cover:"
- print
"========="
+ print
()
+ print
("No cover:")
+ print
("=========")
for book in without_cover:
for book in without_cover:
- print
full_url(book
)
+ print
(full_url(book)
)
if with_ancestral_cover:
if with_ancestral_cover:
- print
- print
"With ancestral cover:"
- print
"====================="
+ print
()
+ print
("With ancestral cover:")
+ print
("=====================")
for book in with_ancestral_cover:
for book in with_ancestral_cover:
- print
full_url(book
)
+ print
(full_url(book)
)