Skip to content

Commit 3ac5bd3

Browse files
committed
Merged [2621] from adam@nostrum.com: Add tarfile and pdf-composite links and functionality to download working group documents from the agenda page. Fixes ietf-tools#539
- Legacy-Id: 2627 Note: SVN reference [2621] has been migrated to Git commit 276d13c
1 parent 06c254a commit 3ac5bd3

4 files changed

Lines changed: 163 additions & 0 deletions

File tree

ietf/meeting/urls.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
(r'^agenda.txt$', views.text_agenda),
1111
(r'^(?P<num>\d+)/agenda(?:.html)?/?$', views.html_agenda),
1212
(r'^(?P<num>\d+)/agenda.txt$', views.text_agenda),
13+
(r'^(?P<num>\d+)/agenda/(?P<session>[A-Za-z0-9-]+)-drafts.pdf$', views.session_draft_pdf),
14+
(r'^(?P<num>\d+)/agenda/(?P<session>[A-Za-z0-9-]+)-drafts.tgz$', views.session_draft_tarfile),
1315
(r'^(?P<num>\d+)/agenda/(?P<session>[A-Za-z0-9-]+)(?P<ext>\.[A-Za-z0-9]+)?$', views.session_agenda),
1416
(r'^$', views.current_materials),
1517
)

ietf/meeting/views.py

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
#import models
55
import datetime
66
import os
7+
import re
8+
import tarfile
9+
10+
from tempfile import mkstemp
711

812
from django.shortcuts import render_to_response, get_object_or_404
913
from ietf.idtracker.models import IETFWG, IRTF, Area
@@ -17,6 +21,9 @@
1721
from django.utils.decorators import decorator_from_middleware
1822
from django.middleware.gzip import GZipMiddleware
1923
from django.db.models import Count
24+
from ietf.idtracker.models import InternetDraft
25+
from ietf.idrfc.idrfc_wrapper import IdWrapper
26+
from ietf.utils.pipe import pipe
2027

2128
from ietf.proceedings.models import Meeting, MeetingTime, WgMeetingSession, MeetingVenue, IESGHistory, Proceeding, Switches, WgProceedingsActivities
2229

@@ -148,3 +155,154 @@ def session_agenda(request, num, session, ext=None):
148155
raise Http404("No %s agenda for the %s session of IETF %s is available" % (ext, session, num))
149156
else:
150157
raise Http404("No agenda for the %s session of IETF %s is available" % (session, num))
158+
159+
def convert_to_pdf(doc_name):
160+
import subprocess
161+
inpath = os.path.join(settings.INTERNET_DRAFT_PATH, doc_name + ".txt")
162+
outpath = os.path.join(settings.INTERNET_DRAFT_PDF_PATH, doc_name + ".pdf")
163+
164+
try:
165+
infile = open(inpath, "r")
166+
except Exception, e:
167+
return
168+
169+
t,tempname = mkstemp()
170+
tempfile = open(tempname, "w")
171+
172+
pageend = 0;
173+
newpage = 0;
174+
formfeed = 0;
175+
for line in infile:
176+
line = re.sub("\r","",line)
177+
line = re.sub("[ \t]+$","",line)
178+
if re.search("\[?[Pp]age [0-9ivx]+\]?[ \t]*$",line):
179+
pageend=1
180+
tempfile.write(line)
181+
continue
182+
if re.search("^[ \t]*\f",line):
183+
formfeed=1
184+
tempfile.write(line)
185+
continue
186+
if re.search("^ *INTERNET.DRAFT.+[0-9]+ *$",line) or re.search("^ *Internet.Draft.+[0-9]+ *$",line) or re.search("^draft-[-a-z0-9_.]+.*[0-9][0-9][0-9][0-9]$",line) or re.search("^RFC.+[0-9]+$",line):
187+
newpage=1
188+
if re.search("^[ \t]*$",line) and pageend and not newpage:
189+
continue
190+
if pageend and newpage and not formfeed:
191+
tempfile.write("\f")
192+
pageend=0
193+
formfeed=0
194+
newpage=0
195+
tempfile.write(line)
196+
197+
infile.close()
198+
tempfile.close()
199+
t,psname = mkstemp()
200+
pipe("enscript --margins 76::76: -B -q -p "+psname + " " +tempname)
201+
os.unlink(tempname)
202+
pipe("ps2pdf "+psname+" "+outpath)
203+
os.unlink(psname)
204+
205+
206+
def session_draft_list(num, session):
207+
extensions = ["html", "htm", "txt", "HTML", "HTM", "TXT", ]
208+
result = []
209+
found = False
210+
for wg in [session, session.upper(), session.lower()]:
211+
for e in extensions:
212+
path = settings.AGENDA_PATH_PATTERN % {"meeting":num, "wg":wg, "ext":e}
213+
if os.path.exists(path):
214+
file = open(path)
215+
agenda = file.read()
216+
file.close()
217+
found = True
218+
break
219+
if found:
220+
break
221+
else:
222+
raise Http404("No agenda for the %s session of IETF %s is available" % (session, num))
223+
224+
drafts = set(re.findall('(draft-[-a-z0-9]*)',agenda))
225+
226+
for draft in drafts:
227+
if (re.search('-[0-9]{2}$',draft)):
228+
doc_name = draft
229+
else:
230+
id = get_object_or_404(InternetDraft, filename=draft)
231+
doc = IdWrapper(id)
232+
doc_name = draft + "-" + id.revision
233+
result.append(doc_name)
234+
235+
return sorted(list(set(result)))
236+
237+
238+
def session_draft_tarfile(request, num, session):
239+
drafts = session_draft_list(num, session);
240+
241+
response = HttpResponse(mimetype='application/octet-stream')
242+
response['Content-Disposition'] = 'attachment; filename=%s-drafts.tgz'%(session)
243+
tarstream = tarfile.open('','w:gz',response)
244+
mfh, mfn = mkstemp()
245+
manifest = open(mfn, "w")
246+
247+
for doc_name in drafts:
248+
pdf_path = os.path.join(settings.INTERNET_DRAFT_PDF_PATH, doc_name + ".pdf")
249+
250+
if (not os.path.exists(pdf_path)):
251+
convert_to_pdf(doc_name)
252+
253+
if os.path.exists(pdf_path):
254+
try:
255+
tarstream.add(pdf_path, str(doc_name + ".pdf"))
256+
manifest.write("Included: "+pdf_path+"\n")
257+
except Exception, e:
258+
manifest.write(("Failed (%s): "%e)+pdf_path+"\n")
259+
else:
260+
manifest.write("Not found: "+pdf_path+"\n")
261+
262+
manifest.close()
263+
tarstream.add(mfn, "manifest.txt")
264+
tarstream.close()
265+
os.unlink(mfn)
266+
return response
267+
268+
def pdf_pages(file):
269+
try:
270+
infile = open(file, "r")
271+
except Exception, e:
272+
return 0
273+
for line in infile:
274+
m = re.match('\] /Count ([0-9]+)',line)
275+
if m:
276+
return int(m.group(1))
277+
return 0
278+
279+
280+
def session_draft_pdf(request, num, session):
281+
drafts = session_draft_list(num, session);
282+
curr_page = 1
283+
pmh, pmn = mkstemp()
284+
pdfmarks = open(pmn, "w")
285+
pdf_list = ""
286+
287+
for draft in drafts:
288+
pdf_path = os.path.join(settings.INTERNET_DRAFT_PDF_PATH, draft + ".pdf")
289+
if (not os.path.exists(pdf_path)):
290+
convert_to_pdf(draft)
291+
292+
if (os.path.exists(pdf_path)):
293+
pages = pdf_pages(pdf_path)
294+
pdfmarks.write("[/Page "+str(curr_page)+" /View [/XYZ 0 792 1.0] /Title (" + draft + ") /OUT pdfmark\n")
295+
pdf_list = pdf_list + " " + pdf_path
296+
curr_page = curr_page + pages
297+
298+
pdfmarks.close()
299+
pdfh, pdfn = mkstemp()
300+
pipe("gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=" + pdfn + " " + pdf_list + " " + pmn)
301+
302+
pdf = open(pdfn,"r")
303+
pdf_contents = pdf.read()
304+
pdf.close()
305+
306+
os.unlink(pmn)
307+
os.unlink(pdfn)
308+
return HttpResponse(pdf_contents, mimetype="application/pdf")

