diff --git a/REQUIRE b/REQUIRE index bf94518..61dc145 100644 --- a/REQUIRE +++ b/REQUIRE @@ -10,7 +10,7 @@ Colors 0.7.1 # Misc Parameters 0.7 DocStringExtensions 0.4 -Compat 0.27 # Sys.iswindows +BinDeps 0.8.7 # Communication MsgPack 0.1.1 diff --git a/deps/build.jl b/deps/build.jl index 9ebc8fc..819de13 100644 --- a/deps/build.jl +++ b/deps/build.jl @@ -1,6 +1,6 @@ using Base.Filesystem +using BinDeps: unpack_cmd, download_cmd -include("../src/download_helpers.jl") const meshcat_sha = "18028760b377c178bc77ee61cf4b9de8d176d3c5" const meshcat_url = "https://github.com/rdeits/meshcat/archive/$meshcat_sha.zip" @@ -33,8 +33,8 @@ function update_meshcat() mktempdir() do download_dir download_path = joinpath(download_dir, "meshcat.zip") - run(DownloadHelpers.download_cmd(meshcat_url, download_path)) - run(DownloadHelpers.unpack_cmd(download_path, download_dir, ".zip", nothing)) + run(download_cmd(meshcat_url, download_path)) + run(unpack_cmd(download_path, download_dir, ".zip", nothing)) mv(joinpath(download_dir, "meshcat-$meshcat_sha"), meshcat_dir; remove_destination=true) end open(stamp_file, "w") do file diff --git a/src/MeshCat.jl b/src/MeshCat.jl index aa855d9..32208dd 100644 --- a/src/MeshCat.jl +++ b/src/MeshCat.jl @@ -17,8 +17,8 @@ using Mux: page using WebIO using JSExpr using Base.Filesystem: rm +using BinDeps: download_cmd, unpack_cmd -import Compat import Base: delete!, length import MsgPack: pack, Ext import GeometryTypes: origin, radius @@ -65,7 +65,6 @@ include("trees.jl") using .SceneTrees include("geometry.jl") include("objects.jl") -include("download_helpers.jl") include("animations.jl") include("commands.jl") include("abstract_visualizer.jl") diff --git a/src/animations.jl b/src/animations.jl index 1484ceb..ae1c336 100644 --- a/src/animations.jl +++ b/src/animations.jl @@ -30,7 +30,7 @@ function convert_frames_to_video(tar_file_path::AbstractString, output_path::Abs end mktempdir() do tmpdir - run(DownloadHelpers.unpack_cmd(tar_file_path, tmpdir, ".tar", nothing)) + run(unpack_cmd(tar_file_path, tmpdir, ".tar", nothing)) cmd = `ffmpeg -r $framerate -i %07d.png -vcodec libx264 -preset slow -crf 18` if overwrite cmd = `$cmd -y` diff --git a/src/download_helpers.jl b/src/download_helpers.jl deleted file mode 100644 index c1bb36c..0000000 --- a/src/download_helpers.jl +++ /dev/null @@ -1,115 +0,0 @@ -module DownloadHelpers - -using Compat - -# Reproduced from https://github.com/JuliaLang/BinDeps.jl - -# BinDeps.jl is licensed under the MIT License: - -# > Copyright (c) 2012: Keno Fischer and other contributors. -# > -# > Permission is hereby granted, free of charge, to any person obtaining -# > a copy of this software and associated documentation files (the -# > "Software"), to deal in the Software without restriction, including -# > without limitation the rights to use, copy, modify, merge, publish, -# > distribute, sublicense, and/or sell copies of the Software, and to -# > permit persons to whom the Software is furnished to do so, subject to -# > the following conditions: -# > -# > The above copyright notice and this permission notice shall be -# > included in all copies or substantial portions of the Software. -# > -# > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -# > EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -# > MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# > NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -# > LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -# > OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -# > WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - - -downloadcmd = nothing -function download_cmd(url::AbstractString, filename::AbstractString) - global downloadcmd - if downloadcmd === nothing - for download_engine in (Compat.Sys.iswindows() ? ("C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell", - :powershell, :curl, :wget, :fetch) : (:curl, :wget, :fetch)) - if endswith(string(download_engine), "powershell") - checkcmd = `$download_engine -NoProfile -Command ""` - else - checkcmd = `$download_engine --help` - end - try - if success(checkcmd) - downloadcmd = download_engine - break - end - catch - continue # don't bail if one of these fails - end - end - end - if downloadcmd == :wget - return `$downloadcmd -O $filename $url` - elseif downloadcmd == :curl - return `$downloadcmd -f -o $filename -L $url` - elseif downloadcmd == :fetch - return `$downloadcmd -f $filename $url` - elseif endswith(string(downloadcmd), "powershell") - tls_cmd = "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12" - download_cmd = "(new-object net.webclient).DownloadFile(\"$(url)\", \"$(filename)\")" - return `$downloadcmd -NoProfile -Command "$(tls_cmd); $(download_cmd)"` - else - extraerr = Compat.Sys.iswindows() ? "check if powershell is on your path or " : "" - error("No download agent available; $(extraerr)install curl, wget, or fetch.") - end -end - -if Compat.Sys.isunix() && Sys.KERNEL != :FreeBSD - function unpack_cmd(file,directory,extension,secondary_extension) - if ((extension == ".gz" || extension == ".Z") && secondary_extension == ".tar") || extension == ".tgz" - return (`tar xzf $file --directory=$directory`) - elseif (extension == ".bz2" && secondary_extension == ".tar") || extension == ".tbz" - return (`tar xjf $file --directory=$directory`) - elseif extension == ".xz" && secondary_extension == ".tar" - return pipeline(`unxz -c $file `, `tar xv --directory=$directory`) - elseif extension == ".tar" - return (`tar xf $file --directory=$directory`) - elseif extension == ".zip" - return (`unzip -x $file -d $directory`) - elseif extension == ".gz" - return pipeline(`mkdir $directory`, `cp $file $directory`, `gzip -d $directory/$file`) - end - error("I don't know how to unpack $file") - end -end - -if Sys.KERNEL == :FreeBSD - # The `tar` on FreeBSD can auto-detect the archive format via libarchive. - # The supported formats can be found in libarchive-formats(5). - # For NetBSD and OpenBSD, libarchive is not available. - # For macOS, it is. But the previous unpack function works fine already. - function unpack_cmd(file, dir, ext, secondary_ext) - tar_args = ["--no-same-owner", "--no-same-permissions"] - return pipeline( - `/bin/mkdir -p $dir`, - `/usr/bin/tar -xf $file -C $dir $tar_args`) - end -end - -if Compat.Sys.iswindows() - const exe7z = joinpath(Compat.Sys.BINDIR, "7z.exe") - - function unpack_cmd(file,directory,extension,secondary_extension) - if ((extension == ".Z" || extension == ".gz" || extension == ".xz" || extension == ".bz2") && - secondary_extension == ".tar") || extension == ".tgz" || extension == ".tbz" - return pipeline(`$exe7z x $file -y -so`, `$exe7z x -si -y -ttar -o$directory`) - elseif (extension == ".zip" || extension == ".7z" || extension == ".tar" || - (extension == ".exe" && secondary_extension == ".7z")) - return (`$exe7z x $file -y -o$directory`) - end - error("I don't know how to unpack $file") - end -end - -end diff --git a/test/downloads.jl b/test/downloads.jl deleted file mode 100644 index 6cfcfd1..0000000 --- a/test/downloads.jl +++ /dev/null @@ -1,8 +0,0 @@ -@testset "download helpers" begin - url = "https://github.com/rdeits/meshcat/archive/18028760b377c178bc77ee61cf4b9de8d176d3c5.zip" - mktempdir() do tmpdir - target = joinpath(tmpdir, "meshcat.zip") - run(MeshCat.DownloadHelpers.download_cmd(url, target)) - run(MeshCat.DownloadHelpers.unpack_cmd(target, tmpdir, ".zip", nothing)) - end -end diff --git a/test/runtests.jl b/test/runtests.jl index cd97846..e1bcf00 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -6,7 +6,6 @@ using Colors using MeshIO, FileIO @testset "MeshCat" begin - include("downloads.jl") include("video_rendering.jl") include("paths.jl") include("visualizer.jl")