|
3 | 3 | import itertools |
4 | 4 | import os |
5 | 5 | import shutil |
| 6 | +import subprocess |
6 | 7 |
|
7 | 8 | import debug # pyflakes:ignore |
8 | 9 |
|
|
31 | 32 | gen_attendees, gen_group_pages, gen_index, gen_irtf, gen_overview, gen_plenaries, |
32 | 33 | gen_progress, gen_research, gen_training, create_proceedings, create_interim_directory, |
33 | 34 | create_recording ) |
| 35 | +from ietf.utils.log import log |
34 | 36 |
|
35 | 37 | # ------------------------------------------------- |
36 | 38 | # Globals |
@@ -187,6 +189,31 @@ def parsedate(d): |
187 | 189 | ''' |
188 | 190 | return (d.strftime('%Y'),d.strftime('%m'),d.strftime('%d')) |
189 | 191 |
|
| 192 | +def is_powerpoint(doc): |
| 193 | + ''' |
| 194 | + Returns true if document is a Powerpoint presentation |
| 195 | + ''' |
| 196 | + return doc.file_extension() in ('ppt','pptx') |
| 197 | + |
| 198 | +def post_process(doc): |
| 199 | + ''' |
| 200 | + Does post processing on uploaded file. |
| 201 | + - Convert PPT to PDF |
| 202 | + ''' |
| 203 | + if is_powerpoint(doc) and hasattr(settings,'SECR_PPT2PDF_COMMAND'): |
| 204 | + try: |
| 205 | + cmd = settings.SECR_PPT2PDF_COMMAND |
| 206 | + cmd.append(doc.get_file_path()) # outdir |
| 207 | + cmd.append(os.path.join(doc.get_file_path(),doc.external_url)) # filename |
| 208 | + subprocess.check_call(cmd) |
| 209 | + except (subprocess.CalledProcessError, OSError) as error: |
| 210 | + log("Error converting PPT: %s" % (error)) |
| 211 | + return |
| 212 | + # change extension |
| 213 | + base,ext = os.path.splitext(doc.external_url) |
| 214 | + doc.external_url = base + '.pdf' |
| 215 | + doc.save() |
| 216 | + |
190 | 217 | # ------------------------------------------------- |
191 | 218 | # AJAX Functions |
192 | 219 | # ------------------------------------------------- |
@@ -678,7 +705,8 @@ def replace_slide(request, slide_id): |
678 | 705 |
|
679 | 706 | new_slide.external_url = disk_filename |
680 | 707 | new_slide.save() |
681 | | - |
| 708 | + post_process(new_slide) |
| 709 | + |
682 | 710 | # create DocEvent uploaded |
683 | 711 | DocEvent.objects.create(doc=slide, |
684 | 712 | by=request.user.person, |
@@ -913,7 +941,8 @@ def redirection_back(meeting, group): |
913 | 941 | DocAlias.objects.get_or_create(name=doc.name, document=doc) |
914 | 942 |
|
915 | 943 | handle_upload_file(file,disk_filename,meeting,material_type.slug) |
916 | | - |
| 944 | + post_process(doc) |
| 945 | + |
917 | 946 | # set Doc state |
918 | 947 | if doc.type.slug=='slides': |
919 | 948 | doc.set_state(State.objects.get(type=doc.type,slug='archived')) |
|
0 commit comments