Skip to content

Commit

Permalink
Merge pull request #12 from dpad/fix/kernel-download-use-tmpdir-and-warn
Browse files Browse the repository at this point in the history
Improve automatic SPICE kernel downloading to avoid incomplete downloads and warn the user.
  • Loading branch information
dpad authored Mar 10, 2021
2 parents 52a39ba + 04c3a64 commit c25c7dd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "OrbitalTrajectories"
uuid = "2b613a20-8d2a-5290-b19f-e06f4bcc2e7d"
authors = ["Dan Padilha"]
version = "0.1.4"
version = "0.1.5"

[deps]
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
Expand Down
37 changes: 21 additions & 16 deletions src/SPICE/spice.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,28 +61,33 @@ module SpiceUtils
meta_hash = Base.SHA1(meta["git-tree-sha1"])
download_URLs = [d["url"] for d in meta["download"]]
kernel_dir = artifact_path(meta_hash)
kernel_paths = [joinpath(kernel_dir, basename(url)) for url in download_URLs]

# Check if the kernel has already been downloaded before, and if not, download it.
for (kernel, url) in zip(kernel_paths, download_URLs)
if !artifact_exists(meta_hash) || !isfile(kernel)
mkpath(kernel_dir)
progress = begin
max_n = 10000
bar = Progress(max_n; desc="Downloading NAIF $(basename(url))", color=Base.info_color())
(total, now) -> update!(bar, total > 0 ? round(Int, (now / total) * max_n) : 0)
end

# Download the kernel into the artifacts folder.
kernel_names = [basename(url) for url in download_URLs]

# Check if the kernel has already been downloaded before, and if not, download it to a temporary directory.
temp_dir = artifact_exists(meta_hash) ? nothing : mktempdir(first(Artifacts.artifacts_dirs()))
if !isnothing(temp_dir)
max_n = 10000
for (kernel, url) in zip(kernel_names, download_URLs)
bar = Progress(max_n; desc="Downloading NAIF kernel: $(kernel)", color=Base.info_color())
progress = (total, now) -> update!(bar, total > 0 ? round(Int, (now / total) * max_n) : 0)
try
Downloads.download(url, kernel; progress)
Downloads.download(url, joinpath(temp_dir, kernel); progress)
finally
finish!(bar)
end
end

# Load the kernel into SPICE.
furnsh(kernel)
# All kernels are now downloaded; move them into the final kernel folder.
mv(temp_dir, kernel_dir)
end

# Load each kernel into SPICE.
for (kernel, url) in zip(kernel_names, download_URLs)
kernel_path = joinpath(kernel_dir, kernel)
if !isfile(kernel_path)
error("Could not find kernel file '$(kernel)'. Delete the $(kernel_dir) directory and try again.")
end
furnsh(kernel_path)
end

return true
Expand Down

2 comments on commit c25c7dd

@dpad
Copy link
Owner Author

@dpad dpad commented on c25c7dd Mar 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/31625

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.5 -m "<description of version>" c25c7ddaecfb701b4b3b76668b10d99af73a9f69
git push origin v0.1.5

Please sign in to comment.