ietf/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@
158158
# Override this in settings_local.py if needed
159159
# *_PATH variables ends with a slash/ .
160160
INTERNET_DRAFT_PATH = '/a/www/ietf-ftp/internet-drafts/'
161+
INTERNET_DRAFT_PDF_PATH = '/a/www/ietf-datatracker/pdf/'
161162
RFC_PATH = '/a/www/ietf-ftp/rfc/'
162163
AGENDA_PATH = '/a/www/www6s/proceedings/'
163164
AGENDA_PATH_PATTERN = '/a/www/www6s/proceedings/%(meeting)s/agenda/%(wg)s.%(ext)s'

ietf/templates/meeting/agenda.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,11 @@ <h2 class="ietf-divider">{{ slot.meeting_date|date:"l"|upper }}, {{ slot.meeting
277277
<td>{{ session.info.area|upper}}</td>
278278
<td>{% if session.info.isWG %}<a href="/wg/{{ session.info.acronym|lower }}/">{{ session.info.acronym|lower }}</a>{% else %}{{ session.info.acronym|lower }}{% endif %}</td>
279279
<td>
280+
<table width="100%"><tr><td>
280281
<img src="/images/color-palette-4x4.gif" alt="" onclick="pickAgendaColor('{{meeting.num}}-{{slot.meeting_date|date:"D"|lower}}-{{slot.time_desc|slice:":4"}}-{{session.info.area|upper}}-{{session.info.acronym|lower}}',this);" title="color tag this line"/ class="noprint">
281282
{% if session.info.agenda_file %}<a href="http://www.ietf.org/proceedings/{{ session.info.agenda_file }}" title="session agenda">{{ session.info.acronym_name|escape }} {{ session.info.group_type_str }}</a>{% else %}{{ session.info.acronym_name|escape }} {{ session.info.group_type_str }}{% endif %}
282283
{% if session.info.special_agenda_note %}<br/> - {{ session.info.special_agenda_note }}{% endif %}
284+
</td><td align="right">drafts:&nbsp;<a href="/meeting/79/agenda/{{session.info.acronym}}-drafts.tgz">tar</a>|<a href="/meeting/79/agenda/{{session.info.acronym}}-drafts.pdf">pdf</a></td></tr></table>
283285
</td>
284286
{% endif %}
285287
</tr>

0 commit comments

Comments
 (0)