Skip to content

Commit 9b43e15

Browse files
committed
Update reference relationships (asyncronously) for new rfcs found when syncing with the rfc index. Fixes ticket ietf-tools#1347. Commit ready to merge.
- Legacy-Id: 7557
1 parent c83fef3 commit 9b43e15

4 files changed

Lines changed: 35 additions & 4 deletions

File tree

ietf/bin/rfc-editor-index-updates

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import os, sys, re, json, datetime
44
import syslog
5+
import traceback
56

67
syslog.openlog(os.path.basename(__file__), syslog.LOG_PID, syslog.LOG_USER)
78

@@ -13,6 +14,7 @@ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ietf.settings")
1314

1415
from django.conf import settings
1516
from optparse import OptionParser
17+
from django.core.mail import mail_admins
1618

1719
parser = OptionParser()
1820
parser.add_option("-d", dest="skip_date",
@@ -24,7 +26,9 @@ skip_date = datetime.date.today() - datetime.timedelta(days=365)
2426
if options.skip_date:
2527
skip_date = datetime.datetime.strptime(options.skip_date, "%Y-%m-%d").date()
2628

29+
from ietf.utils.pipe import pipe
2730
from ietf.sync.rfceditor import *
31+
from ietf.doc.utils import rebuild_reference_relations
2832

2933
syslog.syslog("Updating document metadata from RFC index from %s" % settings.RFC_EDITOR_QUEUE_URL)
3034

@@ -35,6 +39,28 @@ if len(data) < MIN_INDEX_RESULTS:
3539
syslog.syslog("Not enough results, only %s" % len(data))
3640
sys.exit(1)
3741

38-
changed = update_docs_from_rfc_index(data, skip_older_than_date=skip_date)
42+
changed, new_rfcs = update_docs_from_rfc_index(data, skip_older_than_date=skip_date)
43+
3944
for c in changed:
4045
syslog.syslog(c)
46+
47+
# This can be called while processing a notifying POST from the RFC Editor
48+
# Spawn a child to sync the rfcs and calculate new reference relationships
49+
# so that the POST
50+
51+
newpid = os.fork()
52+
53+
if newpid == 0:
54+
try:
55+
pipe("%s -a %s %s" % (settings.RSYNC_BINARY,settings.RFC_TEXT_RSYNC_SOURCE,settings.RFC_PATH))
56+
for rfc in new_rfcs:
57+
rebuild_reference_relations(rfc)
58+
syslog.syslog("Updated references for %s"%rfc.canonical_name())
59+
except:
60+
subject = "Exception in updating references for new rfcs: %s : %s" % (sys.exc_info()[0],sys.exc_info()[1])
61+
msg = "%s\n%s\n----\n%s"%(sys.exc_info()[0],sys.exc_info()[1],traceback.format_tb(sys.exc_info()[2]))
62+
mail_admins(subject,msg,fail_silently=True)
63+
syslog.syslog(subject)
64+
os._exit(0)
65+
else:
66+
sys.exit(0)

ietf/settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ def skip_suspicious_operations(record):
313313
IANA_SYNC_CHANGES_URL = "https://datatracker.iana.org:4443/data-tracker/changes"
314314
IANA_SYNC_PROTOCOLS_URL = "http://www.iana.org/protocols/"
315315

316+
RFC_TEXT_RSYNC_SOURCE="ftp.rfc-editor.org::rfcs-text-only"
317+
316318
RFC_EDITOR_SYNC_PASSWORD="secret"
317319
RFC_EDITOR_SYNC_NOTIFICATION_URL = "http://www.rfc-editor.org/parser/parser.php"
318320
RFC_EDITOR_QUEUE_URL = "http://www.rfc-editor.org/queue2.xml"
@@ -369,6 +371,7 @@ def skip_suspicious_operations(record):
369371
DOT_BINARY = '/usr/bin/dot'
370372
UNFLATTEN_BINARY= '/usr/bin/unflatten'
371373
PS2PDF_BINARY = '/usr/bin/ps2pdf'
374+
RSYNC_BINARY = '/usr/bin/rsync'
372375

373376
# Account settings
374377
DAYS_TO_EXPIRE_REGISTRATION_LINK = 3

ietf/sync/rfceditor.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ def update_docs_from_rfc_index(data, skip_older_than_date=None):
317317
system = Person.objects.get(name="(System)")
318318

319319
results = []
320+
new_rfcs = []
320321

321322
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:
322323

@@ -399,6 +400,7 @@ def update_docs_from_rfc_index(data, skip_older_than_date=None):
399400
other_changes = True
400401

401402
results.append("Added RFC published event: %s" % e.time.strftime("%Y-%m-%d"))
403+
new_rfcs.append(doc)
402404

403405
for t in ("draft-iesg", "draft-stream-iab", "draft-stream-irtf", "draft-stream-ise"):
404406
slug = doc.get_state_slug(t)
@@ -461,7 +463,7 @@ def parse_relation_list(l):
461463
doc.time = datetime.datetime.now()
462464
doc.save()
463465

464-
return results
466+
return results, new_rfcs
465467

466468

467469
def post_approved_draft(url, name):

ietf/sync/tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ def test_rfc_index(self):
306306
draft_filename = "%s-%s.txt" % (doc.name, doc.rev)
307307
self.write_draft_file(draft_filename, 5000)
308308

309-
changed = rfceditor.update_docs_from_rfc_index(data, today - datetime.timedelta(days=30))
309+
changed,_ = rfceditor.update_docs_from_rfc_index(data, today - datetime.timedelta(days=30))
310310

311311
doc = Document.objects.get(name=doc.name)
312312

@@ -329,7 +329,7 @@ def test_rfc_index(self):
329329
self.assertTrue(os.path.exists(os.path.join(self.archive_dir, draft_filename)))
330330

331331
# make sure we can apply it again with no changes
332-
changed = rfceditor.update_docs_from_rfc_index(data, today - datetime.timedelta(days=30))
332+
changed,_ = rfceditor.update_docs_from_rfc_index(data, today - datetime.timedelta(days=30))
333333
self.assertEqual(len(changed), 0)
334334

335335

0 commit comments

Comments
 (0)