Skip to content

Commit

Permalink
Update reference relationships (asyncronously) for new rfcs found whe…
Browse files Browse the repository at this point in the history
…n syncing with the rfc index. Fixes ticket #1347. Commit ready to merge.

 - Legacy-Id: 7557
  • Loading branch information
rjsparks committed Apr 1, 2014
1 parent c83fef3 commit 9b43e15
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
28 changes: 27 additions & 1 deletion ietf/bin/rfc-editor-index-updates
Expand Up @@ -2,6 +2,7 @@

import os, sys, re, json, datetime
import syslog
import traceback

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

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

from django.conf import settings
from optparse import OptionParser
from django.core.mail import mail_admins

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

from ietf.utils.pipe import pipe
from ietf.sync.rfceditor import *
from ietf.doc.utils import rebuild_reference_relations

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

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

changed = update_docs_from_rfc_index(data, skip_older_than_date=skip_date)
changed, new_rfcs = update_docs_from_rfc_index(data, skip_older_than_date=skip_date)

for c in changed:
syslog.syslog(c)

# This can be called while processing a notifying POST from the RFC Editor
# Spawn a child to sync the rfcs and calculate new reference relationships
# so that the POST

newpid = os.fork()

if newpid == 0:
try:
pipe("%s -a %s %s" % (settings.RSYNC_BINARY,settings.RFC_TEXT_RSYNC_SOURCE,settings.RFC_PATH))
for rfc in new_rfcs:
rebuild_reference_relations(rfc)
syslog.syslog("Updated references for %s"%rfc.canonical_name())
except:
subject = "Exception in updating references for new rfcs: %s : %s" % (sys.exc_info()[0],sys.exc_info()[1])
msg = "%s\n%s\n----\n%s"%(sys.exc_info()[0],sys.exc_info()[1],traceback.format_tb(sys.exc_info()[2]))
mail_admins(subject,msg,fail_silently=True)
syslog.syslog(subject)
os._exit(0)
else:
sys.exit(0)
3 changes: 3 additions & 0 deletions ietf/settings.py
Expand Up @@ -313,6 +313,8 @@ def skip_suspicious_operations(record):
IANA_SYNC_CHANGES_URL = "https://datatracker.iana.org:4443/data-tracker/changes"
IANA_SYNC_PROTOCOLS_URL = "http://www.iana.org/protocols/"

RFC_TEXT_RSYNC_SOURCE="ftp.rfc-editor.org::rfcs-text-only"

RFC_EDITOR_SYNC_PASSWORD="secret"
RFC_EDITOR_SYNC_NOTIFICATION_URL = "http://www.rfc-editor.org/parser/parser.php"
RFC_EDITOR_QUEUE_URL = "http://www.rfc-editor.org/queue2.xml"
Expand Down Expand Up @@ -369,6 +371,7 @@ def skip_suspicious_operations(record):
DOT_BINARY = '/usr/bin/dot'
UNFLATTEN_BINARY= '/usr/bin/unflatten'
PS2PDF_BINARY = '/usr/bin/ps2pdf'
RSYNC_BINARY = '/usr/bin/rsync'

# Account settings
DAYS_TO_EXPIRE_REGISTRATION_LINK = 3
Expand Down
4 changes: 3 additions & 1 deletion ietf/sync/rfceditor.py
Expand Up @@ -317,6 +317,7 @@ def update_docs_from_rfc_index(data, skip_older_than_date=None):
system = Person.objects.get(name="(System)")

results = []
new_rfcs = []

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:

Expand Down Expand Up @@ -399,6 +400,7 @@ def update_docs_from_rfc_index(data, skip_older_than_date=None):
other_changes = True

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

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

return results
return results, new_rfcs


def post_approved_draft(url, name):
Expand Down
4 changes: 2 additions & 2 deletions ietf/sync/tests.py
Expand Up @@ -306,7 +306,7 @@ def test_rfc_index(self):
draft_filename = "%s-%s.txt" % (doc.name, doc.rev)
self.write_draft_file(draft_filename, 5000)

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

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

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

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


Expand Down

0 comments on commit 9b43e15

Please sign in to comment.