Merged [2621] from adam@nostrum.com: Add tarfile and pdf-composite links and functionality to download working group documents from the agenda page. Fixes #539
- Legacy-Id: 2627 Note: SVN reference [2621] has been migrated to Git commit 276d13ca2ddef96a11b86cbc31210a057c20a415
This commit is contained in:
parent
06c254abe8
commit
3ac5bd3154
|
@ -10,6 +10,8 @@ urlpatterns = patterns('',
|
|||
(r'^agenda.txt$', views.text_agenda),
|
||||
(r'^(?P<num>\d+)/agenda(?:.html)?/?$', views.html_agenda),
|
||||
(r'^(?P<num>\d+)/agenda.txt$', views.text_agenda),
|
||||
(r'^(?P<num>\d+)/agenda/(?P<session>[A-Za-z0-9-]+)-drafts.pdf$', views.session_draft_pdf),
|
||||
(r'^(?P<num>\d+)/agenda/(?P<session>[A-Za-z0-9-]+)-drafts.tgz$', views.session_draft_tarfile),
|
||||
(r'^(?P<num>\d+)/agenda/(?P<session>[A-Za-z0-9-]+)(?P<ext>\.[A-Za-z0-9]+)?$', views.session_agenda),
|
||||
(r'^$', views.current_materials),
|
||||
)
|
||||
|
|
|
@ -4,6 +4,10 @@
|
|||
#import models
|
||||
import datetime
|
||||
import os
|
||||
import re
|
||||
import tarfile
|
||||
|
||||
from tempfile import mkstemp
|
||||
|
||||
from django.shortcuts import render_to_response, get_object_or_404
|
||||
from ietf.idtracker.models import IETFWG, IRTF, Area
|
||||
|
@ -17,6 +21,9 @@ from django.conf import settings
|
|||
from django.utils.decorators import decorator_from_middleware
|
||||
from django.middleware.gzip import GZipMiddleware
|
||||
from django.db.models import Count
|
||||
from ietf.idtracker.models import InternetDraft
|
||||
from ietf.idrfc.idrfc_wrapper import IdWrapper
|
||||
from ietf.utils.pipe import pipe
|
||||
|
||||
from ietf.proceedings.models import Meeting, MeetingTime, WgMeetingSession, MeetingVenue, IESGHistory, Proceeding, Switches, WgProceedingsActivities
|
||||
|
||||
|
@ -148,3 +155,154 @@ def session_agenda(request, num, session, ext=None):
|
|||
raise Http404("No %s agenda for the %s session of IETF %s is available" % (ext, session, num))
|
||||
else:
|
||||
raise Http404("No agenda for the %s session of IETF %s is available" % (session, num))
|
||||
|
||||
def convert_to_pdf(doc_name):
|
||||
import subprocess
|
||||
inpath = os.path.join(settings.INTERNET_DRAFT_PATH, doc_name + ".txt")
|
||||
outpath = os.path.join(settings.INTERNET_DRAFT_PDF_PATH, doc_name + ".pdf")
|
||||
|
||||
try:
|
||||
infile = open(inpath, "r")
|
||||
except Exception, e:
|
||||
return
|
||||
|
||||
t,tempname = mkstemp()
|
||||
tempfile = open(tempname, "w")
|
||||
|
||||
pageend = 0;
|
||||
newpage = 0;
|
||||
formfeed = 0;
|
||||
for line in infile:
|
||||
line = re.sub("\r","",line)
|
||||
line = re.sub("[ \t]+$","",line)
|
||||
if re.search("\[?[Pp]age [0-9ivx]+\]?[ \t]*$",line):
|
||||
pageend=1
|
||||
tempfile.write(line)
|
||||
continue
|
||||
if re.search("^[ \t]*\f",line):
|
||||
formfeed=1
|
||||
tempfile.write(line)
|
||||
continue
|
||||
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):
|
||||
newpage=1
|
||||
if re.search("^[ \t]*$",line) and pageend and not newpage:
|
||||
continue
|
||||
if pageend and newpage and not formfeed:
|
||||
tempfile.write("\f")
|
||||
pageend=0
|
||||
formfeed=0
|
||||
newpage=0
|
||||
tempfile.write(line)
|
||||
|
||||
infile.close()
|
||||
tempfile.close()
|
||||
t,psname = mkstemp()
|
||||
pipe("enscript --margins 76::76: -B -q -p "+psname + " " +tempname)
|
||||
os.unlink(tempname)
|
||||
pipe("ps2pdf "+psname+" "+outpath)
|
||||
os.unlink(psname)
|
||||
|
||||
|
||||
def session_draft_list(num, session):
|
||||
extensions = ["html", "htm", "txt", "HTML", "HTM", "TXT", ]
|
||||
result = []
|
||||
found = False
|
||||
for wg in [session, session.upper(), session.lower()]:
|
||||
for e in extensions:
|
||||
path = settings.AGENDA_PATH_PATTERN % {"meeting":num, "wg":wg, "ext":e}
|
||||
if os.path.exists(path):
|
||||
file = open(path)
|
||||
agenda = file.read()
|
||||
file.close()
|
||||
found = True
|
||||
break
|
||||
if found:
|
||||
break
|
||||
else:
|
||||
raise Http404("No agenda for the %s session of IETF %s is available" % (session, num))
|
||||
|
||||
drafts = set(re.findall('(draft-[-a-z0-9]*)',agenda))
|
||||
|
||||
for draft in drafts:
|
||||
if (re.search('-[0-9]{2}$',draft)):
|
||||
doc_name = draft
|
||||
else:
|
||||
id = get_object_or_404(InternetDraft, filename=draft)
|
||||
doc = IdWrapper(id)
|
||||
doc_name = draft + "-" + id.revision
|
||||
result.append(doc_name)
|
||||
|
||||
return sorted(list(set(result)))
|
||||
|
||||
|
||||
def session_draft_tarfile(request, num, session):
|
||||
drafts = session_draft_list(num, session);
|
||||
|
||||
response = HttpResponse(mimetype='application/octet-stream')
|
||||
response['Content-Disposition'] = 'attachment; filename=%s-drafts.tgz'%(session)
|
||||
tarstream = tarfile.open('','w:gz',response)
|
||||
mfh, mfn = mkstemp()
|
||||
manifest = open(mfn, "w")
|
||||
|
||||
for doc_name in drafts:
|
||||
pdf_path = os.path.join(settings.INTERNET_DRAFT_PDF_PATH, doc_name + ".pdf")
|
||||
|
||||
if (not os.path.exists(pdf_path)):
|
||||
convert_to_pdf(doc_name)
|
||||
|
||||
if os.path.exists(pdf_path):
|
||||
try:
|
||||
tarstream.add(pdf_path, str(doc_name + ".pdf"))
|
||||
manifest.write("Included: "+pdf_path+"\n")
|
||||
except Exception, e:
|
||||
manifest.write(("Failed (%s): "%e)+pdf_path+"\n")
|
||||
else:
|
||||
manifest.write("Not found: "+pdf_path+"\n")
|
||||
|
||||
manifest.close()
|
||||
tarstream.add(mfn, "manifest.txt")
|
||||
tarstream.close()
|
||||
os.unlink(mfn)
|
||||
return response
|
||||
|
||||
def pdf_pages(file):
|
||||
try:
|
||||
infile = open(file, "r")
|
||||
except Exception, e:
|
||||
return 0
|
||||
for line in infile:
|
||||
m = re.match('\] /Count ([0-9]+)',line)
|
||||
if m:
|
||||
return int(m.group(1))
|
||||
return 0
|
||||
|
||||
|
||||
def session_draft_pdf(request, num, session):
|
||||
drafts = session_draft_list(num, session);
|
||||
curr_page = 1
|
||||
pmh, pmn = mkstemp()
|
||||
pdfmarks = open(pmn, "w")
|
||||
pdf_list = ""
|
||||
|
||||
for draft in drafts:
|
||||
pdf_path = os.path.join(settings.INTERNET_DRAFT_PDF_PATH, draft + ".pdf")
|
||||
if (not os.path.exists(pdf_path)):
|
||||
convert_to_pdf(draft)
|
||||
|
||||
if (os.path.exists(pdf_path)):
|
||||
pages = pdf_pages(pdf_path)
|
||||
pdfmarks.write("[/Page "+str(curr_page)+" /View [/XYZ 0 792 1.0] /Title (" + draft + ") /OUT pdfmark\n")
|
||||
pdf_list = pdf_list + " " + pdf_path
|
||||
curr_page = curr_page + pages
|
||||
|
||||
pdfmarks.close()
|
||||
pdfh, pdfn = mkstemp()
|
||||
pipe("gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=" + pdfn + " " + pdf_list + " " + pmn)
|
||||
|
||||
pdf = open(pdfn,"r")
|
||||
pdf_contents = pdf.read()
|
||||
pdf.close()
|
||||
|
||||
os.unlink(pmn)
|
||||
os.unlink(pdfn)
|
||||
return HttpResponse(pdf_contents, mimetype="application/pdf")
|
||||
|
|
|
@ -158,6 +158,7 @@ TEST_RUNNER = 'ietf.utils.test_runner.run_tests'
|
|||
# Override this in settings_local.py if needed
|
||||
# *_PATH variables ends with a slash/ .
|
||||
INTERNET_DRAFT_PATH = '/a/www/ietf-ftp/internet-drafts/'
|
||||
INTERNET_DRAFT_PDF_PATH = '/a/www/ietf-datatracker/pdf/'
|
||||
RFC_PATH = '/a/www/ietf-ftp/rfc/'
|
||||
AGENDA_PATH = '/a/www/www6s/proceedings/'
|
||||
AGENDA_PATH_PATTERN = '/a/www/www6s/proceedings/%(meeting)s/agenda/%(wg)s.%(ext)s'
|
||||
|
|
|
@ -277,9 +277,11 @@ You can customize the agenda below to show only selected working group sessions.
|
|||
<td>{{ session.info.area|upper}}</td>
|
||||
<td>{% if session.info.isWG %}<a href="/wg/{{ session.info.acronym|lower }}/">{{ session.info.acronym|lower }}</a>{% else %}{{ session.info.acronym|lower }}{% endif %}</td>
|
||||
<td>
|
||||
<table width="100%"><tr><td>
|
||||
<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">
|
||||
{% 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 %}
|
||||
{% if session.info.special_agenda_note %}<br/> - {{ session.info.special_agenda_note }}{% endif %}
|
||||
</td><td align="right">drafts: <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>
|
||||
</td>
|
||||
{% endif %}
|
||||
</tr>
|
||||
|
|
Loading…
Reference in a new issue