|
1 | 1 | import os
|
| 2 | +import sys |
2 | 3 | from subprocess import call
|
3 | 4 |
|
4 | 5 | from pdfrw import PdfReader, PdfWriter
|
5 | 6 |
|
6 | 7 | sections = ['Introduction','1_Experimental_datasets', '2_Structured_data_from_literature', '3_Analysis_tools', '4_Simulation_environments', '5_Model_sharing', '6_Computing_infrastructure', '7_Open_source_initiatives', '8_Web_portals']
|
7 | 8 | #sections = ['Introduction','1_Experimental_datasets', '2_Structured_data_from_literature']
|
8 | 9 |
|
| 10 | +only_sec = None |
| 11 | + |
| 12 | +if len(sys.argv) == 2: |
| 13 | + only_sec = sys.argv[1] |
| 14 | + print("Only doing sections starting with %s"%only_sec) |
9 | 15 |
|
10 | 16 | for section in sections:
|
11 | 17 |
|
12 |
| - print("++++++++++++++++++++++++++++++++++\n+ Adding section: %s\n+"%section) |
13 |
| - big_file = PdfWriter() |
14 |
| - |
15 |
| - files = os.listdir(section) |
16 |
| - |
17 |
| - files = sorted(files) |
18 |
| - |
19 |
| - for f in files: |
20 |
| - fpath = section+'/'+f |
21 |
| - if os.path.isfile(fpath) and fpath.endswith('pptx') and not f=='Template.pptx': |
22 |
| - print("+ Incorporating: %s"%fpath) |
23 |
| - call(["libreoffice", "--headless", "--invisible", "--convert-to", "pdf", fpath]) |
24 |
| - pdf_file_name = f.replace('pptx','pdf') |
25 |
| - |
26 |
| - pdf_file = PdfReader(pdf_file_name) |
27 |
| - print("+ Adding pages from %s\n+"%pdf_file_name) |
28 |
| - big_file.addpages(pdf_file.pages) |
29 |
| - call(["mv", pdf_file_name, "temp"]) |
30 |
| - |
31 |
| - |
32 |
| - big_file.write('Part1_%s.pdf'%section) |
| 18 | + if only_sec==None or section.startswith(only_sec): |
| 19 | + print("++++++++++++++++++++++++++++++++++\n+ Adding section: %s\n+"%section) |
| 20 | + big_file = PdfWriter() |
| 21 | + |
| 22 | + files = os.listdir(section) |
| 23 | + |
| 24 | + files = sorted(files) |
| 25 | + |
| 26 | + for f in files: |
| 27 | + fpath = section+'/'+f |
| 28 | + if os.path.isfile(fpath) and fpath.endswith('pptx') and not f=='Template.pptx': |
| 29 | + print("+ Incorporating: %s"%fpath) |
| 30 | + call(["/Applications/LibreOffice.app/Contents/MacOS/soffice", "--headless", "--invisible", "--convert-to", "pdf", fpath]) |
| 31 | + pdf_file_name = f.replace('pptx','pdf') |
| 32 | + |
| 33 | + pdf_file = PdfReader(pdf_file_name) |
| 34 | + print("+ Adding pages from %s\n+"%pdf_file_name) |
| 35 | + big_file.addpages(pdf_file.pages) |
| 36 | + if not 'ICG' in pdf_file_name: |
| 37 | + call(["mv", pdf_file_name, "temp"]) |
| 38 | + |
| 39 | + |
| 40 | + big_file.write('Part1_%s.pdf'%section) |
33 | 41 |
|
34 | 42 |
|
35 | 43 | print("Done.")
|
|
0 commit comments