Skip to content

Commit 435d649

Browse files
committed
Added a management command: 'check_person_names_and_aliases'.
When we started explicitly listing draft and RFC author names on the documemnt pages in commit [18549], it uncovered a number of links that 404'ed because name alias entries were missing for some person entries, in particular for authors of early RFCs and drafts. Adding such alias entries can be done automatically in most cases. This new management command will do so, and also report (and in some cases fix) additional issues, such as names incorrectly incorporating '<>', name aliases that are email addresses, and more. Run with -v2 (verbosity 2) it will report all found names and aliases for each issue type, and run with -f it will fix those that can be automatically fixed. - Legacy-Id: 18599 Note: SVN reference [18549] has been migrated to Git commit 2899c2a
1 parent 112cb62 commit 435d649

1 file changed

Lines changed: 98 additions & 0 deletions

File tree

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Copyright The IETF Trust 2018-2020, All Rights Reserved
2+
# -*- coding: utf-8 -*-
3+
4+
5+
from tqdm import tqdm
6+
7+
from django.core.management.base import BaseCommand
8+
9+
import debug # pyflakes:ignore
10+
11+
from ietf.person.models import Person, Alias
12+
13+
14+
class Command(BaseCommand):
15+
help = ("""
16+
Check for missing Alias records, and create missing record if requested.
17+
Check for certain bad Alias records, and fix if requested.
18+
Check for certain bad strings in Person names and fix if requested.
19+
""")
20+
21+
def add_arguments(self, parser):
22+
parser.add_argument('-f', '--fix', action='store_true', default=False,
23+
help="Create missing aliases")
24+
25+
def handle(self, *args, **options):
26+
verbosity = options['verbosity']
27+
fix = options['fix']
28+
system_names = ['(System)', 'IAB', 'IANA', ]
29+
missing = []
30+
badalias = []
31+
badname = []
32+
onename = []
33+
addrname = []
34+
for person in tqdm(Person.objects.all()):
35+
email = person.email()
36+
# Person names with junk
37+
if '<>' in person.name:
38+
name = person.name
39+
if fix:
40+
person.name = name.replace('<>', '').strip()
41+
person.save()
42+
badname.append((name, person.name, email))
43+
if '@' in person.name:
44+
# Can't fix this here, needs human intervention
45+
addrname.append((person.name, '-', email))
46+
#
47+
alias_names = { n for n in [ person.name, person.ascii, person.plain_name(), person.plain_ascii(), ] if n and (' ' in n and not '@' in n) }
48+
aliases = Alias.objects.filter(name__in=alias_names, person=person)
49+
# Aliases that look like email addresses
50+
for alias in aliases:
51+
if '@' in alias.name:
52+
name = alias.name
53+
aliases = aliases.exclude(pk=alias.pk)
54+
if fix:
55+
alias.delete()
56+
badalias.append((name, '-', email))
57+
# Missing aliases
58+
if aliases.count() < len(alias_names):
59+
for name in alias_names - { a.name for a in aliases }:
60+
if fix:
61+
Alias.objects.create(person=person, name=name)
62+
missing.append((name, person.name, email))
63+
if not ' ' in person.name and not person.name in system_names:
64+
name = person.name
65+
# Names using Chinese ideographs don't necessary have spaces
66+
if (all( 0x4E00 <= ord(c) <= 0x9FFF for c in name) or # Han
67+
all( 0xAC00 <= ord(c) <= 0xD7AF for c in name) ): # HanGul
68+
pass
69+
else:
70+
onename.append((name, '-', email))
71+
72+
action = "Fixed" if fix else "Found"
73+
#
74+
print("\n %s %d bad names." % (action, len(badname)))
75+
if verbosity > 1:
76+
for n in badname:
77+
print(n)
78+
print("\n %s %d missing aliases." % (action, len(missing)))
79+
if verbosity > 1:
80+
for n in missing:
81+
print(n)
82+
print("\n %s %d bad aliases." % (action, len(badalias)))
83+
if verbosity > 1:
84+
for n in badalias:
85+
print(n)
86+
print("\n Found %d names that could be email addresses." % (len(addrname)))
87+
if verbosity > 1:
88+
for n in addrname:
89+
print(n)
90+
else:
91+
print(" Use -v2 to list them.")
92+
print("\n Found %d single-word names (names with no space)." % (len(onename), ))
93+
if verbosity > 1:
94+
for n in onename:
95+
print(n)
96+
else:
97+
print(" Use -v2 to list them.")
98+

0 commit comments

Comments
 (0)