Skip to content

Commit c055d37

Browse files
committed
Removed extref app. Refined population migrations.
- Legacy-Id: 17509
1 parent 316dd18 commit c055d37

21 files changed

Lines changed: 106 additions & 92 deletions

File tree

ietf/extresource/management/commands/find_github_backup_info.py renamed to ietf/doc/management/commands/find_github_backup_info.py

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

44
from django.core.management.base import BaseCommand
5-
from django.db.models import Q
65

76
from ietf.extresource.models import ExtResource
87
from ietf.doc.models import DocExtResource

ietf/doc/migrations/0032_extres.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
# Copyright The IETF Trust 2020, All Rights Reserved
21
# -*- coding: utf-8 -*-
3-
# Generated by Django 1.11.29 on 2020-03-19 13:56
2+
# Generated by Django 1.11.29 on 2020-03-22 10:49
43
from __future__ import unicode_literals
54

65
from django.db import migrations, models
@@ -11,7 +10,7 @@
1110
class Migration(migrations.Migration):
1211

1312
dependencies = [
14-
('extresource', '0001_extres'),
13+
('name', '0011_populate_extres'),
1514
('doc', '0031_set_state_for_charters_of_replaced_groups'),
1615
]
1716

@@ -20,8 +19,9 @@ class Migration(migrations.Migration):
2019
name='DocExtResource',
2120
fields=[
2221
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
22+
('value', models.CharField(max_length=2083)),
2323
('doc', ietf.utils.models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='doc.Document')),
24-
('extresource', ietf.utils.models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='extresource.ExtResource')),
24+
('name', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='name.ExtResourceName')),
2525
],
2626
),
2727
]

ietf/doc/migrations/0033_populate_docextresources.py

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
import debug
99

10+
from collections import OrderedDict
11+
1012
from django.db import migrations
1113

1214
"""
@@ -41,14 +43,31 @@
4143
"GitLab User Name": "gitlab_username",
4244
}
4345

46+
# TODO: Review all the None values below and make sure ignoring the URLs they match is really the right thing to do.
47+
url_map = OrderedDict({
48+
"https?://github\\.com": "github_repo",
49+
"https?://trac\\.ietf\\.org/.*/wiki": "wiki",
50+
"ietf\\.org.*/trac/wiki": "wiki",
51+
"trac.*wiki": "wiki",
52+
"www\\.ietf\\.org/mailman" : None,
53+
"www\\.ietf\\.org/mail-archive" : None,
54+
"mailarchive\\.ietf\\.org" : None,
55+
"ietf\\.org/logs": "jabber_log",
56+
"ietf\\.org/jabber/logs": "jabber_log",
57+
"xmpp:.*?join": "jabber_room",
58+
"bell-labs\\.com": None,
59+
"html\\.charters": None,
60+
"datatracker\\.ietf\\.org": None,
61+
})
62+
4463
def forward(apps, schema_editor):
4564
DocExtResource = apps.get_model('doc', 'DocExtResource')
46-
ExtResource = apps.get_model('extresource', 'ExtResource')
4765
ExtResourceName = apps.get_model('name', 'ExtResourceName')
4866
DocumentUrl = apps.get_model('doc', 'DocumentUrl')
4967

5068
mapped = 0
5169
not_mapped = 0
70+
ignored = 0
5271

5372
for doc_url in DocumentUrl.objects.all():
5473
match_found = False
@@ -57,13 +76,31 @@ def forward(apps, schema_editor):
5776
match_found = True
5877
mapped += 1
5978
name = ExtResourceName.objects.get(slug=slug)
60-
ext_res = ExtResource.objects.create(name_id=slug, value= doc_url.url) # TODO: validate this value against name.type
61-
DocExtResource.objects.create(doc=doc_url.doc, extresource=ext_res)
79+
DocExtResource.objects.create(doc=doc_url.doc, name_id=slug, value=doc_url.url) # TODO: validate this value against name.type
6280
break
81+
if not match_found:
82+
for regext, slug in url_map.items():
83+
if re.search(regext, doc_url.url):
84+
match_found = True
85+
if slug:
86+
mapped +=1
87+
name = ExtResourceName.objects.get(slug=slug)
88+
# Munge the URL if it's the first github repo match
89+
# Remove "/tree/master" substring if it exists
90+
# Remove trailing "/issues" substring if it exists
91+
# Remove "/blob/master/.*" pattern if present
92+
if regext == "https?://github\\.com":
93+
doc_url.url = doc_url.url.replace("/tree/master","")
94+
doc_url.url = re.sub('/issues$', '', doc_url.url)
95+
doc_url.url = re.sub('/blob/master.*$', '', doc_url.url)
96+
DocExtResource.objects.create(doc=doc_url.doc, name_id=slug, value=doc_url.url) # TODO: validate this value against name.type
97+
else:
98+
ignored +=1
99+
break
63100
if not match_found:
64101
debug.show('("Not Mapped:",doc_url.desc, doc_url.tag.slug, doc_url.doc.name, doc_url.url)')
65102
not_mapped += 1
66-
debug.show('(mapped, not_mapped)')
103+
debug.show('(mapped, ignored, not_mapped)')
67104

68105
def reverse(apps, schema_editor):
69106
DocExtResource = apps.get_model('doc', 'DocExtResource')
@@ -73,7 +110,6 @@ class Migration(migrations.Migration):
73110

74111
dependencies = [
75112
('doc', '0032_extres'),
76-
('extresource', '0001_extres'),
77113
('name', '0011_populate_extres'),
78114
]
79115

ietf/doc/models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@
2222

2323
import debug # pyflakes:ignore
2424

25-
from ietf.extresource.models import ExtResource
2625
from ietf.group.models import Group
2726
from ietf.name.models import ( DocTypeName, DocTagName, StreamName, IntendedStdLevelName, StdLevelName,
2827
DocRelationshipName, DocReminderTypeName, BallotPositionName, ReviewRequestStateName, ReviewAssignmentStateName, FormalLanguageName,
29-
DocUrlTagName)
28+
DocUrlTagName, ExtResourceName)
3029
from ietf.person.models import Email, Person
3130
from ietf.person.utils import get_active_balloters
3231
from ietf.utils import log
@@ -865,7 +864,8 @@ class DocumentURL(models.Model):
865864

866865
class DocExtResource(models.Model):
867866
doc = ForeignKey(Document) # Should this really be to DocumentInfo rather than Document?
868-
extresource = ForeignKey(ExtResource)
867+
name = models.ForeignKey(ExtResourceName, on_delete=models.CASCADE)
868+
value = models.CharField(max_length=2083) # 2083 is the maximum legal URL length
869869

870870
@python_2_unicode_compatible
871871
class RelatedDocHistory(models.Model):

ietf/extresource/__init__.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

ietf/extresource/admin.py

Lines changed: 0 additions & 4 deletions
This file was deleted.

ietf/extresource/apps.py

Lines changed: 0 additions & 6 deletions
This file was deleted.

ietf/extresource/management/__init__.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

ietf/extresource/management/commands/__init__.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

ietf/extresource/migrations/0001_extres.py

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)