|
17 | 17 |
|
18 | 18 |
|
19 | 19 | if len(sys.argv) != 3:
|
20 |
| - print('usage: ' + sys.argv[0] + ' <example_name> <SPHINX_DESTINATION>') |
| 20 | + print("usage: " + sys.argv[0] + " <example_name> <SPHINX_DESTINATION>") |
21 | 21 | sys.exit(1)
|
22 | 22 |
|
23 | 23 | # Collect our directories.
|
24 | 24 | cwd = os.getcwd()
|
25 | 25 | example_name = sys.argv[1]
|
26 | 26 | example_dir = os.path.join(cwd, example_name)
|
27 |
| -example_idx = example_dir.index('SphinxExamples') + 15 |
28 |
| -html_output_dir = os.path.join(sys.argv[2], 'html', example_dir[example_idx:]) |
| 27 | +example_idx = example_dir.index("SphinxExamples") + 15 |
| 28 | +html_output_dir = os.path.join(sys.argv[2], "html", example_dir[example_idx:]) |
29 | 29 |
|
30 | 30 | if not os.path.exists( html_output_dir ):
|
31 | 31 | os.makedirs( html_output_dir )
|
32 | 32 |
|
33 | 33 | # Copy files to support web editting to the html output.
|
34 | 34 | files_to_copy_to_html_output = []
|
35 |
| -files_to_copy_to_html_output.append(os.path.join(example_dir, 'CMakeLists.txt')) |
36 |
| -files_to_copy_to_html_output.extend(glob.glob(os.path.join(example_dir, '*.cxx'))) |
37 |
| -files_to_copy_to_html_output.extend(glob.glob(os.path.join(example_dir, '*.html'))) |
38 |
| -files_to_copy_to_html_output.extend(glob.glob(os.path.join(example_dir, '*.py'))) |
39 |
| -files_to_copy_to_html_output.extend(glob.glob(os.path.join(example_dir, '*.rst'))) |
| 35 | +files_to_copy_to_html_output.append(os.path.join(example_dir, "CMakeLists.txt")) |
| 36 | +files_to_copy_to_html_output.extend(glob.glob(os.path.join(example_dir, "*.cxx"))) |
| 37 | +files_to_copy_to_html_output.extend(glob.glob(os.path.join(example_dir, "*.html"))) |
| 38 | +files_to_copy_to_html_output.extend(glob.glob(os.path.join(example_dir, "*.py"))) |
| 39 | +files_to_copy_to_html_output.extend(glob.glob(os.path.join(example_dir, "*.rst"))) |
40 | 40 | for path in files_to_copy_to_html_output:
|
41 | 41 | shutil.copy2(path, html_output_dir)
|
42 | 42 |
|
|
45 | 45 | files_for_tarball = files_to_copy_to_html_output
|
46 | 46 |
|
47 | 47 | # Add a directory to build the project.
|
48 |
| -build_dir = os.path.join(example_dir, 'build') |
| 48 | +build_dir = os.path.join(example_dir, "build") |
49 | 49 | if not os.path.exists(build_dir):
|
50 | 50 | os.mkdir(build_dir)
|
51 | 51 | files_for_tarball.append(build_dir)
|
52 | 52 |
|
53 | 53 | # Substitude CMAKE_CURRENT_BINARY_DIR for CMAKE_CURRENT_SOURCE_DIR in the
|
54 | 54 | # tarball CMakeLists.txt. This so the input images can be found.
|
55 |
| -tarball_cmakelist = os.path.join(example_dir, 'CMakeLists.txt.tarball') |
56 |
| -with open(tarball_cmakelist, 'w') as new_list_file: |
57 |
| - with open(os.path.join(example_dir, 'CMakeLists.txt'), 'r') as old_list_file: |
| 55 | +tarball_cmakelist = os.path.join(example_dir, "CMakeLists.txt.tarball") |
| 56 | +with open(tarball_cmakelist, "w") as new_list_file: |
| 57 | + with open(os.path.join(example_dir, "CMakeLists.txt"), "r") as old_list_file: |
58 | 58 | for line in old_list_file:
|
59 |
| - newline = line.replace('CMAKE_CURRENT_BINARY_DIR', 'CMAKE_CURRENT_SOURCE_DIR') |
| 59 | + newline = line.replace( |
| 60 | + "CMAKE_CURRENT_BINARY_DIR", "CMAKE_CURRENT_SOURCE_DIR" |
| 61 | + ) |
60 | 62 | new_list_file.write(newline)
|
61 | 63 | files_for_tarball = files_for_tarball[1:]
|
62 | 64 | files_for_tarball.append(tarball_cmakelist)
|
63 | 65 |
|
64 |
| -inputs = glob.glob(os.path.join(example_dir, '*.sha512')) |
| 66 | +inputs = glob.glob(os.path.join(example_dir, "*.sha512")) |
65 | 67 | for path in inputs:
|
66 | 68 | files_for_tarball.append(path[:-7])
|
67 | 69 |
|
68 | 70 | # Remove duplicates.
|
69 | 71 | files_for_tarball = set(files_for_tarball)
|
70 | 72 |
|
71 |
| -with tarfile.open(os.path.join(html_output_dir, example_name + '.tar.gz'), \ |
72 |
| - 'w:gz', dereference=True) as tarfile: |
| 73 | +with tarfile.open( |
| 74 | + os.path.join(html_output_dir, example_name + ".tar.gz"), "w:gz", dereference=True |
| 75 | +) as tarfile: |
73 | 76 | example_dir_idx = example_dir.index(example_name)
|
74 | 77 | def strip_path(tarinfo):
|
75 |
| - tarinfo.name = tarinfo.name[example_dir_idx-1:] |
| 78 | + tarinfo.name = tarinfo.name[example_dir_idx - 1 :] |
76 | 79 | # Put the inputs and outputs into the build directory because the test
|
77 | 80 | # will not be able to find them otherwise.
|
78 | 81 | basename = os.path.basename(tarinfo.name)
|
79 |
| - if basename == 'CMakeLists.txt.tarball': |
80 |
| - head, tail = os.path.split(tarinfo.name) |
81 |
| - tarinfo.name = os.path.join(head, 'CMakeLists.txt') |
| 82 | + if basename == "CMakeLists.txt.tarball": |
| 83 | + head, tail = os.path.split(tarinfo.name) |
| 84 | + tarinfo.name = os.path.join(head, "CMakeLists.txt") |
82 | 85 | return tarinfo
|
83 | 86 | for path in files_for_tarball:
|
84 | 87 | tarfile.add(path, filter=strip_path)
|
85 | 88 |
|
86 |
| -with zipfile.ZipFile(os.path.join(html_output_dir, example_name + '.zip'), \ |
87 |
| - 'w') as zipfile: |
| 89 | +with zipfile.ZipFile( |
| 90 | + os.path.join(html_output_dir, example_name + ".zip"), "w" |
| 91 | +) as zipfile: |
88 | 92 | example_dir_idx = example_dir.index(example_name)
|
89 | 93 | for path in files_for_tarball:
|
90 |
| - arcname = path[example_dir_idx-1:] |
| 94 | + arcname = path[example_dir_idx - 1 :] |
91 | 95 | # Put the inputs and outputs into the build directory because the test
|
92 | 96 | # will not be able to find them otherwise.
|
93 | 97 | basename = os.path.basename(arcname)
|
94 |
| - if basename == 'CMakeLists.txt.tarball': |
95 |
| - head, tail = os.path.split(arcname) |
96 |
| - arcname = os.path.join(head, 'CMakeLists.txt') |
| 98 | + if basename == "CMakeLists.txt.tarball": |
| 99 | + head, tail = os.path.split(arcname) |
| 100 | + arcname = os.path.join(head, "CMakeLists.txt") |
97 | 101 | zipfile.write(path, arcname)
|
0 commit comments