|
| 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 | +def forwards(apps, schema_editor): |
| 20 | + Document = apps.get_model('doc', 'Document') |
| 21 | + SubmissionCheck = apps.get_model('submit', 'SubmissionCheck') |
| 22 | + checker = DraftYangChecker() |
| 23 | + |
| 24 | + for draft in tqdm(Document.objects.filter(type_id='draft', states__slug='active', submission__checks__checker='yang validation').distinct()): |
| 25 | + submission = draft.submission_set.filter(rev=draft.rev).order_by('-id').first() |
| 26 | + if submission: |
| 27 | + prev_check = submission.checks.filter(checker=checker.name).order_by('-id').first() |
| 28 | + if prev_check and prev_check.message: |
| 29 | + result = checker.check_file_txt(get_file_name(draft)) |
| 30 | + passed, message, errors, warnings, items = result |
| 31 | + items = json.loads(json.dumps(items)) |
| 32 | + items['draft'] = draft.name |
| 33 | + items['rev'] = draft.rev |
| 34 | + check = SubmissionCheck.objects.create(submission=submission, checker=checker.name, passed=passed, |
| 35 | + message=message, errors=errors, warnings=warnings, items=items, |
| 36 | + symbol=checker.symbol) |
| 37 | + if 'code' in check.items and check.items['code']: |
| 38 | + code = check.items['code'] |
| 39 | + if 'yang' in code: |
| 40 | + modules = code['yang'] |
| 41 | + # Yang impact analysis URL |
| 42 | + draft.documenturl_set.filter(tag_id='yang-impact-analysis').delete() |
| 43 | + f = settings.SUBMIT_YANG_CATALOG_MODULEARG |
| 44 | + moduleargs = '&'.join([ f.format(module=m) for m in modules]) |
| 45 | + url = settings.SUBMIT_YANG_CATALOG_IMPACT_URL.format(moduleargs=moduleargs, draft=draft.name) |
| 46 | + desc = settings.SUBMIT_YANG_CATALOG_IMPACT_DESC.format(modules=','.join(modules), draft=draft.name) |
| 47 | + draft.documenturl_set.create(url=url, tag_id='yang-impact-analysis', desc=desc) |
| 48 | + # Yang module metadata URLs |
| 49 | + old_urls = draft.documenturl_set.filter(tag_id='yang-module-metadata') |
| 50 | + old_urls.delete() |
| 51 | + for module in modules: |
| 52 | + url = settings.SUBMIT_YANG_CATALOG_MODULE_URL.format(module=module) |
| 53 | + desc = settings.SUBMIT_YANG_CATALOG_MODULE_DESC.format(module=module) |
| 54 | + draft.documenturl_set.create(url=url, tag_id='yang-module-metadata', desc=desc) |
| 55 | + |
| 56 | +def backwards(apps, schema_editor): |
| 57 | + pass |
| 58 | + |
| 59 | +class Migration(migrations.Migration): |
| 60 | + |
| 61 | + dependencies = [ |
| 62 | + ('submit', '0022_submission_check_json_upgrade'), |
| 63 | + ] |
| 64 | + |
| 65 | + operations = [ |
| 66 | + migrations.RunPython(forwards, backwards), |
| 67 | + ] |
0 commit comments