|
1 | 1 | #!/usr/bin/env python
|
2 | 2 |
|
3 |
| -""" Build tarballs for the examples. |
| 3 | +""" Build archives for the examples. |
4 | 4 |
|
5 | 5 | Build the .tar.gz and .zip for the example, and copy them along with the
|
6 | 6 | supporting files into the html output.
|
|
12 | 12 | import os
|
13 | 13 | import shutil
|
14 | 14 | import sys
|
15 |
| -import tarfile |
16 | 15 | import zipfile
|
17 | 16 | from pathlib import Path
|
18 | 17 |
|
|
26 | 25 |
|
27 | 26 | example_name = sys.argv[1]
|
28 | 27 | base_dir = cwd.parent.parent.parent
|
| 28 | +example_dir = str(cwd / example_name) |
29 | 29 | example_relative_path = cwd.relative_to(base_dir) / example_name
|
30 | 30 | html_output_dir = str(Path(sys.argv[2]) / "html" / example_relative_path)
|
31 | 31 |
|
|
38 | 38 | files_to_copy_to_html_output.extend(glob.glob(os.path.join(example_dir, "*.cxx")))
|
39 | 39 | files_to_copy_to_html_output.extend(glob.glob(os.path.join(example_dir, "*.html")))
|
40 | 40 | files_to_copy_to_html_output.extend(glob.glob(os.path.join(example_dir, "*.py")))
|
| 41 | +files_to_copy_to_html_output.extend(glob.glob(os.path.join(example_dir, "*.ipynb"))) |
41 | 42 | files_to_copy_to_html_output.extend(glob.glob(os.path.join(example_dir, "*.rst")))
|
42 | 43 | for path in files_to_copy_to_html_output:
|
43 | 44 | shutil.copy2(path, html_output_dir)
|
44 | 45 |
|
45 | 46 |
|
46 |
| -# Tarballs for users to download from the website. |
47 |
| -files_for_tarball = files_to_copy_to_html_output |
| 47 | +# archives for users to download from the website. |
| 48 | +files_for_archive = files_to_copy_to_html_output |
48 | 49 |
|
49 | 50 | # Add a directory to build the project.
|
50 | 51 | build_dir = os.path.join(example_dir, "build")
|
51 | 52 | if not os.path.exists(build_dir):
|
52 | 53 | os.mkdir(build_dir)
|
53 |
| -files_for_tarball.append(build_dir) |
| 54 | +files_for_archive.append(build_dir) |
54 | 55 |
|
55 | 56 | # Substitude CMAKE_CURRENT_BINARY_DIR for CMAKE_CURRENT_SOURCE_DIR in the
|
56 |
| -# tarball CMakeLists.txt. This so the input images can be found. |
57 |
| -tarball_cmakelist = os.path.join(example_dir, "CMakeLists.txt.tarball") |
58 |
| -with open(tarball_cmakelist, "w") as new_list_file: |
| 57 | +# archive CMakeLists.txt. This so the input images can be found. |
| 58 | +archive_cmakelist = os.path.join(example_dir, "CMakeLists.txt.archive") |
| 59 | +with open(archive_cmakelist, "w") as new_list_file: |
59 | 60 | with open(os.path.join(example_dir, "CMakeLists.txt"), "r") as old_list_file:
|
60 | 61 | for line in old_list_file:
|
61 | 62 | newline = line.replace(
|
62 | 63 | "CMAKE_CURRENT_BINARY_DIR", "CMAKE_CURRENT_SOURCE_DIR"
|
63 | 64 | )
|
64 | 65 | new_list_file.write(newline)
|
65 |
| -files_for_tarball = files_for_tarball[1:] |
66 |
| -files_for_tarball.append(tarball_cmakelist) |
| 66 | +files_for_archive = files_for_archive[1:] |
| 67 | +files_for_archive.append(archive_cmakelist) |
67 | 68 |
|
68 | 69 | inputs = glob.glob(os.path.join(example_dir, "*.sha512"))
|
69 | 70 | for path in inputs:
|
70 |
| - files_for_tarball.append(path[:-7]) |
| 71 | + files_for_archive.append(path[:-7]) |
71 | 72 |
|
72 | 73 | # Remove duplicates.
|
73 |
| -files_for_tarball = set(files_for_tarball) |
74 |
| - |
75 |
| -with tarfile.open( |
76 |
| - os.path.join(html_output_dir, example_name + ".tar.gz"), "w:gz", dereference=True |
77 |
| -) as tarfile: |
78 |
| - example_dir_idx = example_dir.index(example_name) |
79 |
| - |
80 |
| - def strip_path(tarinfo): |
81 |
| - tarinfo.name = tarinfo.name[example_dir_idx - 1 :] |
82 |
| - # Put the inputs and outputs into the build directory because the test |
83 |
| - # will not be able to find them otherwise. |
84 |
| - basename = os.path.basename(tarinfo.name) |
85 |
| - if basename == "CMakeLists.txt.tarball": |
86 |
| - head, tail = os.path.split(tarinfo.name) |
87 |
| - tarinfo.name = os.path.join(head, "CMakeLists.txt") |
88 |
| - return tarinfo |
89 |
| - |
90 |
| - for path in files_for_tarball: |
91 |
| - tarfile.add(path, filter=strip_path) |
| 74 | +files_for_archive = set(files_for_archive) |
92 | 75 |
|
93 | 76 | with zipfile.ZipFile(
|
94 | 77 | os.path.join(html_output_dir, example_name + ".zip"), "w"
|
95 | 78 | ) as zipfile:
|
96 | 79 | example_dir_idx = example_dir.index(example_name)
|
97 |
| - for path in files_for_tarball: |
| 80 | + for path in files_for_archive: |
98 | 81 | arcname = path[example_dir_idx - 1 :]
|
99 | 82 | # Put the inputs and outputs into the build directory because the test
|
100 | 83 | # will not be able to find them otherwise.
|
101 | 84 | basename = os.path.basename(arcname)
|
102 |
| - if basename == "CMakeLists.txt.tarball": |
| 85 | + if basename == "CMakeLists.txt.archive": |
103 | 86 | head, tail = os.path.split(arcname)
|
104 | 87 | arcname = os.path.join(head, "CMakeLists.txt")
|
105 | 88 | zipfile.write(path, arcname)
|
0 commit comments