Skip to content

Commit ba3010e

Browse files
committed
Added fetch and use of the RFC-Editor's errata.json file in order to set a new 'verified-errata' document tag, and use that to show the link to inline-errata documents only when there is verified errata. Fixes issue ietf-tools#2861.
- Legacy-Id: 17212
1 parent a3edd91 commit ba3010e

8 files changed

Lines changed: 112 additions & 29 deletions

File tree

bin/check-copyright

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ COPYRIGHT
3535
"""
3636
from __future__ import print_function
3737

38+
import datetime
3839
import os
3940
import sys
4041
import time
@@ -150,15 +151,18 @@ def get_first_commit(path):
150151
cmd = 'svn log %s' % path
151152
if opt_verbose > 1:
152153
note("Running '%s' ..." % cmd)
153-
commit_log = pipe(cmd)
154-
commit_log = commit_log.splitlines()
155-
commit_log.reverse()
156-
for line in commit_log:
157-
if re.search(loginfo_format, line):
158-
rev, who, when = split_loginfo(line)
159-
break
160-
else:
161-
pass
154+
try:
155+
commit_log = pipe(cmd)
156+
commit_log = commit_log.splitlines()
157+
commit_log.reverse()
158+
for line in commit_log:
159+
if re.search(loginfo_format, line):
160+
rev, who, when = split_loginfo(line)
161+
break
162+
else:
163+
pass
164+
except OSError:
165+
rev, who, when = None, None, datetime.datetime.now()
162166
return { path: { 'rev': rev, 'who': who, 'date': when.strftime('%Y-%m-%d %H:%M:%S'), }, }
163167

164168

ietf/bin/rfc-editor-index-updates

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
#!/usr/bin/env python
22

3-
import os, sys, datetime
3+
import datetime
4+
import json
5+
import os
6+
import sys
47
import traceback
58

9+
from six.moves.urllib.request import urlopen
10+
611
# boilerplate
712
basedir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../.."))
813
sys.path = [ basedir ] + sys.path
@@ -38,15 +43,22 @@ if options.skip_date:
3843

3944
log("Updating document metadata from RFC index from %s" % settings.RFC_EDITOR_INDEX_URL)
4045

41-
response = ietf.sync.rfceditor.fetch_index_xml(settings.RFC_EDITOR_INDEX_URL)
42-
data = ietf.sync.rfceditor.parse_index(response)
46+
rfc_index_xml = ietf.sync.rfceditor.fetch_index_xml(settings.RFC_EDITOR_INDEX_URL)
47+
index_data = ietf.sync.rfceditor.parse_index(rfc_index_xml)
48+
49+
rfc_errata_json = urlopen(settings.RFC_EDITOR_ERRATA_JSON_URL)
50+
errata_data = json.load(rfc_errata_json)
51+
52+
if len(index_data) < ietf.sync.rfceditor.MIN_INDEX_RESULTS:
53+
log("Not enough index entries, only %s" % len(index_data))
54+
sys.exit(1)
4355

44-
if len(data) < ietf.sync.rfceditor.MIN_INDEX_RESULTS:
45-
log("Not enough results, only %s" % len(data))
56+
if len(errata_data) < ietf.sync.rfceditor.MIN_ERRATA_RESULTS:
57+
log("Not enough errata entries, only %s" % len(errata_data))
4658
sys.exit(1)
4759

4860
new_rfcs = []
49-
for changes, doc, rfc_published in ietf.sync.rfceditor.update_docs_from_rfc_index(data, skip_older_than_date=skip_date):
61+
for changes, doc, rfc_published in ietf.sync.rfceditor.update_docs_from_rfc_index(index_data, errata_data, skip_older_than_date=skip_date):
5062
if rfc_published:
5163
new_rfcs.append(doc)
5264

ietf/doc/views_doc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def document_main(request, name, rev=None):
229229

230230
if "txt" in found_types:
231231
file_urls.append(("htmlized", settings.TOOLS_ID_HTML_URL + name))
232-
if doc.tags.filter(slug="errata"):
232+
if doc.tags.filter(slug="verified-errata").exists():
233233
file_urls.append(("with errata", settings.RFC_EDITOR_INLINE_ERRATA_URL.format(rfc_number=rfc_number)))
234234

235235
if not found_types:

ietf/name/fixtures/names.json

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9100,6 +9100,16 @@
91009100
"model": "name.doctagname",
91019101
"pk": "sheph-u"
91029102
},
9103+
{
9104+
"fields": {
9105+
"desc": "",
9106+
"name": "Has verified errata",
9107+
"order": 0,
9108+
"used": true
9109+
},
9110+
"model": "name.doctagname",
9111+
"pk": "verified-errata"
9112+
},
91039113
{
91049114
"fields": {
91059115
"desc": "",
@@ -14216,7 +14226,7 @@
1421614226
"fields": {
1421714227
"command": "xym",
1421814228
"switch": "--version",
14219-
"time": "2019-12-18T00:13:51.087",
14229+
"time": "2020-01-09T00:13:22.771",
1422014230
"used": true,
1422114231
"version": "xym 0.4"
1422214232
},
@@ -14227,7 +14237,7 @@
1422714237
"fields": {
1422814238
"command": "pyang",
1422914239
"switch": "--version",
14230-
"time": "2019-12-18T00:13:52.218",
14240+
"time": "2020-01-09T00:13:23.631",
1423114241
"used": true,
1423214242
"version": "pyang 2.1"
1423314243
},
@@ -14238,7 +14248,7 @@
1423814248
"fields": {
1423914249
"command": "yanglint",
1424014250
"switch": "--version",
14241-
"time": "2019-12-18T00:13:52.367",
14251+
"time": "2020-01-09T00:13:23.912",
1424214252
"used": true,
1424314253
"version": "yanglint 0.14.80"
1424414254
},
@@ -14249,9 +14259,9 @@
1424914259
"fields": {
1425014260
"command": "xml2rfc",
1425114261
"switch": "--version",
14252-
"time": "2019-12-18T00:13:53.390",
14262+
"time": "2020-01-09T00:13:24.917",
1425314263
"used": true,
14254-
"version": "xml2rfc 2.36.0"
14264+
"version": "xml2rfc 2.37.2"
1425514265
},
1425614266
"model": "utils.versioninfo",
1425714267
"pk": 4
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright The IETF Trust 2020, All Rights Reserved
2+
# -*- coding: utf-8 -*-
3+
4+
from __future__ import absolute_import, print_function, unicode_literals
5+
6+
from django.db import migrations
7+
8+
def forward(apps, schema_editor):
9+
DocTagName = apps.get_model('name','DocTagName')
10+
DocTagName.objects.get_or_create(slug='verified-errata', name='Has verified errata', desc='', used=True, order=0)
11+
12+
def reverse(apps, schema_editor):
13+
DocTagName = apps.get_model('name','DocTagName')
14+
DocTagName.objects.filter(slug='verified-errata').delete()
15+
16+
class Migration(migrations.Migration):
17+
18+
dependencies = [
19+
('name', '0008_reviewerqueuepolicyname'),
20+
]
21+
22+
operations = [
23+
migrations.RunPython(forward, reverse)
24+
]

ietf/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,7 @@ def skip_unreadable_post(record):
734734
#RFC_EDITOR_GROUP_NOTIFICATION_URL = "https://www.rfc-editor.org/notification/group.php"
735735
RFC_EDITOR_QUEUE_URL = "https://www.rfc-editor.org/queue2.xml"
736736
RFC_EDITOR_INDEX_URL = "https://www.rfc-editor.org/rfc/rfc-index.xml"
737+
RFC_EDITOR_ERRATA_JSON_URL = "https://www.rfc-editor.org/errata.json"
737738
RFC_EDITOR_ERRATA_URL = "https://www.rfc-editor.org/errata_search.php?rfc={rfc_number}&amp;rec_status=0"
738739
RFC_EDITOR_INLINE_ERRATA_URL = "https://www.rfc-editor.org/rfc/inline-errata/rfc{rfc_number}.html"
739740

ietf/sync/rfceditor.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright The IETF Trust 2012-2019, All Rights Reserved
1+
# Copyright The IETF Trust 2012-2020, All Rights Reserved
22
# -*- coding: utf-8 -*-
33

44

@@ -32,8 +32,9 @@
3232
#INDEX_URL = "https://www.rfc-editor.org/rfc/rfc-index.xml"
3333
#POST_APPROVED_DRAFT_URL = "https://www.rfc-editor.org/sdev/jsonexp/jsonparser.php"
3434

35+
MIN_ERRATA_RESULTS = 5000
36+
MIN_INDEX_RESULTS = 8000
3537
MIN_QUEUE_RESULTS = 10
36-
MIN_INDEX_RESULTS = 5000
3738

3839
def get_child_text(parent_node, tag_name):
3940
text = []
@@ -330,11 +331,18 @@ def extract_doc_list(parentNode, tagName):
330331
return data
331332

332333

333-
def update_docs_from_rfc_index(data, skip_older_than_date=None):
334+
def update_docs_from_rfc_index(index_data, errata_data, skip_older_than_date=None):
334335
"""Given parsed data from the RFC Editor index, update the documents
335336
in the database. Yields a list of change descriptions for each
336337
document, if any."""
337338

339+
errata = {}
340+
for item in errata_data:
341+
name = item['doc-id']
342+
if not name in errata:
343+
errata[name] = []
344+
errata[name].append(item)
345+
338346
std_level_mapping = {
339347
"Standard": StdLevelName.objects.get(slug="std"),
340348
"Internet Standard": StdLevelName.objects.get(slug="std"),
@@ -356,12 +364,13 @@ def update_docs_from_rfc_index(data, skip_older_than_date=None):
356364
}
357365

358366
tag_has_errata = DocTagName.objects.get(slug='errata')
367+
tag_has_verified_errata = DocTagName.objects.get(slug='verified-errata')
359368
relationship_obsoletes = DocRelationshipName.objects.get(slug="obs")
360369
relationship_updates = DocRelationshipName.objects.get(slug="updates")
361370

362371
system = Person.objects.get(name="(System)")
363372

364-
for rfc_number, title, authors, rfc_published_date, current_status, updates, updated_by, obsoletes, obsoleted_by, also, draft, has_errata, stream, wg, file_formats, pages, abstract in data:
373+
for rfc_number, title, authors, rfc_published_date, current_status, updates, updated_by, obsoletes, obsoleted_by, also, draft, has_errata, stream, wg, file_formats, pages, abstract in index_data:
365374

366375
if skip_older_than_date and rfc_published_date < skip_older_than_date:
367376
# speed up the process by skipping old entries
@@ -493,13 +502,20 @@ def parse_relation_list(l):
493502
changes.append("created alias %s" % prettify_std_name(a))
494503

495504
if has_errata:
496-
if not doc.tags.filter(pk=tag_has_errata.pk):
505+
if not doc.tags.filter(pk=tag_has_errata.pk).exists():
497506
doc.tags.add(tag_has_errata)
498507
changes.append("added Errata tag")
508+
has_verified_errata = name.upper() in errata and any([ e['errata_status_code']=='Verified' for e in errata[name.upper()] ])
509+
if has_verified_errata and not doc.tags.filter(pk=tag_has_verified_errata.pk).exists():
510+
doc.tags.add(tag_has_verified_errata)
511+
changes.append("added Verified Errata tag")
499512
else:
500513
if doc.tags.filter(pk=tag_has_errata.pk):
501514
doc.tags.remove(tag_has_errata)
502515
changes.append("removed Errata tag")
516+
if doc.tags.filter(pk=tag_has_verified_errata.pk):
517+
doc.tags.remove(tag_has_verified_errata)
518+
changes.append("removed Verified Errata tag")
503519

504520
if changes:
505521
events.append(DocEvent.objects.create(

ietf/sync/tests.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright The IETF Trust 2012-2019, All Rights Reserved
1+
# Copyright The IETF Trust 2012-2020, All Rights Reserved
22
# -*- coding: utf-8 -*-
33

44

@@ -315,6 +315,22 @@ def test_rfc_index(self):
315315
area=doc.group.parent.acronym,
316316
group=doc.group.acronym)
317317

318+
errata = [{
319+
"errata_id":1,
320+
"doc-id":"RFC123",
321+
"errata_status_code":"Verified",
322+
"errata_type_code":"Editorial",
323+
"section": "4.1",
324+
"orig_text":" S: 220-smtp.example.com ESMTP Server",
325+
"correct_text":" S: 220 smtp.example.com ESMTP Server",
326+
"notes":"There are 3 instances of this (one on p. 7 and two on p. 8). \n",
327+
"submit_date":"2007-07-19",
328+
"submitter_name":"Rob Siemborski",
329+
"verifier_id":99,
330+
"verifier_name":None,
331+
"update_date":"2019-09-10 09:09:03"},
332+
]
333+
318334
data = rfceditor.parse_index(io.StringIO(t))
319335
self.assertEqual(len(data), 1)
320336

@@ -339,7 +355,7 @@ def test_rfc_index(self):
339355
self.write_draft_file(draft_filename, 5000)
340356

341357
changes = []
342-
for cs, d, rfc_published in rfceditor.update_docs_from_rfc_index(data, today - datetime.timedelta(days=30)):
358+
for cs, d, rfc_published in rfceditor.update_docs_from_rfc_index(data, errata, today - datetime.timedelta(days=30)):
343359
changes.append(cs)
344360

345361
doc = Document.objects.get(name=doc.name)
@@ -364,7 +380,7 @@ def test_rfc_index(self):
364380
self.assertTrue(os.path.exists(os.path.join(self.archive_dir, draft_filename)))
365381

366382
# make sure we can apply it again with no changes
367-
changed = list(rfceditor.update_docs_from_rfc_index(data, today - datetime.timedelta(days=30)))
383+
changed = list(rfceditor.update_docs_from_rfc_index(data, errata, today - datetime.timedelta(days=30)))
368384
self.assertEqual(len(changed), 0)
369385

370386

0 commit comments

Comments
 (0)