|
34 | 34 |
|
35 | 35 | import codecs, re, os, glob |
36 | 36 | import datetime |
37 | | -import tarfile |
| 37 | +import tarfile, StringIO, time |
38 | 38 |
|
39 | 39 | from django.views.generic.simple import direct_to_template |
40 | 40 | from django.core.urlresolvers import reverse as urlreverse |
@@ -352,36 +352,40 @@ def agenda_documents(request): |
352 | 352 | telechats.append({'date':date, 'docs':res}) |
353 | 353 | return direct_to_template(request, 'iesg/agenda_documents.html', { 'telechats':telechats }) |
354 | 354 |
|
355 | | -def telechat_docs_tarfile(request,year,month,day): |
356 | | - from tempfile import mkstemp |
357 | | - date=datetime.date(int(year),int(month),int(day)) |
358 | | - if settings.USE_DB_REDESIGN_PROXY_CLASSES: |
359 | | - from ietf.doc.models import TelechatDocEvent |
360 | | - docs = [] |
361 | | - for d in IDInternal.objects.filter(docevent__telechatdocevent__telechat_date=date).distinct(): |
362 | | - if d.latest_event(TelechatDocEvent, type="scheduled_for_telechat").telechat_date == date: |
363 | | - docs.append(d) |
364 | | - else: |
365 | | - docs= IDInternal.objects.filter(telechat_date=date, primary_flag=1, agenda=1) |
| 355 | +def telechat_docs_tarfile(request, date): |
| 356 | + date = get_agenda_date(date) |
| 357 | + |
| 358 | + docs = [] |
| 359 | + for d in Document.objects.filter(docevent__telechatdocevent__telechat_date=date).distinct(): |
| 360 | + if d.latest_event(TelechatDocEvent, type="scheduled_for_telechat").telechat_date == date: |
| 361 | + docs.append(d) |
| 362 | + |
366 | 363 | response = HttpResponse(mimetype='application/octet-stream') |
367 | | - response['Content-Disposition'] = 'attachment; filename=telechat-%s-%s-%s-docs.tgz'%(year, month, day) |
368 | | - tarstream = tarfile.open('','w:gz',response) |
369 | | - mfh, mfn = mkstemp() |
370 | | - manifest = open(mfn, "w") |
| 364 | + response['Content-Disposition'] = 'attachment; filename=telechat-%s-docs.tgz' % date.isoformat() |
| 365 | + |
| 366 | + tarstream = tarfile.open('', 'w:gz', response) |
| 367 | + |
| 368 | + manifest = StringIO.StringIO() |
| 369 | + |
371 | 370 | for doc in docs: |
372 | | - doc_path = os.path.join(settings.INTERNET_DRAFT_PATH, doc.draft.filename+"-"+doc.draft.revision_display()+".txt") |
| 371 | + doc_path = os.path.join(settings.INTERNET_DRAFT_PATH, doc.name + "-" + doc.rev + ".txt") |
373 | 372 | if os.path.exists(doc_path): |
374 | 373 | try: |
375 | | - tarstream.add(doc_path, str(doc.draft.filename+"-"+doc.draft.revision_display()+".txt")) |
376 | | - manifest.write("Included: "+doc_path+"\n") |
377 | | - except Exception, e: |
378 | | - manifest.write(("Failed (%s): "%e)+doc_path+"\n") |
| 374 | + tarstream.add(doc_path, str(doc.name + "-" + doc.rev + ".txt")) |
| 375 | + manifest.write("Included: %s\n" % doc_path) |
| 376 | + except Exception as e: |
| 377 | + manifest.write("Failed (%s): %s\n" % (e, doc_path)) |
379 | 378 | else: |
380 | | - manifest.write("Not found: "+doc_path+"\n") |
381 | | - manifest.close() |
382 | | - tarstream.add(mfn, "manifest.txt") |
| 379 | + manifest.write("Not found: %s\n" % doc_path) |
| 380 | + |
| 381 | + manifest.seek(0) |
| 382 | + t = tarfile.TarInfo(name="manifest.txt") |
| 383 | + t.size = len(manifest.buf) |
| 384 | + t.mtime = time.time() |
| 385 | + tarstream.addfile(t, manifest) |
| 386 | + |
383 | 387 | tarstream.close() |
384 | | - os.unlink(mfn) |
| 388 | + |
385 | 389 | return response |
386 | 390 |
|
387 | 391 | def discusses(request): |
|
0 commit comments