Skip to content

Commit 5018e60

Browse files
authored
Merge pull request #248 from aylward/CreateTarball
Create tarball
2 parents df5343f + 635cbc7 commit 5018e60

File tree

412 files changed

+916
-119
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

412 files changed

+916
-119
lines changed

CMake/ITKSphinxExamplesMacros.cmake

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
include(CMakeParseArguments)
22

33
# A high level target that the individual targets depend on.
4-
#add_custom_target( CreateTarballs ALL
5-
# ${CMAKE_COMMAND} -E echo "Done creating individual example tarballs..."
4+
#add_custom_target( CreateDownloadableArchives ALL
5+
# ${CMAKE_COMMAND} -E echo "Done creating individual example downloadable archives..."
66
#)
77

88
# Macro for adding an example.
@@ -11,20 +11,20 @@ include(CMakeParseArguments)
1111
# CMakeLists.txt. That file should be standalone for building the example.
1212
# This macro is intended to be instantiated in the CMakeLists.txt one directory
1313
# above where the example exists. It does things like creating the example
14-
# tarball's in the example output directory, and custom targets for building
14+
# archives's in the example output directory, and custom targets for building
1515
# the Sphinx documentation for an individual example. The Sphinx target will be
1616
# called ${example_name}Doc.
1717
macro(add_example example_name)
1818
if(BUILD_DOCUMENTATION)
1919
if(SPHINX_HTML_OUTPUT)
20-
add_custom_target(${example_name}Tarball
21-
COMMAND ${PYTHON_EXECUTABLE} ${ITKSphinxExamples_SOURCE_DIR}/Utilities/CreateTarball.py
20+
add_custom_target(${example_name}DownloadableArchive
21+
COMMAND ${PYTHON_EXECUTABLE} ${ITKSphinxExamples_SOURCE_DIR}/Utilities/CreateDownloadableArchive.py
2222
${example_name} ${SPHINX_DESTINATION}
2323
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
24-
COMMENT "Creating tarballs for ${example_name}"
24+
COMMENT "Creating downloadable archive for ${example_name}"
2525
DEPENDS copy_sources
2626
)
27-
add_dependencies(CreateTarballs ${example_name}Tarball)
27+
add_dependencies(CreateDownloadableArchives ${example_name}DownloadableArchive)
2828
endif()
2929
endif()
3030

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,8 @@ if(BUILD_DOCUMENTATION)
262262
add_dependencies(gitstats copy_sources)
263263

264264
# A high level target that the individual targets depend on.
265-
add_custom_target(CreateTarballs ALL
266-
${CMAKE_COMMAND} -E echo "Done creating individual example tarballs..."
265+
add_custom_target(CreateDownloadableArchives ALL
266+
${CMAKE_COMMAND} -E echo "Done creating individual example downloadable archives..."
267267
)
268268

269269
if(NOT ITKDoxygenXML_DIR)
@@ -282,7 +282,7 @@ if(BUILD_DOCUMENTATION)
282282
set(SPHINX_CONF_DIR ${ITKSphinxExamples_BINARY_DIR}/Formatting)
283283
set(SPHINX_INPUT_DIR ${ITKSphinxExamples_BINARY_DIR})
284284
set(SPHINX_DESTINATION ${ITKSphinxExamples_BINARY_DIR})
285-
set(SPHINX_DEPENDENCIES gitstats ITKDoxygenXML ITKSphinxExamplesData ITKDoxygenTAG CreateTarballs)
285+
set(SPHINX_DEPENDENCIES gitstats ITKDoxygenXML ITKSphinxExamplesData ITKDoxygenTAG CreateDownloadableArchives)
286286

287287
option(DOC_WITH_LOCAL_DOXYGEN "Generate documentation with local doxygen" OFF)
288288
mark_as_advanced(DOC_WITH_LOCAL_DOXYGEN)

Formatting/templates/relations.html

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
{%- endif %}
2020
{%- endfor -%}
2121
{%- endmacro %}
22-
{%- set tarballname = examplename(pagename)%}
22+
{%- set archivename = examplename(pagename)%}
2323

2424
{%- if prev %}
2525
{%- if slashcount == 4 %}
@@ -62,17 +62,9 @@
6262

6363
{%- if slashcount == 4 %}
6464
<li class="dropdown">
65-
<a role="button"
66-
id="dDownload"
67-
data-toggle="dropdown"
68-
data-target="#"
69-
href="#"><span class="glyphicon glyphicon-download-alt"></span> <span class="hidden-sm hidden-tablet">&nbsp; {{ _('Download') }} <b class="caret"> </span></b></a>
70-
<ul class="dropdown-menu"
71-
role="menu"
72-
aria-labelledby="dDownload">
73-
<li><a href="{{ tarballname ~ ".zip" }}">Packed as .zip</a></li>
74-
<li><a href="{{ tarballname ~ ".tar.gz" }}">Packed as .tar.gz</a></li>
75-
</ul>
65+
<a href="{{ meta.get("name") ~ ".zip" }}">
66+
<span class="glyphicon glyphicon-download-alt"></span> <span class="hidden-sm hidden-tablet">&nbsp; {{ _('Download') }}</span>
67+
</a>
7668
</li>
7769
{%- endif %}
7870

Utilities/CookieCutter/{{cookiecutter.example_name}}/Documentation.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
:name: {{ cookiecutter.example_name }}
2+
13
{{ cookiecutter.example_title }}
24
================================
35

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/usr/bin/env python
2+
3+
""" Build archives for the examples.
4+
5+
Build the .tar.gz and .zip for the example, and copy them along with the
6+
supporting files into the html output.
7+
8+
To be executed in the binary tree in the directory above the example.
9+
"""
10+
11+
import glob
12+
import os
13+
import shutil
14+
import sys
15+
import zipfile
16+
from pathlib import Path
17+
18+
19+
if len(sys.argv) != 3:
20+
print("usage: " + sys.argv[0] + " <example_name> <SPHINX_DESTINATION>")
21+
sys.exit(1)
22+
23+
# Collect our directories.
24+
cwd = Path(os.getcwd())
25+
26+
example_name = sys.argv[1]
27+
base_dir = cwd.parent.parent.parent
28+
example_dir = str(cwd / example_name)
29+
example_relative_path = cwd.relative_to(base_dir) / example_name
30+
html_output_dir = str(Path(sys.argv[2]) / "html" / example_relative_path)
31+
32+
if not os.path.exists(html_output_dir):
33+
os.makedirs(html_output_dir)
34+
35+
# Copy files to support web editting to the html output.
36+
files_to_copy_to_html_output = []
37+
files_to_copy_to_html_output.append(os.path.join(example_dir, "CMakeLists.txt"))
38+
files_to_copy_to_html_output.extend(glob.glob(os.path.join(example_dir, "*.cxx")))
39+
files_to_copy_to_html_output.extend(glob.glob(os.path.join(example_dir, "*.html")))
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")))
42+
files_to_copy_to_html_output.extend(glob.glob(os.path.join(example_dir, "*.rst")))
43+
for path in files_to_copy_to_html_output:
44+
shutil.copy2(path, html_output_dir)
45+
46+
47+
# archives for users to download from the website.
48+
files_for_archive = files_to_copy_to_html_output
49+
50+
# Add a directory to build the project.
51+
build_dir = os.path.join(example_dir, "build")
52+
if not os.path.exists(build_dir):
53+
os.mkdir(build_dir)
54+
files_for_archive.append(build_dir)
55+
56+
# Substitude CMAKE_CURRENT_BINARY_DIR for CMAKE_CURRENT_SOURCE_DIR in the
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:
60+
with open(os.path.join(example_dir, "CMakeLists.txt"), "r") as old_list_file:
61+
for line in old_list_file:
62+
newline = line.replace(
63+
"CMAKE_CURRENT_BINARY_DIR", "CMAKE_CURRENT_SOURCE_DIR"
64+
)
65+
new_list_file.write(newline)
66+
files_for_archive = files_for_archive[1:]
67+
files_for_archive.append(archive_cmakelist)
68+
69+
inputs = glob.glob(os.path.join(example_dir, "*.sha512"))
70+
for path in inputs:
71+
files_for_archive.append(path[:-7])
72+
73+
# Remove duplicates.
74+
files_for_archive = set(files_for_archive)
75+
76+
with zipfile.ZipFile(
77+
os.path.join(html_output_dir, example_name + ".zip"), "w"
78+
) as zipfile:
79+
example_dir_idx = example_dir.index(example_name)
80+
for path in files_for_archive:
81+
arcname = path[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(arcname)
85+
if basename == "CMakeLists.txt.archive":
86+
head, tail = os.path.split(arcname)
87+
arcname = os.path.join(head, "CMakeLists.txt")
88+
zipfile.write(path, arcname)

Utilities/CreateTarball.py

Lines changed: 0 additions & 97 deletions
This file was deleted.

src/Bridge/VtkGlue/ConvertAnRGBitkImageTovtkImageData/Documentation.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
:name: ConvertAnRGBitkImageTovtkImageData
2+
13
Convert an RGB itk::Image to vtkImageData
24
=========================================
35

src/Bridge/VtkGlue/ConvertAnitkImageTovtkImageData/Documentation.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
:name: ConvertAnitkImageTovtkImageData
2+
13
Convert an itk::Image to vtkImageData
24
=====================================
35

src/Bridge/VtkGlue/ConvertRGBvtkImageDataToAnitkImage/Documentation.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
:name: ConvertRGBvtkImageDataToAnitkImage
2+
13
Convert RGB vtkImageData to an itk::Image
24
=========================================
35

src/Bridge/VtkGlue/ConvertvtkImageDataToAnitkImage/Documentation.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
:name: ConvertvtkImageDataToAnitkImage
2+
13
Convert vtkImageData to an itk::Image
24
=====================================
35

0 commit comments

Comments
 (0)