Skip to content

Commit bce70e7

Browse files
authored
feat: import iab agendas from iab website (ietf-tools#6197)
* feat: import iab agendas from wiki * chore: adjust command help text
1 parent 95050f3 commit bce70e7

2 files changed

Lines changed: 244 additions & 0 deletions

File tree

Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
# Copyright The IETF Trust 2023, All Rights Reserved
2+
3+
import datetime
4+
import os
5+
import shutil
6+
import subprocess
7+
import tempfile
8+
9+
from pathlib import Path
10+
11+
from django.core.management.base import BaseCommand
12+
from django.conf import settings
13+
14+
from ietf.doc.models import Document, DocAlias, DocEvent
15+
from ietf.meeting.models import Meeting, Session
16+
17+
18+
def agendas_to_import():
19+
return [
20+
"2018-09-05.md",
21+
"2018-09-12.md",
22+
"2018-09-26.md",
23+
"2018-10-03.md",
24+
"2018-10-10.md",
25+
"2018-10-24.md",
26+
"2018-11-04.md",
27+
"2018-11-05.md",
28+
"2018-11-08.md",
29+
"2018-11-21.md",
30+
"2018-11-28.md",
31+
"2018-12-05.md",
32+
"2018-12-19.md",
33+
"2019-01-09.md",
34+
"2019-01-16.md",
35+
"2019-01-23.md",
36+
"2019-02-06.md",
37+
"2019-02-13.md",
38+
"2019-02-27.md",
39+
"2019-03-06.md",
40+
"2019-03-13.md",
41+
"2019-03-24.md",
42+
"2019-03-25.md",
43+
"2019-03-28.md",
44+
"2019-04-10.md",
45+
"2019-04-17.md",
46+
"2019-05-01.md",
47+
"2019-05-08.md",
48+
"2019-05-29.md",
49+
"2019-06-12.md",
50+
"2019-06-26.md",
51+
"2019-07-10.md",
52+
"2019-07-21.md",
53+
"2019-07-25.md",
54+
"2019-08-07.md",
55+
"2019-08-21.md",
56+
"2019-08-28.md",
57+
"2019-09-04.md",
58+
"2019-09-18.md",
59+
"2019-10-02.md",
60+
"2019-10-16.md",
61+
"2019-10-30.md",
62+
"2019-11-17.md",
63+
"2019-11-18.md",
64+
"2019-11-21.md",
65+
"2019-12-04.md",
66+
"2019-12-11.md",
67+
"2019-12-18.md",
68+
"2020-01-08.md",
69+
"2020-01-15.md",
70+
"2020-01-22.md",
71+
"2020-02-05.md",
72+
"2020-02-12.md",
73+
"2020-02-19.md",
74+
"2020-03-04.md",
75+
"2020-03-11.md",
76+
"2020-03-18.md",
77+
"2020-04-01.md",
78+
"2020-04-08.md",
79+
"2020-04-15.md",
80+
"2020-04-29.md",
81+
"2020-05-13.md",
82+
"2020-05-20.md",
83+
"2020-05-27.md",
84+
"2020-06-10.md",
85+
"2020-06-17.md",
86+
"2020-07-01.md",
87+
"2020-07-15.md",
88+
"2020-08-12.md",
89+
"2020-08-26.md",
90+
"2020-09-09.md",
91+
"2020-09-23.md",
92+
"2020-10-07.md",
93+
"2020-10-14.md",
94+
"2020-10-21.md",
95+
"2020-11-04.md",
96+
"2020-12-02.md",
97+
"2020-12-16.md",
98+
"2021-01-06.md",
99+
"2021-01-13.md",
100+
"2021-01-20.md",
101+
"2021-01-27.md",
102+
"2021-02-03.md",
103+
"2021-02-10.md",
104+
"2021-02-17.md",
105+
"2021-02-24.md",
106+
"2021-03-03.md",
107+
"2021-03-24.md",
108+
"2021-03-31.md",
109+
"2021-04-07.md",
110+
"2021-04-14.md",
111+
"2021-04-21.md",
112+
"2021-05-05.md",
113+
"2021-05-12.md",
114+
"2021-05-19.md",
115+
"2021-05-26.md",
116+
"2021-06-02.md",
117+
"2021-06-16.md",
118+
"2021-06-23.md",
119+
"2021-06-30.md",
120+
"2021-07-14.md",
121+
"2021-07-21.md",
122+
"2021-08-11.md",
123+
"2021-08-25.md",
124+
"2021-09-01.md",
125+
"2021-09-08.md",
126+
"2021-09-22.md",
127+
"2021-10-06.md",
128+
"2021-10-20.md",
129+
"2021-10-27.md",
130+
"2021-11-17.md",
131+
"2021-12-01.md",
132+
"2021-12-08.md",
133+
"2021-12-15.md",
134+
"2022-01-12.md",
135+
"2022-01-19.md",
136+
"2022-02-02.md",
137+
"2022-02-16.md",
138+
"2022-02-23.md",
139+
"2022-03-02.md",
140+
"2022-03-09.md",
141+
"2022-03-20.md",
142+
"2022-04-06.md",
143+
"2022-04-13.md",
144+
"2022-04-20.md",
145+
"2022-04-27.md",
146+
"2022-05-04.md",
147+
"2022-05-11.md",
148+
"2022-06-01.md",
149+
"2022-06-15.md",
150+
"2022-06-22.md",
151+
"2022-06-29.md",
152+
"2022-07-06.md",
153+
"2022-07-24.md",
154+
"2022-07-26.md",
155+
"2022-08-10.md",
156+
"2022-08-24.md",
157+
"2022-09-07.md",
158+
"2022-09-21.md",
159+
"2022-09-28.md",
160+
"2022-10-05.md",
161+
"2022-10-12.md",
162+
"2022-10-26.md",
163+
"2022-11-06.md",
164+
"2022-11-08.md",
165+
"2022-11-10.md",
166+
"2022-11-23.md",
167+
"2022-12-07.md",
168+
"2022-12-14.md",
169+
]
170+
171+
172+
class Command(BaseCommand):
173+
help = "Performs a one-time import of older IAB agendas"
174+
175+
def handle(self, *args, **options):
176+
if Document.objects.filter(name="agenda-interim-2018-iab-26-20180905").exists():
177+
print("Command has already been run - exiting")
178+
exit(0)
179+
180+
tmpdir = tempfile.mkdtemp()
181+
process = subprocess.Popen(
182+
["git", "clone", "https://github.com/kesara/iab-scraper.git", tmpdir],
183+
stdout=subprocess.PIPE,
184+
stderr=subprocess.PIPE,
185+
)
186+
stdout, stderr = process.communicate()
187+
if not Path(tmpdir).joinpath("iab_agendas", "2018-09-05.md").exists():
188+
print("Git clone of the iab-scraper directory did not go as expected")
189+
print("stdout:", stdout)
190+
print("stderr:", stderr)
191+
print(f"Clean up {tmpdir} manually")
192+
exit(-1)
193+
194+
agendas = agendas_to_import()
195+
for agenda in agendas:
196+
[year, month, day] = [int(part) for part in agenda[:10].split("-")]
197+
agenda_date = datetime.date(year, month, day)
198+
meeting = Meeting.objects.get(
199+
date=agenda_date, type_id="interim", session__group__acronym="iab"
200+
)
201+
counter = int(meeting.number.split("-")[3])
202+
agenda_docname = (
203+
f"agenda-interim-{year}-iab-{counter:02d}-{agenda_date:%Y%m%d}"
204+
)
205+
agenda_filename = f"{agenda_docname}-00.md"
206+
# Create Document
207+
doc = Document.objects.create(
208+
name=agenda_docname,
209+
type_id="agenda",
210+
title=f"Agenda {meeting.number} {agenda_date:%Y-%m-%d}",
211+
group_id=7, # The IAB group
212+
rev="00",
213+
uploaded_filename=agenda_filename,
214+
)
215+
DocAlias.objects.create(name=doc.name).docs.add(doc)
216+
e = DocEvent.objects.create(
217+
type="comment",
218+
doc=doc,
219+
rev="00",
220+
by_id=1, # The "(System)" person
221+
desc="Agenda moved into datatracker from iab wordpress website",
222+
)
223+
doc.save_with_history([e])
224+
225+
session = Session.objects.get(meeting=meeting)
226+
# Add Document to Session
227+
session.sessionpresentation_set.create(document=doc, rev=doc.rev)
228+
229+
# Put file in place
230+
source = Path(tmpdir).joinpath("iab_agendas", agenda)
231+
dest = Path(settings.AGENDA_PATH).joinpath(
232+
meeting.number, "agenda", agenda_filename
233+
)
234+
if dest.exists():
235+
print(f"WARNING: {dest} already exists - not overwriting it.")
236+
else:
237+
os.makedirs(dest.parent, exist_ok=True)
238+
shutil.copy(source, dest)
239+
240+
shutil.rmtree(tmpdir)

ietf/templates/group/meetings.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ <h2 class="mt-3" id="farpastmeets">Meetings more than four years ago</h2>
135135
</td>
136136
<td>
137137
{% if not s.canceled %}
138+
<a class="btn btn-sm {% if not s.agenda %}btn-secondary disabled{% else %}btn-primary{% endif %}"
139+
{% if s.agenda %}href="{{ s.agenda.get_absolute_url }}"{% endif %}>
140+
Agenda
141+
</a>
138142
<a class="btn btn-sm {% if not s.minutes %}btn-secondary disabled{% else %}btn-primary{% endif %}"
139143
{% if s.minutes %}href="{{ s.minutes.get_absolute_url }}"{% endif %}>
140144
Minutes

0 commit comments

Comments
 (0)