Skip to content

Commit 29a0c8a

Browse files
committed
Added a data migration to create yang catalog links for yang documents published before the yang catalog link feature was introduced in the datatracker.
- Legacy-Id: 14447
1 parent 7d7b7de commit 29a0c8a

1 file changed

Lines changed: 72 additions & 0 deletions

File tree

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.10.8 on 2017-11-01 14:00
3+
from __future__ import unicode_literals, print_function
4+
5+
import os
6+
import json
7+
from tqdm import tqdm
8+
9+
from django.db import migrations
10+
from django.conf import settings
11+
12+
import debug # pyflakes:ignore
13+
14+
from ietf.submit.checkers import DraftYangChecker
15+
16+
def get_file_name(draft):
17+
return os.path.join(settings.INTERNET_DRAFT_PATH, '%s-%s.txt'%(draft.name, draft.rev))
18+
19+
YANG_RFCS = [ 5717, 6021, 6022, 6087, 6095, 6241, 6243, 6470, 6536, 6643,
20+
6728, 6991, 7223, 7224, 7277, 7317, 7407, 7758, 7895, 7952, 8022, 8040,
21+
8049, 8072, 8177, 8194, 8294, ]
22+
23+
def forwards(apps, schema_editor):
24+
DocAlias = apps.get_model('doc', 'DocAlias')
25+
SubmissionCheck = apps.get_model('submit', 'SubmissionCheck')
26+
checker = DraftYangChecker()
27+
28+
for rfc_number in tqdm(YANG_RFCS):
29+
draft = DocAlias.objects.get(name="rfc%s" % rfc_number).document
30+
submission = draft.submission_set.filter(rev=draft.rev).order_by('-id').first()
31+
if submission:
32+
prev_check = submission.checks.filter(checker=checker.name).order_by('-id').first()
33+
if prev_check and prev_check.message:
34+
result = checker.check_file_txt(get_file_name(draft))
35+
passed, message, errors, warnings, items = result
36+
items = json.loads(json.dumps(items))
37+
items['draft'] = draft.name
38+
items['rev'] = draft.rev
39+
check = SubmissionCheck.objects.create(submission=submission, checker=checker.name, passed=passed,
40+
message=message, errors=errors, warnings=warnings, items=items,
41+
symbol=checker.symbol)
42+
if 'code' in check.items and check.items['code']:
43+
code = check.items['code']
44+
if 'yang' in code:
45+
modules = code['yang']
46+
# Yang impact analysis URL
47+
draft.documenturl_set.filter(tag_id='yang-impact-analysis').delete()
48+
f = settings.SUBMIT_YANG_CATALOG_MODULEARG
49+
moduleargs = '&'.join([ f.format(module=m) for m in modules])
50+
url = settings.SUBMIT_YANG_CATALOG_IMPACT_URL.format(moduleargs=moduleargs, draft=draft.name)
51+
desc = settings.SUBMIT_YANG_CATALOG_IMPACT_DESC.format(modules=','.join(modules), draft=draft.name)
52+
draft.documenturl_set.create(url=url, tag_id='yang-impact-analysis', desc=desc)
53+
# Yang module metadata URLs
54+
old_urls = draft.documenturl_set.filter(tag_id='yang-module-metadata')
55+
old_urls.delete()
56+
for module in modules:
57+
url = settings.SUBMIT_YANG_CATALOG_MODULE_URL.format(module=module)
58+
desc = settings.SUBMIT_YANG_CATALOG_MODULE_DESC.format(module=module)
59+
draft.documenturl_set.create(url=url, tag_id='yang-module-metadata', desc=desc)
60+
61+
def backwards(apps, schema_editor):
62+
pass
63+
64+
class Migration(migrations.Migration):
65+
66+
dependencies = [
67+
('submit', '0023_create_draft_yang_links'),
68+
]
69+
70+
operations = [
71+
migrations.RunPython(forwards, backwards),
72+
]

0 commit comments

Comments
 (0)